Repository navigation
Conversation
mcp 2.x renamed streamablehttp_client to streamable_http_client and the client factory now yields (read, write) instead of the v1 3-tuple with a session-id callback. The post-import hook for mcp.client.streamable_http crashed with AttributeError on any module exposing only the new name, and _wrap_transport_with_callback would fail unpacking a 2-tuple. Resolve the wrapped attribute by whichever name the installed SDK provides, and handle both yield shapes in the callback wrapper. Regression tests: two tests that fail without the fix (unpack crash on 2-tuple; hook wrapping the removed v1 name).
8 of 9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Makes
traceai-mcpwork onmcp>=2.x. The instrumentor's post-import hook formcp.client.streamable_httpwrapsstreamablehttp_client, which mcp 2.xrenamed to
streamable_http_client— soinstrument()raisesAttributeErroron any environment where the module exposes only the new name. The same client
factory also now yields a 2-tuple
(read, write)instead of v1's 3-tuple witha session-id callback, which
_wrap_transport_with_callbackwould fail tounpack. The hook now wraps whichever name the installed SDK provides, and the
wrapper handles both yield shapes.
Why?
mcp2.x is the current SDK. On it, the instrumentor crashes atinstrument()time (post-import hook fires immediately when the module isalready imported) or at first use of the streamable-HTTP transport — i.e. the
transport that current deployments standardize on. We hit this while
instrumenting a live streamable-HTTP MCP deployment.
Note: mcp 2.x also ships native OTel instrumentation (per-request CLIENT spans
_metacontext propagation,mcp/shared/_otel.py, SEP-414), so thetransport-wrapping approach is increasingly belt-and-suspenders on v2 — but the
instrumentor should at least not crash on current SDKs.
How was it tested?
Two new regression tests in
tests/test_framework_mcp.py(
TestMCPSdkV2Compat):test_wrap_transport_with_callback_two_tuple— 2-tuple yield, failspre-patch with the unpack
ValueErrortest_streamable_http_hook_wraps_v2_name— hook must wrap the v2 name,fails pre-patch (hooks the removed
streamablehttp_client)Suite result on
mcp==2.3.0(Python 3.12):The single failure is
test_instrumentation_dependencies, which assertslen(_instruments) >= 2whilepackage.pydeclares("mcp >= 0.1.0",)—pre-existing on a clean checkout, unrelated to this change. Reverting this
patch makes both new tests fail, as expected.
Also verified end-to-end:
MCPInstrumentor().instrument()+streamable_http_clientagainst a live streamable-HTTP MCP server(mcp 2.3.0) — client connects, requests complete, spans export.
pytestorvitest)ruff check/mypy/npm run typecheck/npm run lintall passChecklist
mainfeat:,fix:,docs:,chore:…)docs/VOCABULARY.mdNotes for reviewers
AI use: Devin (Cognition) drafted the fix and tests; verified against a
live MCP deployment before opening. Human reviewed the diff and this body.
Worth a separate look (out of scope here):
_uninstrumentonly unwrapsmcp.client.stdio/mcp.server.stdio— the SSE, streamable-HTTP andServerSessionwraps stay installed afteruninstrument(). Happy to file afollow-up issue/PR if wanted.