fix(server): keep the "MCP error <code>:" prefix off tool result envelopes (#647) - #656
Merged
Merged
Conversation
…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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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
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'sMcpError, whose constructor bakes the JSON-RPC code into.message, andsessionErrorToResultcopied that verbatim.src/errors/debug-errors.ts— newDebugErrorbase (extendsMcpError) that records the plain text asdetail; every typed error moves onto it..messageis untouched, so the JSON-RPC path (dispatch rethrowsMcpError; the SDK derives the wire error from the code) still carries the prefix.getErrorMessage()reportsdetailfor aDebugError.src/server/tool-result.ts—sessionErrorToResultputserror.detailin the envelope. This is the single choke point every handler family goes through, so no handler changes.list_threads' failure now readsCannot list threads: …(wasCannot listThreads: …).tool-result.test.tspins the un-prefixed envelope; newtests/core/unit/errors/debug-errors.test.tscovers every class (.messageprefixed,.detailplain,.datastructured,getErrorMessage).changelog.d/647.fixed.md.Verified live (mcp-debugger on mcp-debugger)
Before the fix, a
javascriptattach session on the running HTTP backend paused insessionErrorToResultshowederror.message = 'MCP error -32600: Cannot step over: …',error.detail = undefined, and the envelope carried the prefix. Afterdev_rebuild_and_restart, the samestep_overon 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