fix(mcp): guard nil initializeParams on new-protocol notifications#1047
Open
kuangmi-bit wants to merge 1 commit into
Open
fix(mcp): guard nil initializeParams on new-protocol notifications#1047kuangmi-bit wants to merge 1 commit into
kuangmi-bit wants to merge 1 commit into
Conversation
When a JSON-RPC notification (id: null) carries new-protocol _meta (protocolVersion >= 2026-07-28), validateRequestMeta returns usesNewProtocol=true with initializeParams=nil — notifications do not carry client identity per SEP-2575. The per-request protocol version check at server.go:1816 then dereferenced initializeParams without a nil guard, causing a panic. Fix: add validatedMeta.initializeParams != nil guard before accessing .ProtocolVersion. Notifications skip the version check entirely (same guard pattern already used at line 1846 for init state). Adds regression test: notification with new-protocol _meta must not panic and must return without error. Fixes modelcontextprotocol#1043 Fixes modelcontextprotocol#1046
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.
What
Fixes a panic in the server-side per-request protocol metadata path when a JSON-RPC notification (
id: null) carries new-protocol_meta(protocolVersion >= 2026-07-28).Root cause
validateRequestMeta(§2.3 step 3) returnsusesNewProtocol=truewithinitializeParams=nilfor notifications — notifications do not carry client identity per SEP-2575. The protocol version check atserver.go:1816then dereferencedinitializeParams.ProtocolVersionwithout a nil guard.Fix
Add
validatedMeta.initializeParams != nilguard before accessing.ProtocolVersion. Notifications skip the version check entirely — the same guard pattern already used at line 1846 for initialization state.Regression test
TestServerSessionHandle_NewProtocolNotificationWithoutParamssends anotifications/cancellednotification with new-protocol_metaand verifies it returns without error (no panic).Related
Fixes #1043
Fixes #1046