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 & Prompt Errors
ToolNotFoundError, ToolExecutionError, PromptNotFoundError, PromptExecutionError
Resource Errors
ResourceNotFoundError, ResourceReadError, InvalidResourceUriError
Validation Errors
InvalidInputError, InvalidOutputError, InvalidMethodError, MissingPromptArgumentError
Auth Errors
UnauthorizedError, AuthConfigurationError, SessionMissingError, AuthorizationRequiredError
Agent Errors
AgentNotFoundError, AgentExecutionError, AgentLoopExceededError, AgentTimeoutError
Rate Limit Errors
RateLimitError, QuotaExceededError
Transport Errors
TransportNotConnectedError, UnsupportedContentTypeError
Remote Errors
RemoteConnectionError, RemoteTimeoutError, RemoteToolNotFoundError
Elicitation Errors
ElicitationNotSupportedError, ElicitationTimeoutError, ElicitationFallbackRequired
Provider Errors
ProviderNotRegisteredError, DependencyCycleError, ProviderConstructionError
Registry Errors
RegistryDefinitionNotFoundError, FlowNotRegisteredError, EntryValidationError
Decorator Errors
InvalidDecoratorMetadataError, HookTargetNotDefinedError
Normalization Errors
MissingProvideError, InvalidUseClassError, InvalidEntityError
SDK Errors
FlowExitedWithoutOutputError, ServerNotFoundError, ConfigNotFoundError
Auth Internal Errors
EncryptionContextNotSetError, VaultLoadError, TokenLeakDetectedError
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) |