Spaces:
Running
Running
Jeremiah Lowin commited on
Commit ·
446f852
1
Parent(s): 5437d7f
Fix import
Browse files
src/fastmcp/client/transports.py
CHANGED
|
@@ -37,7 +37,6 @@ from pydantic import AnyUrl
|
|
| 37 |
from typing_extensions import Unpack
|
| 38 |
|
| 39 |
from fastmcp.client.auth import OAuth
|
| 40 |
-
from fastmcp.server import FastMCP as FastMCPServer
|
| 41 |
from fastmcp.server.dependencies import get_http_headers
|
| 42 |
from fastmcp.server.server import FastMCP
|
| 43 |
from fastmcp.utilities.logging import get_logger
|
|
@@ -55,7 +54,6 @@ __all__ = [
|
|
| 55 |
"ClientTransport",
|
| 56 |
"SSETransport",
|
| 57 |
"StreamableHttpTransport",
|
| 58 |
-
"FastMCPServer",
|
| 59 |
"StdioTransport",
|
| 60 |
"PythonStdioTransport",
|
| 61 |
"FastMCPStdioTransport",
|
|
@@ -656,7 +654,7 @@ class FastMCPTransport(ClientTransport):
|
|
| 656 |
tests or scenarios where client and server run in the same runtime.
|
| 657 |
"""
|
| 658 |
|
| 659 |
-
def __init__(self, mcp:
|
| 660 |
"""Initialize a FastMCPTransport from a FastMCP server instance."""
|
| 661 |
|
| 662 |
# Accept both FastMCP 2.x and FastMCP 1.0 servers. Both expose a
|
|
@@ -770,7 +768,7 @@ def infer_transport(transport: ClientTransportT) -> ClientTransportT: ...
|
|
| 770 |
|
| 771 |
|
| 772 |
@overload
|
| 773 |
-
def infer_transport(transport:
|
| 774 |
|
| 775 |
|
| 776 |
@overload
|
|
@@ -805,7 +803,7 @@ def infer_transport(transport: Path) -> PythonStdioTransport | NodeStdioTranspor
|
|
| 805 |
|
| 806 |
def infer_transport(
|
| 807 |
transport: ClientTransport
|
| 808 |
-
|
|
| 809 |
| FastMCP1Server
|
| 810 |
| AnyUrl
|
| 811 |
| Path
|
|
@@ -822,7 +820,7 @@ def infer_transport(
|
|
| 822 |
|
| 823 |
The function supports these input types:
|
| 824 |
- ClientTransport: Used directly without modification
|
| 825 |
-
-
|
| 826 |
- Path or str (file path): Creates PythonStdioTransport (.py) or NodeStdioTransport (.js)
|
| 827 |
- AnyUrl or str (URL): Creates StreamableHttpTransport (default) or SSETransport (for /sse endpoints)
|
| 828 |
- MCPConfig or dict: Creates MCPConfigTransport, potentially connecting to multiple servers
|
|
@@ -860,7 +858,7 @@ def infer_transport(
|
|
| 860 |
return transport
|
| 861 |
|
| 862 |
# the transport is a FastMCP server (2.x or 1.0)
|
| 863 |
-
elif isinstance(transport,
|
| 864 |
inferred_transport = FastMCPTransport(mcp=transport)
|
| 865 |
|
| 866 |
# the transport is a path to a script
|
|
|
|
| 37 |
from typing_extensions import Unpack
|
| 38 |
|
| 39 |
from fastmcp.client.auth import OAuth
|
|
|
|
| 40 |
from fastmcp.server.dependencies import get_http_headers
|
| 41 |
from fastmcp.server.server import FastMCP
|
| 42 |
from fastmcp.utilities.logging import get_logger
|
|
|
|
| 54 |
"ClientTransport",
|
| 55 |
"SSETransport",
|
| 56 |
"StreamableHttpTransport",
|
|
|
|
| 57 |
"StdioTransport",
|
| 58 |
"PythonStdioTransport",
|
| 59 |
"FastMCPStdioTransport",
|
|
|
|
| 654 |
tests or scenarios where client and server run in the same runtime.
|
| 655 |
"""
|
| 656 |
|
| 657 |
+
def __init__(self, mcp: FastMCP | FastMCP1Server):
|
| 658 |
"""Initialize a FastMCPTransport from a FastMCP server instance."""
|
| 659 |
|
| 660 |
# Accept both FastMCP 2.x and FastMCP 1.0 servers. Both expose a
|
|
|
|
| 768 |
|
| 769 |
|
| 770 |
@overload
|
| 771 |
+
def infer_transport(transport: FastMCP) -> FastMCPTransport: ...
|
| 772 |
|
| 773 |
|
| 774 |
@overload
|
|
|
|
| 803 |
|
| 804 |
def infer_transport(
|
| 805 |
transport: ClientTransport
|
| 806 |
+
| FastMCP
|
| 807 |
| FastMCP1Server
|
| 808 |
| AnyUrl
|
| 809 |
| Path
|
|
|
|
| 820 |
|
| 821 |
The function supports these input types:
|
| 822 |
- ClientTransport: Used directly without modification
|
| 823 |
+
- FastMCP or FastMCP1Server: Creates an in-memory FastMCPTransport
|
| 824 |
- Path or str (file path): Creates PythonStdioTransport (.py) or NodeStdioTransport (.js)
|
| 825 |
- AnyUrl or str (URL): Creates StreamableHttpTransport (default) or SSETransport (for /sse endpoints)
|
| 826 |
- MCPConfig or dict: Creates MCPConfigTransport, potentially connecting to multiple servers
|
|
|
|
| 858 |
return transport
|
| 859 |
|
| 860 |
# the transport is a FastMCP server (2.x or 1.0)
|
| 861 |
+
elif isinstance(transport, FastMCP | FastMCP1Server):
|
| 862 |
inferred_transport = FastMCPTransport(mcp=transport)
|
| 863 |
|
| 864 |
# the transport is a path to a script
|