Agent Wealth HubFree public resources
中文 EN العربية

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

  1. List possible argument errors, permission denials, unavailable dependencies, and unexpected exceptions. [mcp-errors] [mcp-tools]
  2. Raise ToolError for recoverable tool failures; raise MCPError(code, message, data) for protocol-level rejection. [mcp-errors] [mcp-tools]
  3. Do not return an error string; inspect CallToolResult.is_error, and keep unexpected crash details in server logs. [mcp-errors] [mcp-tools]
  4. Log a controlled diagnostic ID server-side and keep full internal exceptions in protected logs. [mcp-errors] [mcp-tools]
  5. 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

Permissions

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

https://github.com/modelcontextprotocol/python-sdk/blob/754254c08fe1c3eda18b69da3d336106fe8d72d6/docs/servers/handling-errors.md

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

Main topic

When to use a Skill or MCP

Related resources