Skip to content

fix(mcp): connect to Streamable HTTP servers on mcp 2.x - #118

Merged
wxai-space merged 3 commits into
wanxingai:mainfrom
vishalhabib99:fix/streamable-http-mcp2
Oct 28, 2026
Merged

wxai-space merged 3 commits into
wanxingai:mainfrom
vishalhabib99:fix/streamable-http-mcp2

Conversation

@vishalhabib99

@vishalhabib99 vishalhabib99 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Problem

pyproject.toml asks for mcp>=1.9.0, so a fresh pip install lightagent (0.11.0) now resolves mcp 2.3.0. mcp 2.x removed mcp.client.streamable_http.streamablehttp_client. In mcp_client_manager.py that import falls into the "older SDK" except ImportError branch, and every streamable-http server then fails with:

RuntimeError: installed MCP SDK does not support Streamable HTTP

The SDK supports it. It's newer, not older: 2.x has streamable_http_client(url, http_client=...). That function has no headers= argument, so headers have to travel on the httpx client.

Change

LightAgent/mcp_client_manager.py:

  • Also import streamable_http_client and create_mcp_http_client. Both exist in mcp 1.24+ and 2.x.
  • If the old streamablehttp_client exists, nothing changes. Otherwise, build the httpx client with create_mcp_http_client(headers=headers) (static headers plus the credential provider's), enter it on the same exit_stack so it closes with the session, and pass it to streamable_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_client uses the 2.x shape: the old name is missing, headers go through create_mcp_http_client, and the transport yields two streams. It fails on main and passes here.

  • PYTHONPATH=. pytest -q tests: 366 passed, 1 skipped, in a venv from pip install -e ., which resolves mcp 2.3.0.

  • End to end: a local streamable-HTTP MCP server whose tool echoes the X-Test request header, connected through MCPClientManager._create_session and then called:

    mcp 1.25.0 mcp 2.3.0
    main header=hello RuntimeError: installed MCP SDK does not support Streamable HTTP
    this branch header=hello header=hello

Note: in a venv built from requirements.txt (mcp==1.10.1 and its pins), 33 test modules fail to import (cannot import name 'eval_type_backport' from 'pydantic._internal._typing_extra'), so I ran the suite from pyproject.toml instead.

vishalhabib99 and others added 2 commits October 26, 2026 14:26
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.
@wxai-space

Copy link
Copy Markdown
Collaborator

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.

@vishalhabib99

Copy link
Copy Markdown
Contributor Author

Thanks for carrying this forward in #121 and for catching the input_schema / inputSchema difference. I missed that one. Happy to test #121 against a real Streamable HTTP server if that would help.

@wxai-space

Copy link
Copy Markdown
Collaborator

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.

@vishalhabib99

Copy link
Copy Markdown
Contributor Author

Thanks @wxai-space, and for keeping the original commits. Catching the input_schema/inputSchema difference took real HTTP testing; I'd only exercised the connect path. The branch looks good to me as it stands.

@wxai-space
wxai-space merged commit 90e8412 into wanxingai:main Oct 28, 2026
14 checks passed
@vishalhabib99

Copy link
Copy Markdown
Contributor Author

Thanks for merging, @wxai-space, and for testing it against a real HTTP server. That's what caught the input_schema difference my PR missed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants