Repository navigation
Description
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
- Register a local in-process tool that raises an exception with a recognizable text.
- Make the refund of its charge fail. The tests injected this.
- Call the tool through
POST /mcp, then send the same request again as a replay. - For comparison, do the same through
POST /mcp/messagesand 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.messagecarried the whole text, on the first call and on replays.data.codewasinternal_erroranddata.fixwas "Try again later.".POST /mcp/messages: messagerefund_failed,data.coderefund_failed.- REST invoke:
detail.errorrefund_failed. - The exception text of the refund store was on no route.
- For a local tool whose refund succeeds, every route answers
tool_execution_failedwithout 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:
/mcpsays "Try again later.", whilegateway/docs/denial-details.mdsays forrefund_failednot to retry the action.
Logs or minimal reproduction
gateway/app/routers/mcp_standard.pyline 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) andrefund_failed; upstream_error:{reason}for an upstream tool (line 3857). It is stored for replay. /mcp/messagesreduces it torefund_failed(mcp.pyline 538). The REST invoke route does the same (mcp.pylines 5276 to 5278).- The disagreement in the repository:
- The comment at
mcp.pylines 3113 to 3117 andgateway/docs/denial-details.mdlines 231 to 233 say the reason that travels names the tool's error. gateway/tests/test_mcp_internal_error_disclosure.pylines 320 to 326 assert that the message isrefund_failed(line 323) and that the tool's text is absent (line 326). The test covers/mcp/messagesonly. Its docstring (lines 268 to 269) says the message carries only the tool's error, which the assert at line 326 contradicts.
- The comment at
- History: fix(mcp): answer -32006 for a failing local tool, never its text #383, merged on 2026-11-26, stopped
POST /mcpfrom sending a failing local tool's text when the charge was refunded. It left this path unchanged: the receipt outcome here isfailed_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
- OS: Linux
- Runtime and version: Python 3.12, pytest with an in-process client, SQLite
- Package or deployment details: the gateway at the two commits named first above. Nothing was run on PostgreSQL or at the fix(trust): a retired signing key refuses to sign instead of reactivating #331 head.
Suggested next step
- Decide the contract first.
- If the tool's text must not travel: build the message at
mcp_standard.pyline 894 with the function that/mcp/messagesuses (_public_jsonrpc_message,mcp.pyline 505). Then correct the comment, the doc lines and the test docstring above, and addPOST /mcpto 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
Activity
Scope the refund_failed comment and doc to what holds on every path