MCP Error Codes
Error Hierarchy
Base Error Classes
McpError (Abstract)
Base class for all MCP-related errors.PublicMcpError
Errors safe to expose to clients (validation errors, not found, etc.).InternalMcpError
Errors that should NOT expose details (server errors, unexpected failures).Error Categories
Tool Errors
ToolNotFoundError, ToolExecutionError
Resource Errors
ResourceNotFoundError, ResourceReadError
Validation Errors
InvalidInputError, InvalidOutputError
Auth Errors
UnauthorizedError, AuthorizationRequiredError
Agent Errors
AgentNotFoundError, AgentExecutionError
Rate Limit Errors
RateLimitError, QuotaExceededError
Usage Patterns
Throwing Errors
Using fail()
Error with Details
Custom toJsonRpcError
Some errors overridetoJsonRpcError() for custom data:
Error Properties
| Property | Type | Description |
|---|---|---|
errorId | string | Unique ID for tracking (auto-generated) |
isPublic | boolean | Whether to expose message to clients |
statusCode | number | HTTP status code equivalent |
code | string | Error code for categorization |
mcpErrorCode | number | JSON-RPC error code (optional) |