Repository navigation
fix(mcp): make http doc sources work with mcp 2.x - #243
Conversation
mcp 2.x removed mcp.client.streamable_http.streamablehttp_client, and the [mcp] extra (mcp>=1.0) now resolves to mcp 2.3.0, so every mcp:http= doc source failed with an ImportError. Use streamable_http_client (mcp 1.24+ and 2.x), fall back to the old name on older 1.x, and take the first two streams since 1.x yields (read, write, get_session_id) and 2.x yields (read, write). Signed-off-by: Vishal Habib <[email protected]>
antonwolfy
left a comment
There was a problem hiding this comment.
LGTM. The http branch now prefers streamable_http_client, falls back to streamablehttp_client on ImportError, and reads only the first two streams, so it handles both the 1.x three-stream and 2.x two-stream shapes. No other use of the old name or the 3-tuple remains in the repo.
What I ran, on a Linux review host at 116836a:
make ci-local: 29 passed, 0 failed, 7 skipped (jobs that do not apply to a PR or need tools absent here); changed-line coverage passed.- Mutation run on the new test: 8 mutants (base module, either name alone, wrong stream indexes, 3-way unpack, dropped fallback, swapped import order,
except Exception). The test fails on the base module for the 2.x case only and kills 6 of the 8; swapping the import order and broadening theexceptstill pass, which is harmless for behaviour.
Checked, no issues
- Changelog: the fragment sits under
### Fixed, follows the existing naming pattern and is required becausedokimi/dokimi/changed. - Static checks: ruff, mypy and deptry pass on the PR head.
I did not run the branch against a real mcp SDK; I read the SDK's source instead. On its main (2.x), streamable_http_client(url, *, http_client=..., ...) yields (read_stream, write_stream) and streamablehttp_client is gone; v1.30.0 has both names, and its deprecation warning fires only for parameters this call does not pass. That matches the two shapes the PR handles.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #243 +/- ##
==========================================
+ Coverage 92.34% 92.40% +0.06%
==========================================
Files 240 240
Lines 30400 30404 +4
Branches 5025 5025
==========================================
+ Hits 28073 28096 +23
+ Misses 1639 1619 -20
- Partials 688 689 +1
🚀 New features to boost your workflow:
|
|
Thanks @antonwolfy for the thorough review, especially running |
Summary
mcp:http=doc sources fail on mcp 2.x. The[mcp]extra asks formcp>=1.0, which now resolves to mcp 2.3.0. mcp 2.x removedmcp.client.streamable_http.streamablehttp_client, whichMCPProtocolClient._open_sessionimports for thehttptransport, so every HTTP doc source fails with:The
stdioandssetransports are unaffected.Changes
dokimi/mcp/mcp_protocol.py: importstreamable_http_client(present in mcp 1.24+ and 2.x) and fall back tostreamablehttp_clienton older 1.x. Read the first two yielded streams, because 1.x yields(read, write, get_session_id)and 2.x yields(read, write).tests/test_mcp_protocol.py: one parametrized test with a fake SDK in the three shapes (2.x, 1.24+, older 1.x).changelog.d/fragment under Fixed.Risk
Small. This only touches the
httpbranch of_open_session. The extra's version range is unchanged, so this doesn't cap mcp, and users already on mcp 2.x keep working.Testing
Against a real local streamable-HTTP MCP server:
MCPProtocolClient(transport="http", url="http://127.0.0.1:8765/mcp")._list_tool_names():['echo']ImportError['echo']['echo']New test: the mcp 2.x case fails on main and all 3 cases pass on this branch.
tests/test_mcp_protocol.pypasses in full (13).Full suite on macOS: 8290 passed and 16 failed. I re-ran the failing modules on main (
test_process,test_ragas_runtime,test_repo_runner,test_model_defaults), and the same failures happen there. They come from process limits and optional dependencies in my environment, not from this change.ruff checkandmypy dokimi/mcp/mcp_protocol.pyare clean.Checklist
pytestpasses (see note on pre-existing macOS failures)ruffandmypypass on the changed files