pub enum McpError {
Show 18 variants
Parse {
message: String,
source: Option<BoxError>,
},
InvalidRequest {
message: String,
source: Option<BoxError>,
},
MethodNotFound {
method: String,
available: Box<[String]>,
},
InvalidParams(Box<InvalidParamsDetails>),
Internal {
message: String,
source: Option<BoxError>,
},
Transport(Box<TransportDetails>),
ToolExecution(Box<ToolExecutionDetails>),
ResourceNotFound {
uri: String,
},
ResourceAccessDenied {
uri: String,
reason: Option<String>,
},
ConnectionFailed {
message: String,
source: Option<BoxError>,
},
SessionExpired {
session_id: String,
},
HandshakeFailed(Box<HandshakeDetails>),
CapabilityNotSupported {
capability: String,
available: Box<[String]>,
},
UserRejected {
message: String,
operation: String,
},
Timeout {
operation: String,
duration: Duration,
},
Cancelled {
operation: String,
reason: Option<String>,
},
WithContext {
context: String,
source: Box<McpError>,
},
InternalMessage {
message: String,
},
}Expand description
The primary error type for the MCP SDK.
This unified error type replaces nested error hierarchies with a single, context-rich type that preserves error chains and provides excellent diagnostic output.
Large error variants are boxed to keep Result<T, McpError> small
(approximately 24 bytes on 64-bit systems).
Variants§
Parse
Invalid JSON was received by the server.
Fields
InvalidRequest
The JSON sent is not a valid Request object.
Fields
MethodNotFound
The method does not exist or is not available.
Fields
InvalidParams(Box<InvalidParamsDetails>)
Invalid method parameter(s) (details boxed to reduce enum size).
Internal
Internal JSON-RPC error.
Fields
Transport(Box<TransportDetails>)
Transport-level error (details boxed to reduce enum size).
ToolExecution(Box<ToolExecutionDetails>)
A tool execution failed (details boxed to reduce enum size).
ResourceNotFound
A requested resource was not found.
ResourceAccessDenied
Access to a resource was denied.
Fields
ConnectionFailed
Connection establishment failed.
Fields
SessionExpired
Session has expired.
HandshakeFailed(Box<HandshakeDetails>)
Protocol handshake failed (details boxed to reduce enum size).
CapabilityNotSupported
A requested capability is not supported.
Fields
UserRejected
User rejected an operation.
Fields
Timeout
An operation timed out.
Fields
Cancelled
An operation was cancelled.
Fields
WithContext
An error with additional context.
InternalMessage
A simple internal error with just a message.
Implementations§
Source§impl McpError
impl McpError
Sourcepub fn parse_with_source<E: Error + Send + Sync + 'static>(
message: impl Into<String>,
source: E,
) -> Self
pub fn parse_with_source<E: Error + Send + Sync + 'static>( message: impl Into<String>, source: E, ) -> Self
Create a parse error with a source.
Sourcepub fn invalid_request(message: impl Into<String>) -> Self
pub fn invalid_request(message: impl Into<String>) -> Self
Create an invalid request error.
Sourcepub fn method_not_found(method: impl Into<String>) -> Self
pub fn method_not_found(method: impl Into<String>) -> Self
Create a method not found error.
Sourcepub fn method_not_found_with_suggestions(
method: impl Into<String>,
available: Vec<String>,
) -> Self
pub fn method_not_found_with_suggestions( method: impl Into<String>, available: Vec<String>, ) -> Self
Create a method not found error with suggestions.
Sourcepub fn invalid_params(
method: impl Into<String>,
message: impl Into<String>,
) -> Self
pub fn invalid_params( method: impl Into<String>, message: impl Into<String>, ) -> Self
Create an invalid params error.
Sourcepub fn invalid_params_detailed(
method: impl Into<String>,
message: impl Into<String>,
param_path: Option<String>,
expected: Option<String>,
actual: Option<String>,
) -> Self
pub fn invalid_params_detailed( method: impl Into<String>, message: impl Into<String>, param_path: Option<String>, expected: Option<String>, actual: Option<String>, ) -> Self
Create an invalid params error with full details.
Sourcepub fn internal_with_source<E: Error + Send + Sync + 'static>(
message: impl Into<String>,
source: E,
) -> Self
pub fn internal_with_source<E: Error + Send + Sync + 'static>( message: impl Into<String>, source: E, ) -> Self
Create an internal error with a source.
Sourcepub fn transport(kind: TransportErrorKind, message: impl Into<String>) -> Self
pub fn transport(kind: TransportErrorKind, message: impl Into<String>) -> Self
Create a transport error.
Sourcepub fn transport_with_context(
kind: TransportErrorKind,
message: impl Into<String>,
context: TransportContext,
) -> Self
pub fn transport_with_context( kind: TransportErrorKind, message: impl Into<String>, context: TransportContext, ) -> Self
Create a transport error with context.
Sourcepub fn tool_error(tool: impl Into<String>, message: impl Into<String>) -> Self
pub fn tool_error(tool: impl Into<String>, message: impl Into<String>) -> Self
Create a tool execution error.
Sourcepub fn tool_error_detailed(
tool: impl Into<String>,
message: impl Into<String>,
is_recoverable: bool,
data: Option<Value>,
) -> Self
pub fn tool_error_detailed( tool: impl Into<String>, message: impl Into<String>, is_recoverable: bool, data: Option<Value>, ) -> Self
Create a tool execution error with full details.
Sourcepub fn resource_not_found(uri: impl Into<String>) -> Self
pub fn resource_not_found(uri: impl Into<String>) -> Self
Create a resource not found error.
Sourcepub fn handshake_failed(message: impl Into<String>) -> Self
pub fn handshake_failed(message: impl Into<String>) -> Self
Create a handshake failed error.
Sourcepub fn handshake_failed_with_versions(
message: impl Into<String>,
client_version: Option<String>,
server_version: Option<String>,
) -> Self
pub fn handshake_failed_with_versions( message: impl Into<String>, client_version: Option<String>, server_version: Option<String>, ) -> Self
Create a handshake failed error with version info.
Sourcepub fn capability_not_supported(capability: impl Into<String>) -> Self
pub fn capability_not_supported(capability: impl Into<String>) -> Self
Create a capability not supported error.
Sourcepub fn capability_not_supported_with_available(
capability: impl Into<String>,
available: Vec<String>,
) -> Self
pub fn capability_not_supported_with_available( capability: impl Into<String>, available: Vec<String>, ) -> Self
Create a capability not supported error with available list.
Trait Implementations§
Source§impl Diagnostic for McpError
impl Diagnostic for McpError
Source§fn code(&self) -> Option<Box<dyn Display + '_>>
fn code(&self) -> Option<Box<dyn Display + '_>>
Diagnostic. Ideally also globally unique, and documented
in the toplevel crate’s documentation for easy searching. Rust path
format (foo::bar::baz) is recommended, but more classic codes like
E0123 or enums will work just fine.Source§fn help(&self) -> Option<Box<dyn Display + '_>>
fn help(&self) -> Option<Box<dyn Display + '_>>
Diagnostic. Do you have any
advice for the poor soul who’s just run into this issue?Source§fn severity(&self) -> Option<Severity>
fn severity(&self) -> Option<Severity>
ReportHandlers to change the display format
of this diagnostic. Read moreSource§fn url<'a>(&'a self) -> Option<Box<dyn Display + 'a>>
fn url<'a>(&'a self) -> Option<Box<dyn Display + 'a>>
Diagnostic.Source§fn source_code(&self) -> Option<&dyn SourceCode>
fn source_code(&self) -> Option<&dyn SourceCode>
Diagnostic’s Diagnostic::labels to.Source§fn labels(&self) -> Option<Box<dyn Iterator<Item = LabeledSpan> + '_>>
fn labels(&self) -> Option<Box<dyn Iterator<Item = LabeledSpan> + '_>>
Diagnostic’s Diagnostic::source_codeDiagnostics.Source§fn diagnostic_source(&self) -> Option<&dyn Diagnostic>
fn diagnostic_source(&self) -> Option<&dyn Diagnostic>
Source§impl Error for McpError
impl Error for McpError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl From<&McpError> for JsonRpcError
impl From<&McpError> for JsonRpcError
Auto Trait Implementations§
impl Freeze for McpError
impl !RefUnwindSafe for McpError
impl Send for McpError
impl Sync for McpError
impl Unpin for McpError
impl !UnwindSafe for McpError
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
Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more