feat: add protocol version override support for client session initialization - #2652
feat: add protocol version override support for client session initialization#2652STiFLeR7 wants to merge 4 commits into
Conversation
c9cc22a to
bc76e74
Compare
9b0c1b1 to
3791666
Compare
3791666 to
3902778
Compare
This comment was marked as spam.
This comment was marked as spam.
|
Confirmed and fixed in Went with your option 1: since the PR description's own stated intent is "enabling clients to negotiate older or custom protocol versions," an override has to actually win, not depend on whether the server happens to answer Added:
Both fail on the pre-fix code and pass after (verified via Separate, smaller point from your review I did not change: the arbitrary-custom-version consistency gap ( One more thing surfaced while testing this end-to-end: for an in-process |
negotiate_auto only consulted protocol_version in its initialize() fallback calls, so mode="auto" (the default) silently dropped the override whenever the server/discover probe succeeded first - the override only ever took effect when the probe failed. Since the whole point of protocol_version_override is to let a caller pin an older or custom protocol version, an override must always win: when set, skip the discover probe entirely and go straight to the legacy handshake at that version. Regression tests: a unit test on negotiate_auto proving the probe is skipped even when the stub's discover script would otherwise succeed, and an e2e test over a real streamable-HTTP server (mode="auto" + override) proving only `initialize` is sent and `server/discover` never is. Reported by a static review pass on this PR; verified independently by tracing the actual control flow before applying this fix.
f55e795 to
dce39ec
Compare
RequestResponder and mcp.shared.session were removed upstream since this test was written; message_handler callbacks now receive IncomingMessage (ServerNotification | Exception), matching every other message_handler in this file.
|
Rebased onto main (89 commits) and fixed a genuine lint failure the rebase surfaced: RequestResponder and mcp.shared.session were removed upstream since this test was added. Updated message_handler to the current IncomingMessage type, matching every other handler in this file. Ruff, pyright, and all 92 tests in the file pass. |
Description
This PR adds support for client session protocol version overrides during initialization, enabling clients to negotiate older or custom protocol versions (e.g.
2024-11-05) with MCP servers.Changes
ClientSession.initialize(...)to accept a customprotocol_version.protocol_versionfield to the high-levelClientdataclass.protocol_versionfield toClientSessionParametersinClientSessionGroup.