mcp: prefer the negotiated protocol version over the request context - #1163
Open
gwyszynski-sa wants to merge 1 commit into
Open
Conversation
setMCPHeaders resolved Mcp-Protocol-Version from the request context before c.initializedResult. modelcontextprotocol#1107 established the opposite order and said so in its description; the code it replaced also consulted the context last. The two branches were transposed by the switch-to-if rewrite in modelcontextprotocol#1115, whose subject was an unrelated nil-pointer check. The context branch serves the pre-negotiation server/discover probe, which sets its own value in Client.Connect. Once a version has been negotiated it is the authoritative one for that connection, so initializedResult should win. _meta.protocolVersion from the outgoing message stays on top, so modelcontextprotocol#1109 stays fixed. The existing table built its request with http.NewRequest, so protocolVersionFromContext returned "" in every case and the two orderings were indistinguishable, which is why the transposition went unnoticed. Adds a ctxVersion dimension and three cases pinning the precedence. Fixes modelcontextprotocol#1162
gwyszynski-sa
force-pushed
the
fix/protocol-version-header-precedence
branch
from
August 13, 2026 12:19
6c431d8 to
64d43b3
Compare
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.
setMCPHeaders resolved Mcp-Protocol-Version from the request context before
c.initializedResult. #1107 established the opposite order and said so in its
description; the code it replaced also consulted the context last. The two
branches were transposed by the switch-to-if rewrite in #1115, whose subject
was an unrelated nil-pointer check.
The context branch serves the pre-negotiation server/discover probe, which
sets its own value in Client.Connect. Once a version has been negotiated it is
the authoritative one for that connection, so initializedResult should win.
_meta.protocolVersion from the outgoing message stays on top, so #1109 stays
fixed.
The existing table built its request with http.NewRequest, so
protocolVersionFromContext returned "" in every case and the two orderings
were indistinguishable, which is why the transposition went unnoticed. Adds a
ctxVersion dimension and three cases pinning the precedence.
Fixes #1162