Skip to content

mcp: fix potential nil-pointer dereference on message send - #1115

Merged
yarolegovich merged 2 commits into
mainfrom
yarolegovich/nil-check
Jul 27, 2026
Merged

yarolegovich merged 2 commits into
mainfrom
yarolegovich/nil-check

Conversation

@yarolegovich

Copy link
Copy Markdown
Member

No description provided.

@yarolegovich
yarolegovich merged commit bc72835 into main Jul 27, 2026
9 checks passed
@yarolegovich
yarolegovich deleted the yarolegovich/nil-check branch July 27, 2026 15:20
gwyszynski-sa added a commit to gwyszynski-sa/go-sdk that referenced this pull request Aug 13, 2026
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
guglielmo-san added a commit that referenced this pull request Aug 18, 2026
…1163)

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

Co-authored-by: Guglielmo Colombo <guglielmoc@google.com>
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.

2 participants