Back to catalog / MCP servers
Define a stable error contract for MCP tools
Separate retryable failures, input rejections, and internal faults without exposing server secrets.
Goal
Let MCP clients choose a safe, predictable next action from the error type.
Steps
- List possible argument errors, permission denials, unavailable dependencies, and unexpected exceptions. [mcp-errors] [mcp-tools]
- Raise
ToolErrorfor recoverable tool failures; raiseMCPError(code, message, data)for protocol-level rejection. [mcp-errors] [mcp-tools] - Do not return an error string; inspect
CallToolResult.is_error, and keep unexpected crash details in server logs. [mcp-errors] [mcp-tools] - Log a controlled diagnostic ID server-side and keep full internal exceptions in protected logs. [mcp-errors] [mcp-tools]
- Inject each failure class and verify client response, retry behavior, and log redaction. [mcp-errors] [mcp-tools]
How to verify
Every error class has a predictable response; stacks, tokens, and connection details appear in neither client responses nor ordinary logs.
Troubleshooting
If internal details leak, sanitize the exception mapping and separate protected server logs from client errors.
Permissions
Prerequisites
- Python 3.10+ and the MCP Python SDK compatible with the pinned revision
Permissions
- Use a local or isolated test environment; use least privilege and approval for external data or side effects
Limitations
SDK behavior varies by version. Check the pinned revision against your agent or client, then review data retention, authorization, and side effects before production use.
Pinned upstream source
- Repository
- modelcontextprotocol/python-sdk
- File path
- docs/servers/handling-errors.md
- Pinned commit
754254c08fe1c3eda18b69da3d336106fe8d72d6- Source checked
- 2026-10-14 · Reviewed against the pinned upstream source
Repository metrics
These values describe the upstream repository, not popularity or likes for an individual skill or playbook.
- Stars
- Not collected
- Forks
- Not collected
- Observed at
- Not collected
No metrics snapshot is available yet.
License: MIT