Repository navigation
mcp: reject null sampling messages instead of panicking - #1567
Merged
guglielmo-san merged 1 commit intoDec 4, 2026
Merged
guglielmo-san merged 1 commit into
guglielmo-san merged 1 commit into
Conversation
A sampling/createMessage request whose messages contain null made the client panic in toBase when only a CreateMessageHandler is set. The panic happens on a goroutine started by the SDK, so the client process exits before the handler runs. The same null in a tool's InputRequests, given as *CreateMessageParams, also panicked the server in the 2025-11-25 multi-round-trip shim, in createMessageParamsToWithTools. Return an invalid params error from toBase for a nil message, and keep the nil in createMessageParamsToWithTools so that it reaches the client and is rejected there. Fixes modelcontextprotocol#1563
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
guglielmo-san
approved these changes
Dec 4, 2026
guglielmo-san
merged commit Dec 4, 2026
e3114cb
into
modelcontextprotocol:main
11 of 12 checks passed
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.
Summary
A
sampling/createMessagerequest containing anullelement inmessagescrashes a client that only configuresCreateMessageHandler:toBasedereferences thenilmessage inside an SDK-managed goroutine, terminating the process before the handler runs.Changes
mcp/protocol.go(toBase): Return an invalid params error when amessageselement isnil, so the client responds with JSON-RPC-32602instead of panicking.mcp/mrtr.go(createMessageParamsToWithTools): Preservenilmessage elements asnilwhen converting a tool's*CreateMessageParamsInputRequests(2025-11-25 multi-round-trip path), so the request reaches the client and returns the same error instead of panicking the server.mcp/sampling_test.go(TestCreateMessage_NilMessage): Verify the-32602error path directly and through toolInputRequestsfor bothCreateMessageWithToolsParamsandCreateMessageParamsacross protocol versions2026-07-28and2025-11-25.Verification
toBaseguard panics intoBase; removing thecreateMessageParamsToWithToolsguard panics increateMessageParamsToWithTools.gofmt,go vet ./...,staticcheckv0.8.2,go test ./...(Go 1.26.11 and 1.27.4), andgo test -race ./...(Go 1.27.4) locally onlinux/amd64(WSL2) andwindows/amd64; all passed. (Not run ondarwinorarm64.)Scope & Notes
nilparams (for example, a typednil*CreateMessageParamsinInputRequests) is unchanged, and clients configuringCreateMessageWithToolsHandlercontinue to receivenilmessage elements unchanged.Fixes #1563
AI tools assisted me with the investigation, the patch, and the test runs; I reviewed and verified the changes locally.
René Atencio Roa
Founder, Alekore Systems Inc.