Return MCP errors the agent can act on
Return MCP tool failures as isError results with an error category, a retryable flag and a readable description, keep valid empty results apart from failures, and pick how the agent should react to each kind of error.
Scenario
Your Customer Support Resolution Agent handles refunds through a custom MCP tool, process_refund. On Monday a customer asks for a refund on a jacket bought 75 days ago. Your policy allows 60.
The tool returns Operation failed. The agent retries twice, gets the same answer, and tells the customer "we're having a technical issue, please try again later". The customer tries again on Tuesday.
The same two words came back on Friday when the payment gateway timed out, and that time a retry would have worked. The agent had no way to tell the two apart.
Explanation
Mark the failure as a failure. An MCP tool result has a content array and an optional isError flag. With isError: true, Claude reads the result as a failed call, not as odd-looking data, and can retry, try another tool or explain the problem. In the Agent SDK, a handler that throws gets converted to an error result carrying the raw exception message. Catching the error yourself and returning isError: true lets you compose the message Claude reads.
Say what kind of failure it is. A uniform "Operation failed" leaves the agent guessing. Four kinds need four different reactions:
| Category | Example | Retry? | What the agent does |
|---|---|---|---|
| transient | gateway timeout, service down | yes | retry, or try again shortly |
| validation | amount is negative, bad order id | not as is | fix the input, or ask the customer |
| business | past the refund window | no | explain the rule to the customer, offer an alternative or escalate |
| permission | agent may not refund above $500 | no | escalate to someone who can |
Return that as structured metadata: an errorCategory, an isRetryable boolean, and a description the agent can use. For a business error, write the description so the agent can pass it to the customer ("Refunds are possible within 60 days of delivery; this order was delivered 75 days ago"). That one flag stops wasted retries; the description stops "technical issue" replies.
An empty result is not an error. lookup_order that runs fine and finds no orders for an email address should return an empty list with no isError: the query succeeded, and "no orders" is the answer. If the database timed out, that is a transient error. Returning an empty list for a timeout tells the agent the customer has no orders, which is false.
Recover locally, propagate what's left. A subagent or tool layer should retry transient failures itself. Only an error it can't resolve goes up to the coordinator, with what was tried and any partial results, so the coordinator can decide instead of starting over.
Worked example
Before: every failure looks the same.
return {
content: [{ type: "text", text: "Operation failed" }],
isError: true,
};
After: the refund past the window, in process_refund's handler.
return {
content: [{
type: "text",
text: JSON.stringify({
errorCategory: "business",
isRetryable: false,
description: "Refunds are possible within 60 " +
"days of delivery; delivered 75 days ago.",
}),
}],
isError: true,
};
The agent now knows not to retry, has a sentence it can explain to the customer, and can offer store credit or escalate. The gateway timeout gets errorCategory: "transient" and isRetryable: true, and the agent retries it instead of apologizing.