Repository navigation
mcp: send handler errors that carry no code as Internal error - #1407
Merged
guglielmo-san merged 1 commit intoOct 16, 2026
Merged
guglielmo-san merged 1 commit into
guglielmo-san merged 1 commit into
Conversation
An error returned by a request handler without a JSON-RPC error code reached the peer with code 0. handleReceive now gives such an error the code -32603 (Internal error), keeping its message and keeping it in the chain for errors.Is and errors.As. Errors that already carry a code, and jsonrpc2.ErrNotHandled, are unchanged. The path is shared by both sides, so client handlers (sampling, elicitation) get the same treatment. MCPGODEBUG=nointernalerrorcode=1 restores code 0. Fixes modelcontextprotocol#1394 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
guglielmo-san
approved these changes
Oct 16, 2026
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 request handler that fails with an ordinary error (no JSON-RPC code) answered the peer with error code 0. As suggested in #1394,
handleReceiveinmcp/shared.gonow gives such an error the code -32603 (Internal error), right after the method handler returns. The message is unchanged, and the original error stays in the chain forerrors.Is/errors.As. Errors that already carry a code keep it, andjsonrpc2.ErrNotHandledis left alone so it still becomes "method not found".handleReceiveserves both sides, so a failing client handler (sampling, elicitation) now reaches the server as -32603 too.This is a behavioral change, so
MCPGODEBUG=nointernalerrorcode=1restores code 0. The option is documented indocs/mcpgodebug.mdunder 1.9.0.TestHandlerErrorWithoutCodecovers a server prompt handler and a client sampling handler, with plain, wrapped, coded and wrapped-coded errors, under both settings; without the change it fails with code 0.Fixes #1394
AI disclosure: written with Claude Code; I reviewed the change and ran
go test ./...,go vet ./...,staticcheckand themcptests under-race.🤖 Generated with Claude Code