Skip to content

fix(mcp): make http doc sources work with mcp 2.x - #243

Merged
antonwolfy merged 1 commit into
intel:mainfrom
vishalhabib99:fix/mcp-2-streamable-http
Oct 26, 2026
Merged

antonwolfy merged 1 commit into
intel:mainfrom
vishalhabib99:fix/mcp-2-streamable-http

Conversation

@vishalhabib99

Copy link
Copy Markdown
Contributor

Summary

mcp:http= doc sources fail on mcp 2.x. The [mcp] extra asks for mcp>=1.0, which now resolves to mcp 2.3.0. mcp 2.x removed mcp.client.streamable_http.streamablehttp_client, which MCPProtocolClient._open_session imports for the http transport, so every HTTP doc source fails with:

ImportError: cannot import name 'streamablehttp_client' from 'mcp.client.streamable_http'

The stdio and sse transports are unaffected.

Changes

  • dokimi/mcp/mcp_protocol.py: import streamable_http_client (present in mcp 1.24+ and 2.x) and fall back to streamablehttp_client on 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 http branch 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():

    mcp 1.25.0 mcp 2.3.0
    main ['echo'] ImportError
    this branch ['echo'] ['echo']
  • New test: the mcp 2.x case fails on main and all 3 cases pass on this branch. tests/test_mcp_protocol.py passes 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 check and mypy dokimi/mcp/mcp_protocol.py are clean.

Checklist

  • Tests added/updated and pytest passes (see note on pre-existing macOS failures)
  • ruff and mypy pass on the changed files
  • Docs updated (or N/A)
  • No ad-hoc run artifacts committed
  • New files carry the SPDX license header (or are exempt). The changelog fragment follows the existing fragments, which have no header.

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 antonwolfy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 the except still pass, which is harmless for behaviour.

Checked, no issues

  • Changelog: the fragment sits under ### Fixed, follows the existing naming pattern and is required because dokimi/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-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.40%. Comparing base (b05b9e7) to head (116836a).
⚠️ Report is 1 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

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     
Files with missing lines Coverage Δ
dokimi/dokimi/mcp/mcp_protocol.py 62.30% <100.00%> (+13.10%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@antonwolfy
antonwolfy merged commit b2a9473 into intel:main Oct 26, 2026
20 checks passed
@vishalhabib99

Copy link
Copy Markdown
Contributor Author

Thanks @antonwolfy for the thorough review, especially running make ci-local and the mutation check before approving.

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.

3 participants