#[non_exhaustive]#[repr(i32)]pub enum McpErrorCode {
ConnectionClosed = -32_000,
HeaderMismatch = -32_020,
ResourceNotFound = -32_002,
MissingRequiredClientCapability = -32_021,
UnsupportedProtocolVersion = -32_022,
SessionNotFound = -32_005,
SessionRequired = -32_006,
Forbidden = -32_007,
AlreadySubscribed = -32_008,
NotSubscribed = -32_009,
RequestTimeout = -32_010,
UrlElicitationRequired = -32_042,
}Expand description
MCP-specific error codes (in the -32000 to -32099 range).
Codes marked spec are assigned by an MCP SEP. Others are implementation-defined within the JSON-RPC server-error range; using them is permitted by JSON-RPC 2.0 but they are not part of the MCP wire spec.
Recently-changed assignments:
HeaderMismatch(SEP-2243),MissingRequiredClientCapability, andUnsupportedProtocolVersion(both SEP-2575) were originally assigned -32001/-32003/-32004 by their SEP documents. The upstream error-code allocation policy (spec PR modelcontextprotocol#2907, 2026-06) renumbered them to -32020/-32021/-32022 in the draft schema, which is canonical. This is a breaking change on the wire within the experimental 2026-07-28 surface.AlreadySubscribedandNotSubscribedpreviously occupied -32003 and -32004; they moved to -32008 and -32009 when those slots were believed to be spec-assigned. They stay at -32008/-32009.RequestTimeoutpreviously occupied -32001 and moved to -32010 for the same reason. It stays at -32010.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
ConnectionClosed = -32_000
Transport connection was closed.
HeaderMismatch = -32_020
SEP-2243: HTTP headers (e.g. Mcp-Method, Mcp-Name,
Mcp-Param-*) do not match the corresponding values in the request
body, or a required header is missing or malformed.
Originally -32001 in the SEP text; renumbered to -32020 by the upstream error-code allocation (spec PR modelcontextprotocol#2907).
Use JsonRpcError::header_mismatch to construct.
ResourceNotFound = -32_002
SEP-2164 reassigned resource-not-found to InvalidParams (-32602). Use JsonRpcError::resource_not_found or ErrorCode::InvalidParams.
Resource not found.
Deprecated: SEP-2164 (FINAL) moves this to the standard JSON-RPC
InvalidParams code (-32602). The
JsonRpcError::resource_not_found constructor now emits -32602.
The enum variant is retained so existing pattern matches on
McpErrorCode::ResourceNotFound keep compiling, but the variant’s
numeric value is no longer what the constructor produces.
MissingRequiredClientCapability = -32_021
SEP-2575: client capabilities advertised on the request do not include a capability required by the called method.
Originally -32003 in the SEP text; renumbered to -32021 by the upstream error-code allocation (spec PR modelcontextprotocol#2907).
UnsupportedProtocolVersion = -32_022
SEP-2575: server does not support the protocol version the client
requested (via MCP-Protocol-Version header or per-request _meta).
Originally -32004 in the SEP text; renumbered to -32022 by the upstream error-code allocation (spec PR modelcontextprotocol#2907).
Use JsonRpcError::unsupported_protocol_version to construct.
SessionNotFound = -32_005
Session not found or expired – client should re-initialize.
SEP-2567 deprecates sessions entirely. This code stays for the 2025-11-25 protocol path; sessionless deployments will never emit it.
SessionRequired = -32_006
Session ID is required but was not provided.
SEP-2567 deprecates sessions entirely. Same caveat as SessionNotFound.
Forbidden = -32_007
Access forbidden (insufficient scope or authorization).
AlreadySubscribed = -32_008
Resource already subscribed. Moved from -32003 when that slot was believed to be spec-assigned; stays at -32008.
NotSubscribed = -32_009
Resource not subscribed (for unsubscribe). Moved from -32004 when that slot was believed to be spec-assigned; stays at -32009.
RequestTimeout = -32_010
Request exceeded timeout. Moved from -32001 when that slot was believed to be spec-assigned; stays at -32010.
UrlElicitationRequired = -32_042
URL elicitation is required before processing the request.
Implementations§
Trait Implementations§
Source§impl Clone for McpErrorCode
impl Clone for McpErrorCode
Source§fn clone(&self) -> McpErrorCode
fn clone(&self) -> McpErrorCode
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for McpErrorCode
Source§impl Debug for McpErrorCode
impl Debug for McpErrorCode
impl Eq for McpErrorCode
Source§impl PartialEq for McpErrorCode
impl PartialEq for McpErrorCode
impl StructuralPartialEq for McpErrorCode
Auto Trait Implementations§
impl Freeze for McpErrorCode
impl RefUnwindSafe for McpErrorCode
impl Send for McpErrorCode
impl Sync for McpErrorCode
impl Unpin for McpErrorCode
impl UnsafeUnpin for McpErrorCode
impl UnwindSafe for McpErrorCode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.