MCP tool error handling: isError for payment tools
If a tool ran and failed, return a normal result with isError: true and a message the model can act on. Save JSON-RPC errors for unknown tools, malformed requests and server errors. That's the MCP spec's split. For a tool that spends money, each error also has to say two more things: whether money moved, and whether the same call is safe to repeat. Most error-handling guides skip both.
The guides that rank for this are SDK and gateway docs plus a couple of blog posts, and their examples are weather lookups and travel bookings. This guide starts from what the current MCP tools specification says, read on 2026-11-29 (version 2026-07-28), and then covers the cases that only show up when a tool can charge a card. It ends with an audit of our own server, which doesn't get all of this right yet.
The two error channels in the spec
The spec defines two ways for a tool call to fail:
| Channel | Use it for | Shape | Does the model see it? |
|---|---|---|---|
| Protocol error | Unknown tool; a malformed request that fails the CallToolRequest schema; server errors | JSON-RPC error object, e.g. code -32602 | Clients MAY pass it on; the spec says these are "less likely to result in successful recovery" |
| Tool execution error | API failures; input validation errors ("date in wrong format, value out of range"); business logic errors | result with content and isError: true | Clients SHOULD pass it on "to enable self-correction" |
The spec's own example of a tool error is a validation failure:
{
"jsonrpc": "2.0",
"id": 4,
"result": {
"resultType": "complete",
"content": [
{ "type": "text",
"text": "Invalid departure date: must be in the future. Current date is 08/08/2025." }
],
"isError": true
}
}
The message includes the current date, so the model has what it needs to fix the call. A good tool error is one the model can act on without asking a human.
Where the SDK and the spec disagree
The spec still lists "Unknown tool" as a protocol error. The TypeScript SDK went further. Pull request 1044, merged on 28 October 2025, changed calls to non-existent tools, calls to disabled tools, and inputSchema validation failures to return a result with isError: true. The reason given was that otherwise "the LLM would not be able to see that an error occurred and self-correct." Clients will see both shapes in practice, so handle both. Apollo's MCP server error-handling docs give the client-side order: treat a JSON-RPC error as a protocol failure, then check result.isError before parsing content. An HTTP 2xx only means the request was accepted.
Why payment tools need more than isError
A weather tool that fails has no side effects. A purchase tool can fail after the side effect: the charge goes through, then the provider call times out, then your handler throws. If the error only says "something went wrong, try again", the model will try again. Alpic's July 2025 post on tool error responses recommends "try again immediately" guidance for unknown errors. That's reasonable for reads and risky for writes. A retry is only safe if the tool deduplicates, which is what MCP tool idempotency covers.
The spec also says a client SHOULD "implement timeouts for tool calls". A timeout is the case where neither side knows for sure what happened. The client gave up and the server may still have charged. Your error design has to cover that case too, because there's no error response at all.
The checklist: 9 rules for tools that spend money
- Return business failures as
isError: true, never as an empty success. "Card declined", "product sold out" and "spending cap reached" are business logic errors under the spec. A result with noisErrorand anerrorkey buried in JSON text looks like success to any client that checks the flag. - Give every error a stable code. Put
code,messageand any fields instructuredContent, and copy the JSON into a text block. The spec says a tool returning structured content SHOULD also return the serialized JSON as text, for backwards compatibility. Orchestrators branch on the code and the model reads the message. - Say whether money moved. Add
charged: false,trueor"unknown"to every error from a purchase tool. It's the first thing a human will ask, and the model can't infer it from "provider error". - Say whether a retry is safe. Add
retryableand, for rate limits,retry_after_seconds. Mark a charge-side failure retryable only if the tool takes an idempotency key and the client will resend the same one. - Separate denials from failures. A spending cap or consent rule saying no is working as designed. Return it as a tool error with its own code and the reason, so the model can show it to the human and stop, rather than trying a cheaper item on its own. Our spending-limit checklist covers where those caps live.
- Tell the model what to do next, including "ask the human". "buyer_email is required" is better than "invalid input", and "ask the user for an email address, then call again" is better still. For anything that needs a person, such as paying a hosted checkout, say so plainly. The patterns are in URL elicitation for payments.
- Make "did it happen?" answerable. Return an order ID as early as you can, even on error, and expose a read-only status tool. After a timeout the model can check the order rather than buy again.
- Sanitize what you return. The spec says servers MUST "sanitize tool outputs". Don't pass provider stack traces, API keys, internal URLs or a customer's card details into a message the model will repeat.
- Treat expired state as a tool error. The spec's guidance on stateful tools says a call with an expired or unknown handle, such as a basket ID, "should return a tool execution error that says so, so the model can recover by creating a new one." The same goes for an expired checkout session.
A worked example
A gift-card tool where the buyer's card is from the same country as the gift card, which our catalog doesn't sell:
{
"jsonrpc": "2.0",
"id": 7,
"result": {
"isError": true,
"content": [
{ "type": "text",
"text": "{\"code\":\"gift_card_domestic_buyer\",\"charged\":false,\"retryable\":false,\"message\":\"Gift cards are sold cross-border only. This card is redeemable in GB and the payment card was issued in GB. Tell the user to buy it locally, or pick a gift card for another country.\"}" }
],
"structuredContent": {
"code": "gift_card_domestic_buyer",
"charged": false,
"retryable": false,
"redeem_country": "GB",
"message": "Gift cards are sold cross-border only. ..."
}
}
}
The model learns it shouldn't retry, nobody was charged, and there's a next step to suggest. An orchestrator can branch on code without reading English. If the tool declares an outputSchema, remember the spec says servers MUST return structured results that match it. Either include the error shape in the schema, or leave structuredContent off error results.
An error table for a commerce MCP server
These are the error codes our server uses today, with how we'd classify each under the rules above:
| Code | Channel | Charged? | Retry? | What the model should do |
|---|---|---|---|---|
buyer_email_required | isError | No | Yes, with the field | Ask the user for an email |
product_not_found | isError | No | No | Search again; the catalog changes weekly |
no_matching_product | isError | No | With different input | Offer another amount or product type |
country_undetermined | isError | No | With a country code | Ask which country the number is from |
rate_limited | isError | No | After retry_after_seconds | Wait, then retry once |
gift_card_domestic_buyer | isError | No | No | Suggest buying locally |
envelope_denied | isError | No | No | Show the reason; the human raises the cap or approves |
envelope_charge_failed | isError | Should be stated | Only with the same key | Check order status before anything else |
| Unknown tool | Protocol (spec) or isError (TS SDK) | No | No | Re-list tools |
What our own server gets wrong today
We read cartapi's MCP handler against this checklist on 2026-11-29. Some of it is fine. Every failure path returns a JSON body with an error code and a message. Rate limits include retry_after_seconds. Envelope denials come back as structured control flow, not as logged exceptions. Searches that find nothing return a hint pointing to the right discovery tool.
The gaps:
- No
isErrorflag. Errors are returned as ordinary text content, so a client that checksisErrorsees success. Rule 1 is the fix. - Unknown tools come back as a result, not as the spec's
-32602protocol error, and withoutisError. That matches neither the spec nor the SDK. - Argument validation falls through to a generic
tool_failedwith the validator's raw message, rather than a code that names the bad field. - No
chargedorretryablefields, and the purchase tools don't take an idempotency key yet. Each call generates its own, as the idempotency guide explains. On the default hosted-checkout path a retry only creates a second unpaid link. On the consent-envelope path it could charge twice, within the envelope's caps.
All four are on our list. The tool annotations guide covers the related step of labelling which tools are read-only and which spend money. The wider design is in consent-first checkout.
FAQ
What is isError in MCP?
isError is a boolean on a tools/call result. When it is true, the tool ran but failed, and the content explains why. The MCP specification calls these tool execution errors and says clients should pass them to the model so it can self-correct.
When should an MCP server return a JSON-RPC error instead of isError?
The specification reserves JSON-RPC protocol errors for an unknown tool, a malformed request that fails the CallToolRequest schema, and server errors. API failures, input validation errors and business logic errors go in a normal result with isError set to true.
Is an invalid argument a protocol error or a tool error in MCP?
A tool error. The specification lists input validation errors, such as a date in the wrong format or a value out of range, as tool execution errors reported with isError: true. The TypeScript SDK made the same change for inputSchema validation failures in pull request 1044, merged in October 2025.
Should an MCP error tell the model to retry?
Only when a retry is safe. For a read-only tool, retry guidance is fine. For a tool that charges money, the error should say whether a charge happened and whether the same call can be repeated, and the tool should take an idempotency key so a retry can't buy twice.
Should MCP errors include structuredContent?
It helps. A machine-readable code, a retryable flag and a charged field let a client or orchestrator branch without parsing prose. The specification says a tool returning structured content should also return the serialized JSON in a text block for backwards compatibility.
Try it
Add cartapi from the install page and ask your agent to buy something from a country we don't cover. You'll see the error and hint shapes described above, and nothing is bought without a checkout you approve.