Skip to content

mcp: answer plain handler errors with -32603 instead of code 0 - #1402

Closed
RyoKusnadi wants to merge 2 commits into
modelcontextprotocol:mainfrom
RyoKusnadi:fix/internal-error-code-for-plain-handler-errors
Closed

RyoKusnadi wants to merge 2 commits into
modelcontextprotocol:mainfrom
RyoKusnadi:fix/internal-error-code-for-plain-handler-errors

Conversation

@RyoKusnadi

@RyoKusnadi RyoKusnadi commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

When a handler returns a plain Go error (no JSON-RPC code), the peer receives it with "code": 0. This affects prompts, resources, completion, subscribe, raw tool handlers, receiving middleware, custom methods and the client-side sampling/elicitation handlers.

This follows the direction suggested in the issue discussion: right after the receiving method handler in handleReceive, an error that carries no code (not a WireError, not ErrNotHandled/ErrMethodNotFound) is wrapped so it is sent with -32603 (Internal error). The message is unchanged and errors.Is/errors.As on the original error still work. Coded errors keep their code.

The change is gated behind MCPGODEBUG=noplainerrorinternalcode=1 and documented under 1.9.0. A test covers a plain and a coded error returned from receiving middleware.

Fixes #1394

@guglielmo-san

Copy link
Copy Markdown
Contributor

Closing as priority given to owner of #1394

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.

mcp: a handler error without a code reaches the peer as JSON-RPC error code 0

2 participants