-
Notifications
You must be signed in to change notification settings - Fork 3.6k
First end-to-end 2026-07-28 stateless tools/call (experimental entry + ClientSession pin) #2917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Pinning the new
Client.protocol_versionto2026-07-28with an in-memoryServer/MCPServerinstance silently produces a broken connection: only the URL branch threads the pin into the transport, so the server runs the legacy stateful path (initialize gate) while the pinned session never sendsinitialize, and every subsequent request fails with a crypticINVALID_PARAMS'Invalid request parameters'. Consider raising a clearValueError(or adding a docstring caveat) whenprotocol_versionis inMODERN_PROTOCOL_VERSIONSand the server is an in-memory instance, until the in-memory modern entry point lands.Extended reasoning...
What happens.
Client.__post_init__only threadsprotocol_versioninto the transport on the URL branch (streamable_http_client(self.server, protocol_version=...)). Whenserveris aServer/MCPServerinstance, it builds a plainInMemoryTransportwith no awareness of the pin (src/mcp/client/client.py:112-118), while the pin is still passed toClientSession(line 138). A2026-07-28-pinnedClientSessionis "born initialized":initialize()returns the locally synthesized result without sending anything on the wire, soClient.__aenter__succeeds and the connection looks healthy.Why every request then fails.
InMemoryTransport._connectrunsactual_server.run(...)on the legacy stateful path (nostateless=True), soServerRunner's init gate is active:if not self.connection.initialize_accepted and method not in _INIT_EXEMPT: raise MCPError(INVALID_PARAMS, 'Invalid request parameters'). The pinned session never sendsinitializeornotifications/initialized, soinitialize_acceptednever becomes true. The per-request_metaenvelope doesn't help either:_resolve_protocol_versiononly honours the_metaversion if it is inSUPPORTED_PROTOCOL_VERSIONS, which does not include2026-07-28, so it falls back to2025-11-25and the gate still fires.Step-by-step proof.
async with Client(my_mcpserver, protocol_version=\"2026-07-28\") as client:—__post_init__buildsInMemoryTransport(no pin),__aenter__callssession.initialize(), which returns the synthesized result without touching the wire. The context manager enters successfully.await client.call_tool(\"add\", {\"a\": 1, \"b\": 2})— the request reachesServerRunner._on_requestwithconnection.initialize_acceptedstill false (no handshake ever ran, andstatelessis False soconnection.initializedwas never pre-set).MCPError(INVALID_PARAMS, \"Invalid request parameters\")— the user sees an error that suggests their arguments are wrong, with no hint that the version pin is the cause.Why nothing prevents it. The new
Client.protocol_versiondocstring explicitly invites pinning to2026-07-28('selects the stateless transport era: no initialize handshake is sent') and frames HTTP behavior as an additional detail, not a precondition. The only acknowledgement of the gap is buried in test infrastructure: tests/interaction/_requirements.py locks the in-memory transport to2025-11-25with the comment 'the in-memory transport has no modern entry point yet'. The public API neither documents nor rejects the combination, so a user following the docstring with the in-memory server (the first usage shown in theClientclass example) hits the cryptic failure.Impact and fix. This is a missing-guard/diagnostics gap rather than silent corruption — the failure is loud, just misleading. Since the in-memory modern factory is explicitly slated to land later in this milestone, the lightweight fix is either (a) raise a clear
ValueErrorin__post_init__whenprotocol_version in MODERN_PROTOCOL_VERSIONSand the server is aServer/MCPServerinstance ('the in-memory transport does not support 2026-07-28 yet'), or (b) add a caveat to theprotocol_versiondocstring stating that modern pins currently only work with URL/HTTP servers. Either removes the trap until the in-memory modern path lands.