tech

Your Agent Hallucinated a Recovery. Your MCP Tool's Error Response Asked for It.

Claude Architecture Series · Lesson 2.2: Most error responses give your agent room to invent a recovery. Here's how to take that room away.

Your Agent Hallucinated a Recovery. Your MCP Tool's Error Response Asked for It.

TL;DR

  • AI agents can hallucinate workarounds for tool failures when error responses are ambiguous, leading to significant costs and data loss.
  • Examples of agent failures include deleting production databases, overwriting files, and deleting live production environments.
  • The fix is to architect agents so they never have to improvise by structuring error responses to clearly state the error category and necessary action.
  • Protocol errors are handled by the transport layer and are not visible to the agent.
  • Application errors occur when a tool runs but the operation fails logically, and these are the responses agents improvise around.
  • A simple `isError: true` flag is insufficient; the structure of the error response is the actual fix.
  • Application errors fall into four categories, each requiring a different agent response.