Repository navigation
mcp: report an error when a sampling or elicitation handler returns nil - #1304
Merged
guglielmo-san merged 7 commits intoOct 16, 2026
Merged
guglielmo-san merged 7 commits into
guglielmo-san merged 7 commits into
Conversation
A CreateMessageHandler, or an ElicitationHandler for a form elicitation, that returned nil, nil made the client dereference the nil result and crash. CreateMessageWithToolsHandler and URL elicitation sent the nil to the server instead. Report an error naming the handler in all four cases, as readResource does for a resource handler.
guglielmo-san
approved these changes
Oct 16, 2026
Contributor
|
@po-et thank you for the contribution! |
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.
A sampling or elicitation handler returning
(nil, nil)could panic in the client or send a null result back to the server. These handler paths report-32603by wrappingjsonrpc2.ErrInternal, while preserving errors returned by the handler.Tests cover both sampling handlers and form/URL elicitation. Four direct tests check the error code and sentinel; eight multi-round-trip cases check propagation on 2026-07-28 and 2025-11-25 sessions.
The branch now includes upstream main
7c486efa8223d5f66af8cf7b2ac9bb04a1ee6b91through a normal merge. The test-file conflict was resolved by retaining both the nil-handler regression and the upstream resource-cache tests. The original production fix and nil-handler test block are unchanged; the contribution remains two files, +113/-3 relative to that base.Validation for head
56129e92521223e712dc1e68d01678f374443117: fullgo test -race ./...,go vet ./..., CI-pinnedstaticcheckv0.6.1, formatting, and diff checks pass locally on Go 1.25.6 / macOS arm64. An independent automated review found no blocking issue and reran the nil-handler and resource-cache tests successfully. All nine public checks have now passed on this exact head, including Go 1.25/1.26 tests, race, client/server conformance, lint, and CodeQL. Local conformance scripts and other-platform local tests were not run in this update.AI assistance was used for the merge-conflict resolution, validation, description, and independent automated review.