MCP Tool Error Handling: isError, Error Categories and Retries
👋 In plain words: Tools fail: servers time out, inputs are wrong, rules forbid an action. If a tool just says 'Operation failed', Claude can't tell whether to retry, fix something, or explain to the user. This lesson shows how to return errors that help Claude recover sensibly.
When a tool fails, the agent can only recover sensibly if it knows why. A generic “Operation failed” leads to pointless retries of policy violations and early surrender on simple timeouts. This is Task Statement 2.2.
🔑 Key terms
- MCP server: A small program that offers tools (and data) to Claude through the Model Context Protocol.
- isError: A flag on a tool result saying 'this call failed'.
- Transient error: A temporary failure, such as a timeout, that may work if you try again.
- Business error: The action broke a rule, such as a refund outside the 30-day window. Retrying won't help.
- Retryable: Whether trying again could succeed.
📖 The story in this lesson
ShopNest's refund tool can fail in four ways: the payment server is slow, the date was typed wrongly, the order is outside the 30-day window, or the bot lacks permission. Each failure needs a different response.
💡 Think of it like this
A good error is like a helpful shop assistant. 'Sorry, the till is rebooting, try again in a minute' (temporary). 'That date isn't valid, please use DD/MM' (fix the input). 'We can't refund after 30 days' (a rule). 'Only the manager can do that' (permission). 'Error' on its own helps nobody.
🚨 The isError pattern
MCP tools signal failure with isError: true in the tool result. Put structured metadata in the content:
{
"isError": true,
"content": [{"type": "text", "text": "{\"errorCategory\": \"business\", \"isRetryable\": false, \"message\": \"Refund window is 30 days; this order was delivered 41 days ago.\", \"customerMessage\": \"This order is outside our 30-day refund window.\"}"}]
}
🌍 Real-world example: A refund outside the window
Instead of throwing a raw error, the refund tool returns a result with isError set, a category, whether a retry could work, and a message the bot can pass on to the customer.
{"isError": true, "errorCategory": "business", "isRetryable": false,
"customerMessage": "This order is outside our 30-day refund window."}🚨 Four error categories
| Category | Example | Retryable? | Agent should… |
|---|---|---|---|
| Transient | Timeout, 503 | Yes | Retry with backoff |
| Validation | Bad date format | Yes, after fixing input | Correct and retry |
| Business | Policy limit exceeded | No | Explain or escalate |
| Permission | Not authorised | No | Escalate or request access |
🌍 Real-world example: Four failures, four responses
A timeout: retry after a short wait. A date in the wrong format: correct it and retry. Outside the refund window: explain to the customer, no retry. No permission: escalate to a human. One category field lets Claude choose correctly every time.
🚨 Empty result is not an error
“No orders found for this customer” is a successful query with zero matches. A database timeout is an access failure. Reporting empty results as errors triggers retries; reporting failures as empty results hides problems.
🌍 Real-world example: 'No orders' vs 'database down'
A new customer has no orders, so the search correctly returns an empty list as a success. On another day the database times out, which is an error. When ShopNest once reported both as 'no orders', customers were told they had never ordered while the database was down.
📘 Local recovery in multi-agent systems
Subagents should handle transient failures themselves and propagate only what they can’t resolve — with what they attempted and any partial results — so the coordinator can decide what to do next.
🌍 Real-world example: The subagent retries first
A search subagent hits a timeout. It retries twice by itself, which works most of the time. Only when it still fails does it report to the coordinator, saying what it tried and including the 3 results it did get.
🛠️ Try it yourself (about 8 minutes)
- List three ways a tool you use could fail.
- Label each one transient, validation, business or permission.
- Write the JSON error for the business case, including a customer-friendly message.
✅ You are done when: each failure has a category and a retryable yes or no, and the JSON includes isError.
🧪 Exam-Style Practice Questions
Try these before opening the answers. They use the same scenario style as the real exam.
Question 1. An MCP tool times out. What should it return?
- A. A Python stack trace
- B. A result with
isError: trueand structured metadata (category transient, retryable) - C. An empty array
- D. Nothing; let the client hang
Show answer
Answer: B. It's structured and actionable. C disguises a failure as "no data". A is noisy and possibly leaks internals. D is broken behaviour.
Question 2. A search returns no matching orders for a valid customer. How should the tool report this?
- A. As an error with
isRetryable: true - B. By throwing a timeout
- C. As a successful result with an empty list
- D. As a permission error
Show answer
Answer: C. A valid query with zero matches is a success. Treating it as an error (A, D, B) triggers pointless retries or escalation.
Question 3. Which error should not be retried?
- A. Network timeout
- B. 503 Service Unavailable
- C. Rate limited
- D. "Refund exceeds the 30-day policy window"
Show answer
Answer: D. A business-rule violation: retrying won't change the outcome, so explain it or escalate. A, B and C are transient.
📝 Assignment
Do these tasks in order. Each one has a Done when check, so you know when it is complete. The stretch task is optional but close to what the exam expects from an architect. Keep your answers in one notes file or Git repository, and revisit them in your final week of revision together with the cheat sheet in the last lesson of this course.
- Task 1: List three failures your own tools can produce and classify each as transient, validation, business or permission.
✅ Done when: Each failure is assigned exactly one category and marked retryable or not retryable, with a reason. - Task 2: Write the JSON error body for a business-rule failure, including a customer-friendly message.
✅ Done when: Your JSON includes isError, errorCategory, isRetryable and a message a customer could read without confusion. - Stretch: make a subagent retry a transient error locally and report partial results to the coordinator only if it still fails.
✅ Done when: A simulated timeout is retried inside the subagent, and only a persistent failure reaches the coordinator with partial results.
❓ Frequently Asked Questions
🤔 What is the isError flag in MCP?
A field on the tool result that tells the client and Claude the tool call failed.
🤔 Which errors should not be retried?
Business-rule violations and permission errors. Retrying cannot change their outcome.
🤔 Is no results an error?
No. A valid query that matches nothing is a successful result with an empty list.
🤔 Why is 'Operation failed' a bad error message?
It hides whether the failure is temporary, caused by bad input or a policy, so the agent cannot choose a sensible recovery.
🏁 Summary
- Return
isErrorplus errorCategory, isRetryable and a readable message. - Business and permission errors are not retryable.
- Empty ≠ failure.
Next, continue with MCP Integration in Claude Code: Scopes, Resources and Built-in Tools.
Independent study material by SQA Tools. Not affiliated with, endorsed by or sponsored by Anthropic. Claude is a trademark of Anthropic. Mock questions are original practice items, not real exam content. Exam facts checked against Anthropic's official exam guides and certification FAQ on 11 November 2026.