Repository navigation
fix(mcp): connect to Streamable HTTP servers on mcp 2.x - #118
Conversation
pyproject asks for mcp>=1.9.0, so pip install lightagent now resolves mcp 2.3.0. mcp 2.x removed streamablehttp_client, the import fell into the 'older SDK' fallback, and every streamable-http server failed with 'installed MCP SDK does not support Streamable HTTP'. Keep the old call when it exists; otherwise use streamable_http_client with an httpx client from create_mcp_http_client carrying the headers (2.x has no headers argument), closed with the session's exit stack.
|
The original contribution is preserved in follow-up PR #121. Real HTTP testing found an additional SDK 2.x tool-model difference (input_schema versus inputSchema), which is now handled for registration and calls. The follow-up also fixes the locked-SDK test failure, checks header precedence and cleanup/reconnect behavior, and adds a three-SDK compatibility CI matrix. Local stateless HTTP probes pass on MCP 1.12.4, 1.30.0, and 2.3.0; full suites pass on the locked and 2.3.0 SDKs. #121 is submitted for review only; no merge has been performed. |
|
The completed fixes have now been appended directly to this original contributor branch at c1852e3, preserving the existing commits and attribution. The newly triggered CI run passed all 7 checks: https://github.com/wanxingai/LightAgent/actions/runs/40616540724 . Supplemental PR #121 has been closed as redundant. This original PR remains open and unmerged for your review; main has not been modified. |
|
Thanks @wxai-space, and for keeping the original commits. Catching the |
|
Thanks for merging, @wxai-space, and for testing it against a real HTTP server. That's what caught the |
Problem
pyproject.tomlasks formcp>=1.9.0, so a freshpip install lightagent(0.11.0) now resolves mcp 2.3.0. mcp 2.x removedmcp.client.streamable_http.streamablehttp_client. Inmcp_client_manager.pythat import falls into the "older SDK"except ImportErrorbranch, and everystreamable-httpserver then fails with:The SDK supports it. It's newer, not older: 2.x has
streamable_http_client(url, http_client=...). That function has noheaders=argument, so headers have to travel on the httpx client.Change
LightAgent/mcp_client_manager.py:streamable_http_clientandcreate_mcp_http_client. Both exist in mcp 1.24+ and 2.x.streamablehttp_clientexists, nothing changes. Otherwise, build the httpx client withcreate_mcp_http_client(headers=headers)(static headers plus the credential provider's), enter it on the sameexit_stackso it closes with the session, and pass it tostreamable_http_client.ClientSession(*streams[:2])already handles both the 1.x three-stream and the 2.x two-stream shapes.Tests
New test
test_streamable_http_works_on_mcp_2_without_streamablehttp_clientuses the 2.x shape: the old name is missing, headers go throughcreate_mcp_http_client, and the transport yields two streams. It fails onmainand passes here.PYTHONPATH=. pytest -q tests: 366 passed, 1 skipped, in a venv frompip install -e ., which resolves mcp 2.3.0.End to end: a local streamable-HTTP MCP server whose tool echoes the
X-Testrequest header, connected throughMCPClientManager._create_sessionand then called:header=helloRuntimeError: installed MCP SDK does not support Streamable HTTPheader=helloheader=helloNote: in a venv built from
requirements.txt(mcp==1.10.1and its pins), 33 test modules fail to import (cannot import name 'eval_type_backport' from 'pydantic._internal._typing_extra'), so I ran the suite frompyproject.tomlinstead.