Skip to content

fix(server): keep the "MCP error <code>:" prefix off tool result envelopes (#647) - #656

Merged
debugmcpdev merged 1 commit into
mainfrom
fix/647-session-error-prefix
Sep 2, 2026
Merged

fix(server): keep the "MCP error <code>:" prefix off tool result envelopes (#647)#656
debugmcpdev merged 1 commit into
mainfrom
fix/647-session-error-prefix

Conversation

@debugmcpdev

Copy link
Copy Markdown
Collaborator

Summary

Every tool that hit a session-lifecycle failure (session not found / terminated / no active proxy) returned {"success": false, "error": "MCP error -32600: Cannot step over: no active proxy for session …"} — the typed session errors extend the SDK's McpError, whose constructor bakes the JSON-RPC code into .message, and sessionErrorToResult copied that verbatim.

  • src/errors/debug-errors.ts — new DebugError base (extends McpError) that records the plain text as detail; every typed error moves onto it. .message is untouched, so the JSON-RPC path (dispatch rethrows McpError; the SDK derives the wire error from the code) still carries the prefix. getErrorMessage() reports detail for a DebugError.
  • src/server/tool-result.tssessionErrorToResult puts error.detail in the envelope. This is the single choke point every handler family goes through, so no handler changes.
  • Rider: list_threads' failure now reads Cannot list threads: … (was Cannot listThreads: …).
  • Tests: tool-result.test.ts pins the un-prefixed envelope; new tests/core/unit/errors/debug-errors.test.ts covers every class (.message prefixed, .detail plain, .data structured, getErrorMessage).
  • Docs: the step_over/into/out report success:false with the message "Stepped over", dropping the actual reason #638 case study, which quotes the prefixed envelope, notes the fix. Changelog fragment changelog.d/647.fixed.md.

Verified live (mcp-debugger on mcp-debugger)

Before the fix, a javascript attach session on the running HTTP backend paused in sessionErrorToResult showed error.message = 'MCP error -32600: Cannot step over: …', error.detail = undefined, and the envelope carried the prefix. After dev_rebuild_and_restart, the same step_over on a never-started mock session returns:

{"success":false,"error":"Cannot step over: no active proxy for session 497e3ff0-…"}

Two usability defects surfaced by that probe are filed separately: #654 (attach pauses the target by default without the schema saying so) and #655 (js stack traces full of node_modules/phantom source-mapped frames).

Fixes #647

🤖 Generated with Claude Code

https://claude.ai/code/session_01SNhNB42Y55cgsknYTQb2Bm

…lopes (#647)

The typed session errors (SessionNotFoundError, SessionTerminatedError,
ProxyNotRunningError, and the rest of the hierarchy) extend the SDK's
McpError, whose constructor bakes `MCP error <code>: ` into .message.
sessionErrorToResult copied that verbatim into every {success:false, error}
envelope, so an agent read "MCP error -32600: Cannot step over: no active
proxy for session …" — protocol plumbing in an application payload.

Introduce DebugError, an intermediate base that records the plain text as
`detail` (the SDK keeps no copy of it), move every typed error onto it, and
have sessionErrorToResult and getErrorMessage report `detail`. .message is
unchanged, so the JSON-RPC path — where dispatch rethrows McpError and the
SDK derives the wire error from the code — still carries the prefix.

Rider: list_threads' ProxyNotRunningError read "Cannot listThreads: …";
it now reads "Cannot list threads: …".

Fixes #647

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SNhNB42Y55cgsknYTQb2Bm
@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@debugmcpdev
debugmcpdev merged commit 76e0fa6 into main Sep 2, 2026
9 checks passed
@debugmcpdev
debugmcpdev deleted the fix/647-session-error-prefix branch September 2, 2026 10:04
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.

Typed session errors leak the "MCP error -32600:" prefix into tool result error fields

1 participant