Spaces:
Running
Running
Sandipan Haldar commited on
Commit ·
65a34c2
1
Parent(s): c87c8e6
Fix static analysis issues
Browse files
src/fastmcp/client/transports.py
CHANGED
|
@@ -6,10 +6,8 @@ import shutil
|
|
| 6 |
import sys
|
| 7 |
from collections.abc import AsyncIterator
|
| 8 |
from pathlib import Path
|
| 9 |
-
from typing import
|
| 10 |
-
|
| 11 |
-
)
|
| 12 |
-
from typing import Any
|
| 13 |
from exceptiongroup import BaseExceptionGroup, catch
|
| 14 |
from mcp import ClientSession, McpError, StdioServerParameters
|
| 15 |
from mcp.client.session import (
|
|
@@ -449,7 +447,7 @@ def infer_transport(
|
|
| 449 |
# the transport is a websocket URL
|
| 450 |
elif isinstance(transport, AnyUrl | str) and str(transport).startswith("ws"):
|
| 451 |
return WSTransport(url=transport)
|
| 452 |
-
|
| 453 |
## if the transport is a config dict
|
| 454 |
elif isinstance(transport, dict):
|
| 455 |
if "mcpServers" not in transport:
|
|
@@ -457,9 +455,11 @@ def infer_transport(
|
|
| 457 |
else:
|
| 458 |
server = transport["mcpServers"]
|
| 459 |
if len(list(server.keys())) > 1:
|
| 460 |
-
raise ValueError(
|
|
|
|
|
|
|
| 461 |
server_name = list(server.keys())[0]
|
| 462 |
-
|
| 463 |
if "command" in server[server_name] and "args" in server[server_name]:
|
| 464 |
return StdioTransport(
|
| 465 |
command=server[server_name]["command"],
|
|
@@ -482,7 +482,7 @@ def infer_transport(
|
|
| 482 |
)
|
| 483 |
|
| 484 |
raise ValueError("Cannot determine transport type from dictionary")
|
| 485 |
-
|
| 486 |
# the transport is an unknown type
|
| 487 |
else:
|
| 488 |
raise ValueError(f"Could not infer a valid transport from: {transport}")
|
|
|
|
| 6 |
import sys
|
| 7 |
from collections.abc import AsyncIterator
|
| 8 |
from pathlib import Path
|
| 9 |
+
from typing import Any, TypedDict
|
| 10 |
+
|
|
|
|
|
|
|
| 11 |
from exceptiongroup import BaseExceptionGroup, catch
|
| 12 |
from mcp import ClientSession, McpError, StdioServerParameters
|
| 13 |
from mcp.client.session import (
|
|
|
|
| 447 |
# the transport is a websocket URL
|
| 448 |
elif isinstance(transport, AnyUrl | str) and str(transport).startswith("ws"):
|
| 449 |
return WSTransport(url=transport)
|
| 450 |
+
|
| 451 |
## if the transport is a config dict
|
| 452 |
elif isinstance(transport, dict):
|
| 453 |
if "mcpServers" not in transport:
|
|
|
|
| 455 |
else:
|
| 456 |
server = transport["mcpServers"]
|
| 457 |
if len(list(server.keys())) > 1:
|
| 458 |
+
raise ValueError(
|
| 459 |
+
"Invalid transport dictionary: multiple servers found - only one expected"
|
| 460 |
+
)
|
| 461 |
server_name = list(server.keys())[0]
|
| 462 |
+
# Stdio transport
|
| 463 |
if "command" in server[server_name] and "args" in server[server_name]:
|
| 464 |
return StdioTransport(
|
| 465 |
command=server[server_name]["command"],
|
|
|
|
| 482 |
)
|
| 483 |
|
| 484 |
raise ValueError("Cannot determine transport type from dictionary")
|
| 485 |
+
|
| 486 |
# the transport is an unknown type
|
| 487 |
else:
|
| 488 |
raise ValueError(f"Could not infer a valid transport from: {transport}")
|