Skip to content

POST /mcp returns a local tool's exception text in the refund_failed error; /mcp/messages and REST invoke do not #441

Backlog

Description

@PetrefiedThunder

Summary

When a local tool raises and the refund of its charge then fails, POST /mcp answers with the JSON-RPC message refund_failed; tool_error:<the tool's exception text>, on the first call and on every replay. POST /mcp/messages and the REST invoke route answer refund_failed for the same stored record. A code comment and the docs describe the first behavior. A disclosure test asserts the second, for /mcp/messages only.

Severity: low. Only an authenticated caller that is allowed on that wallet receives the text. No money moves differently, and the receipt's reason_code is refund_failed on every route. This is an inconsistency between routes, with a small disclosure of an operator tool's exception text to the wallet's own caller.

Affected area

  • spec
  • verifier
  • Python SDK
  • TypeScript SDK
  • integration
  • example
  • gateway
  • build or tooling
  • Other:

Version or commit

main at 37618e049f589318d30112f4e9cc5c656c57cdbd. Line numbers are at that commit. Also tested at the #330 head 707ba293ade3b2de06ff1ac7e5646a4d0411b25c, with the same result. By reading, the #331 head 6af04421c0900c7808b3d84328ae8f12dfc6b7cd has the same line, at gateway/app/routers/mcp_standard.py line 911. It was not run there.

Steps to reproduce

  1. Register a local in-process tool that raises an exception with a recognizable text.
  2. Make the refund of its charge fail. The tests injected this.
  3. Call the tool through POST /mcp, then send the same request again as a replay.
  4. For comparison, do the same through POST /mcp/messages and through the REST invoke route.

Expected behavior

One contract on all three routes, and docs and tests that state it.

Actual behavior

Measured with a local tool whose exception text held a marker, a file path and an SQL fragment:

  • POST /mcp: error.message carried the whole text, on the first call and on replays. data.code was internal_error and data.fix was "Try again later.".
  • POST /mcp/messages: message refund_failed, data.code refund_failed.
  • REST invoke: detail.error refund_failed.
  • The exception text of the refund store was on no route.
  • For a local tool whose refund succeeds, every route answers tool_execution_failed without the tool's text.
  • For an upstream tool the part after the colon is a fixed code, for example upstream_returned_error. No upstream text travels in the message.
  • Side effect: /mcp says "Try again later.", while gateway/docs/denial-details.md says for refund_failed not to retry the action.

Logs or minimal reproduction

  • gateway/app/routers/mcp_standard.py line 894: message = "tool_execution_failed" if e.tool_originated else str(e).
  • The reason is built in gateway/app/routers/mcp.py: refund_failed; tool_error:{exc} for a local tool (line 3119) and refund_failed; upstream_error:{reason} for an upstream tool (line 3857). It is stored for replay.
  • /mcp/messages reduces it to refund_failed (mcp.py line 538). The REST invoke route does the same (mcp.py lines 5276 to 5278).
  • The disagreement in the repository:
    • The comment at mcp.py lines 3113 to 3117 and gateway/docs/denial-details.md lines 231 to 233 say the reason that travels names the tool's error.
    • gateway/tests/test_mcp_internal_error_disclosure.py lines 320 to 326 assert that the message is refund_failed (line 323) and that the tool's text is absent (line 326). The test covers /mcp/messages only. Its docstring (lines 268 to 269) says the message carries only the tool's error, which the assert at line 326 contradicts.
  • History: fix(mcp): answer -32006 for a failing local tool, never its text #383, merged on 2026-11-26, stopped POST /mcp from sending a failing local tool's text when the charge was refunded. It left this path unchanged: the receipt outcome here is failed_unrefunded, and fix(mcp): answer -32006 for a failing local tool, never its text #383 kept it at -32603.
  • Related: AWI: /dom/sync signs a reason_code containing the session UUID, and charges with zero commands executed #354 is about a different route. BUG-AMA-003: API errors lack a next step #253 is about errors that lack a next step. Neither covers this.
  • The scratch tests are available on request.

Environment

Suggested next step

  • Decide the contract first.
  • If the tool's text must not travel: build the message at mcp_standard.py line 894 with the function that /mcp/messages uses (_public_jsonrpc_message, mcp.py line 505). Then correct the comment, the doc lines and the test docstring above, and add POST /mcp to the disclosure test. Not done here: a run of the existing suite with that change.
  • If the tool's text is meant to travel: the doc stands, and /mcp/messages, the REST invoke route and the disclosure test change.

Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions