Skip to main content

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

ESM Errors

EsmPackageLoadError, EsmVersionResolutionError, EsmManifestInvalidError, EsmCacheError, EsmRegistryAuthError, EsmInvalidSpecifierError

Usage Patterns

Throwing Errors

Using fail()

Error with Details

Custom toJsonRpcError

Some errors override toJsonRpcError() for custom data:

Error Properties

Best Practices

Use Specific Error Classes

Preserve Original Errors

Don’t Expose Internal Details

Use Error IDs for Tracking

Import