Spaces:
Running
Running
Jeremiah Lowin commited on
Commit ·
42e32fe
1
Parent(s): 2aa779f
Update transports.py
Browse files
src/fastmcp/client/transports.py
CHANGED
|
@@ -6,8 +6,7 @@ import shutil
|
|
| 6 |
import sys
|
| 7 |
from collections.abc import AsyncIterator
|
| 8 |
from pathlib import Path
|
| 9 |
-
from typing import TYPE_CHECKING, Any,
|
| 10 |
-
from urllib.parse import urlparse
|
| 11 |
|
| 12 |
from mcp import ClientSession, StdioServerParameters
|
| 13 |
from mcp.client.session import (
|
|
@@ -26,7 +25,7 @@ from typing_extensions import Unpack
|
|
| 26 |
|
| 27 |
from fastmcp.server import FastMCP as FastMCPServer
|
| 28 |
from fastmcp.utilities.logging import get_logger
|
| 29 |
-
from fastmcp.utilities.mcp_config import MCPConfig
|
| 30 |
|
| 31 |
if TYPE_CHECKING:
|
| 32 |
from fastmcp.utilities.mcp_config import MCPConfig
|
|
@@ -537,22 +536,3 @@ def infer_transport(
|
|
| 537 |
|
| 538 |
logger.debug(f"Inferred transport: {inferred_transport}")
|
| 539 |
return inferred_transport
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
def infer_transport_type_from_url(
|
| 543 |
-
url: str | AnyUrl,
|
| 544 |
-
) -> Literal["streamable-http", "sse"]:
|
| 545 |
-
"""
|
| 546 |
-
Infer the appropriate transport type from the given URL.
|
| 547 |
-
"""
|
| 548 |
-
url = str(url)
|
| 549 |
-
if not url.startswith("http"):
|
| 550 |
-
raise ValueError(f"Invalid URL: {url}")
|
| 551 |
-
|
| 552 |
-
parsed_url = urlparse(url)
|
| 553 |
-
path = parsed_url.path
|
| 554 |
-
|
| 555 |
-
if "/sse/" in path or path.rstrip("/").endswith("/sse"):
|
| 556 |
-
return "sse"
|
| 557 |
-
else:
|
| 558 |
-
return "streamable-http"
|
|
|
|
| 6 |
import sys
|
| 7 |
from collections.abc import AsyncIterator
|
| 8 |
from pathlib import Path
|
| 9 |
+
from typing import TYPE_CHECKING, Any, TypedDict, cast
|
|
|
|
| 10 |
|
| 11 |
from mcp import ClientSession, StdioServerParameters
|
| 12 |
from mcp.client.session import (
|
|
|
|
| 25 |
|
| 26 |
from fastmcp.server import FastMCP as FastMCPServer
|
| 27 |
from fastmcp.utilities.logging import get_logger
|
| 28 |
+
from fastmcp.utilities.mcp_config import MCPConfig, infer_transport_type_from_url
|
| 29 |
|
| 30 |
if TYPE_CHECKING:
|
| 31 |
from fastmcp.utilities.mcp_config import MCPConfig
|
|
|
|
| 536 |
|
| 537 |
logger.debug(f"Inferred transport: {inferred_transport}")
|
| 538 |
return inferred_transport
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|