fix: support mcp 2.x result shapes in MCP instrumentation - #42
Merged
Conversation
mcp 2.0 (spec 2026-07-28) renamed CallToolResult's fields to snake_case and dropped the camelCase attributes, so the isError read silently returned False (failed tool calls looked healthy) and structuredContent was never found. Reads now try both spellings. tools/call can also return an interim InputRequiredResult (MRTR): its input_requests carry elicitation/sampling content, so interim rounds now get only an mcp.result_type marker instead of recording that payload as output.value. Tests run against both majors: the shims pick the right server fixture (FastMCP vs MCPServer, in-memory Client), fakes pin each major's exact attribute surface, and a new ci job overlays mcp>=2 onto the locked env. GLA2-300 items 1-3; item 4 (SEP-414 trace-propagation docs) follows separately.
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.
Closes GLA2-300 (items 1–3; item 4, the SEP-414 trace-propagation docs, follows separately once this is released).
mcp 2.0.0 shipped with spec 2026-07-28 and
pip install mcpnow installs 2.x, while our extra ismcp>=1.0.0unbounded — so fresh installs already resolve a version where the instrumentation silently misreads results.What was broken on mcp 2.x
CallToolResult.isError/structuredContentno longer exist (renamed to snake_case, camelCase dropped — verified against the real package). Our defensivegetattr(..., False)reads returned the fallback, so failed tool calls produced healthy-looking spans and structured output silently degraded to text blocks.tools/callcan now return an interimInputRequiredResult(MRTR): the retry loop produces one span per round, and the interim payload (input_requests, i.e. elicitation/sampling content) was recorded asoutput.value.Changes
_result_is_error/_record_resultso they're unit-testable.input_requiredrounds record only anmcp.result_typemarker (new semconv key, following the mcp SDK's ownmcp.*namespace) and never record the interim payload as output.MCPServer+ in-memoryClient), version-agnostic error-flag assertion, plus fakes pinning each major's exact attribute surface (RED-first; the six new tests failed before the fix).mcp-v2CI job overlaysmcp>=2,<3on the locked env and re-runs the MCP tests, so the next upstream rename fails a build instead of un-flagging error results in production.Verification
uv run --with "mcp>=2,<3" pytest tests/test_mcp_instrumentation.pygreen (12 passed) — real 2.x, not fakes only.mcp>=1.0.0(unbounded) by design: the wrapper is now correct on both majors simultaneously.