Skip to content

Commit 0a16a7b

Browse files
Add ValueError for missing transport key: sessions.py (#198)
This pull request adds a `ValueError` to validate missing `transport` keys in `MultiServerMCPClient` server configurations. The error message includes valid `transport` values (`stdio`, `sse`, `websocket`, `streamable_http`) and a link to the documentation for clarity. The change was prompted by Grok and ChatGPT suggesting an invalid configuration, such as: ``` { "mcpServers": { "gitmcp": { "command": "npx", "args": ["mcp-remote", "https://gitmcp.io/{owner}/{repo}"] } } } ``` This caused a `KeyError: transport` due to incorrect nesting and missing `transport`. A warning was added to guide users to the correct top-level format, improving error clarity and preventing similar issues. --------- Co-authored-by: Eugene Yurtsev <[email protected]>
1 parent 3530165 commit 0a16a7b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

langchain_mcp_adapters/sessions.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,15 @@ async def create_session(
275275
Yields:
276276
A ClientSession
277277
"""
278+
279+
if "transport" not in connection:
280+
raise ValueError(
281+
"Configuration error: Missing 'transport' key in server configuration. "
282+
"Each server must include 'transport' with one of: "
283+
"'stdio', 'sse', 'websocket', 'streamable_http'. "
284+
"Please refer to the langchain-mcp-adapters documentation for more details."
285+
)
286+
278287
transport = connection["transport"]
279288
if transport == "sse":
280289
if "url" not in connection:
@@ -329,5 +338,6 @@ async def create_session(
329338
yield session
330339
else:
331340
raise ValueError(
332-
f"Unsupported transport: {transport}. Must be one of: 'stdio', 'sse', 'websocket', 'streamable_http'"
341+
f"Unsupported transport: {transport}. "
342+
f"Must be one of: 'stdio', 'sse', 'websocket', 'streamable_http'"
333343
)

0 commit comments

Comments
 (0)