Error Handling in MCP: Designing Resilient Tool Workflows
Build robust MCP workflows that handle errors gracefully. This guide explains common error categories (authentication, validation, network, rate limits) and shows you how to design prompts that recover from failures with reusable recovery templates.
Error Categories
Authentication Errors (401, 403)
Auth Error Recovery
Common causes:
- Invalid or expired API key
- Missing Authorization header
- Insufficient permissions
Validation Errors (400)
Validation Error Recovery
Common causes:
- Missing required fields
- Invalid field format (dates, IDs)
- Invalid field values
Network Errors
Network Error Recovery
Common causes:
- Network connectivity issues
- Server timeout
- DNS resolution problems
Rate Limiting (429)
Rate Limit Recovery
Common causes:
- Too many requests in short time
- Large batch operations
- Tool call loops
Recovery Prompt Templates
Template 1: Graceful Failure
Error Handling Pattern
This pattern: Handles errors gracefully, provides guidance, asks for direction
Template 2: Retry with Backoff
Retry Pattern
This pattern: Handles transient errors, prevents infinite retries
Template 3: Fallback Strategy
Fallback Pattern
This pattern: Tries alternative approaches when primary fails
Complete Examples
Example 1: Resilient Task List
Error-Resilient Prompt
This pattern: Handles all error types with appropriate recovery
Example 2: Safe Batch Operation
Error-Resilient Batch Update
This pattern: Partial success handling, user-controlled retries
Best Practices
Error Handling Best Practices
- Show errors clearly: Always display error messages to the user
- Explain in plain language: Translate technical errors to understandable terms
- Suggest fixes: Provide actionable steps to resolve errors
- Limit retries: Don't retry indefinitely—set reasonable limits
- Handle partial success: For batch operations, show what succeeded/failed
- Ask before retrying: For critical operations, ask permission before retry
Related Resources
Troubleshooting Index
Complete troubleshooting guide
Tool Call Failures
Debug tool call issues
Rate Limiting
Handle rate limits
Batching Guide
Reduce tool calls
Build Resilient MCP Workflows
Use error handling patterns to create robust prompts that recover gracefully
