Failure as Information
When an AI agent calls an MCP server tool and it fails, the error message enters the agent's context. Unlike a scripted program that follows a predetermined error path, the agent can reason about the error and choose a response based on what the error tells it.
A "table not found" error tells the agent to check the table name. A "permission denied" error tells the agent that this approach won't work regardless of retries. A "timeout" error tells the agent that the operation might succeed if tried again or with simpler parameters. Good error messages enable this kind of reasoning. Bad ones leave the agent guessing.
Retry Strategies
Not all failures deserve the same response. The agent needs to distinguish between transient errors (which might succeed on retry) and permanent errors (which won't). A network timeout is transient. A missing table is permanent. A rate limit error is transient but needs a delay before retrying.
Well-designed agents implement graduated retries: try once more immediately for unexpected errors, wait and retry for rate limits, and pivot to an alternative approach for permanent failures. This is more sophisticated than the simple "retry three times" pattern and produces better outcomes.
Alternative Approaches
The most valuable failure response is finding a different path to the same goal. If querying a specific table fails, can the agent find the data in a different table? If one API endpoint is down, is there an alternative endpoint? If a file can't be read directly, can the agent search for it first to get the correct path?
This ability to find alternative approaches is one of the key advantages of agents over rigid scripts. A script follows one path and fails if that path is blocked. An agent can reason about alternative paths and try them, often succeeding where a script would have given up.
Preventing Repeated Failures
Good agents remember what failed within a session. If querying a table with a certain name failed, the agent shouldn't try the exact same query again three steps later. This seems obvious, but without explicit instructions about tracking failures, agents sometimes do repeat themselves, especially in long tasks where the original failure has scrolled out of active attention.
Including instructions like "If a tool call fails, note the failure and do not repeat the same call with the same parameters" in your agent's prompt helps prevent wasteful retries.
Related Reading
- How to Debug an AI Agent That Keeps Making Mistakes
- The Agent Loop: How Autonomous AI Systems Make Decisions
- How Error Messages from MCP Servers Affect Agent Behavior
Discover AI agents on Skillful.sh. Search 137,000+ AI tools.