Skip to content

mcp: prefer the negotiated protocol version over the request context - #1163

Open
gwyszynski-sa wants to merge 1 commit into
modelcontextprotocol:mainfrom
gwyszynski-sa:fix/protocol-version-header-precedence
Open

mcp: prefer the negotiated protocol version over the request context#1163
gwyszynski-sa wants to merge 1 commit into
modelcontextprotocol:mainfrom
gwyszynski-sa:fix/protocol-version-header-precedence

Conversation

@gwyszynski-sa

@gwyszynski-sa gwyszynski-sa commented Aug 13, 2026

Copy link
Copy Markdown

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

setMCPHeaders prefers the request context over the negotiated protocol version since #1115

1 participant