Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mcp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1813,6 +1813,7 @@ func (ss *ServerSession) handle(ctx context.Context, req *jsonrpc.Request) (any,
}

if validatedMeta.usesNewProtocol &&
validatedMeta.initializeParams != nil &&
!slices.Contains(supportedProtocolVersions, validatedMeta.initializeParams.ProtocolVersion) {
data, _ := json.Marshal(UnsupportedProtocolVersionData{
Supported: supportedProtocolVersions,
Expand Down
24 changes: 24 additions & 0 deletions mcp/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1451,3 +1451,27 @@ func TestServerSessionHandle_RejectsRemovedMethodsOnNewProtocol(t *testing.T) {
})
}
}

// TestServerSessionHandle_NewProtocolNotificationWithoutParams verifies that
// a notification carrying new-protocol _meta (id: null) does not panic when
// the server dereferences initializeParams, which is nil for notifications.
// Fixes https://github.com/modelcontextprotocol/go-sdk/issues/1043 and #1046.
func TestServerSessionHandle_NewProtocolNotificationWithoutParams(t *testing.T) {
ss := &ServerSession{server: NewServer(testImpl, nil)}
req := &jsonrpc.Request{
Method: notificationCancelled,
Params: mustMarshal(map[string]any{
"_meta": map[string]any{
MetaKeyProtocolVersion: protocolVersion20260728,
},
"requestId": "r1",
}),
}
// A notification with new-protocol _meta must not panic.
// The expected behavior is that it returns without error
// (notifications are fire-and-forget).
_, err := ss.handle(context.Background(), req)
if err != nil {
t.Fatalf("notification with new-protocol _meta: unexpected error: %v", err)
}
}