fix(mcp): shape a remote JSON-RPC error into a tool result in the gateway proxy - #10216
Conversation
…eway proxy
registerProxiedTool's handler returned `result ?? payload` verbatim. The remote
runs with enableJsonResponse, so a request-level failure (an unknown tool, bad
arguments) still arrives as HTTP 200 with `{ jsonrpc, id, error }` and no
`result` key -- apiPost only throws on a non-2xx status, so that raw envelope
reached the caller as if it were the tool's own answer: no content, no
isError, not a CallToolResult at all. wrapStdioToolHandler's
`ok = result?.isError !== true` then read every one of those as a success,
since the envelope carries no isError of its own.
The handler now inspects what came back: a `result` is still returned
unwrapped and unchanged, but an `error` (or a payload carrying neither) is
shaped into a conformant isError:true result with a closed-set
{ error: { code, message } } envelope, classifying the remote's message
through resolveErrorCode rather than surfacing its numeric JSON-RPC code as
the telemetry error_code.
|
Tip ✅ LoopOver review result - approve/merge recommendedReview updated: 2026-07-31 13:02:34 UTC
Review summary Nits — 3 non-blocking
Decision drivers
Context & advisory signals — never blocks the verdict
Linked issue satisfactionAddressed Review context
Contributor next steps
Signal definitions
🧪 Chat with LoopOverAsk LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.
Full command reference: https://loopover.ai/docs/loopover-commands 🧪 Experimental — new and may change. 🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.
|
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10216 +/- ##
==========================================
- Coverage 80.47% 80.09% -0.38%
==========================================
Files 282 283 +1
Lines 58844 61056 +2212
Branches 6977 7804 +827
==========================================
+ Hits 47354 48905 +1551
- Misses 11199 11521 +322
- Partials 291 630 +339
Flags with carried forward coverage won't be shown. Click here to find out more.
|
fix(mcp): shape a remote JSON-RPC error into a tool result in the gateway proxy
registerProxiedTool's handler returned
result ?? payloadverbatim. The remoteruns with enableJsonResponse, so a request-level failure (an unknown tool, bad
arguments) still arrives as HTTP 200 with
{ jsonrpc, id, error }and noresultkey -- apiPost only throws on a non-2xx status, so that raw envelopereached the caller as if it were the tool's own answer: no content, no
isError, not a CallToolResult at all. wrapStdioToolHandler's
ok = result?.isError !== truethen read every one of those as a success,since the envelope carries no isError of its own.
The handler now inspects what came back: a
resultis still returnedunwrapped and unchanged, but an
error(or a payload carrying neither) isshaped into a conformant isError:true result with a closed-set
{ error: { code, message } } envelope, classifying the remote's message
through resolveErrorCode rather than surfacing its numeric JSON-RPC code as
the telemetry error_code.
Closes #10036