Skip to content

fix(mcp): guard nil initializeParams on new-protocol notifications#1047

Open
kuangmi-bit wants to merge 1 commit into
modelcontextprotocol:mainfrom
kuangmi-bit:fix/null-id-new-protocol-panic
Open

fix(mcp): guard nil initializeParams on new-protocol notifications#1047
kuangmi-bit wants to merge 1 commit into
modelcontextprotocol:mainfrom
kuangmi-bit:fix/null-id-new-protocol-panic

Conversation

@kuangmi-bit

Copy link
Copy Markdown

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) returns usesNewProtocol=true with initializeParams=nil for notifications — notifications do not carry client identity per SEP-2575. The protocol version check at server.go:1816 then dereferenced initializeParams.ProtocolVersion without a nil guard.

Fix

Add validatedMeta.initializeParams != nil guard before accessing .ProtocolVersion. Notifications skip the version check entirely — the same guard pattern already used at line 1846 for initialization state.

Regression test

TestServerSessionHandle_NewProtocolNotificationWithoutParams sends a notifications/cancelled notification with new-protocol _meta and verifies it returns without error (no panic).

Related

Fixes #1043
Fixes #1046

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
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.

Server panics on id: null request with per-request protocol _meta

1 participant