pub enum McpError {
Show 13 variants
Connection {
code: i32,
message: String,
source: Option<Box<dyn Error + Send + Sync>>,
},
Transport {
code: i32,
message: String,
source: Option<Box<dyn Error + Send + Sync>>,
},
Protocol {
code: i32,
message: String,
},
Timeout {
code: i32,
message: String,
duration: Duration,
},
Cancelled {
code: i32,
message: String,
reason: Option<String>,
},
Server {
code: i32,
message: String,
data: Option<Value>,
},
Validation {
code: i32,
message: String,
errors: Vec<String>,
},
Config {
code: i32,
message: String,
source: Option<Box<dyn Error + Send + Sync>>,
},
Io {
code: i32,
message: String,
source: Error,
},
Serialization {
code: i32,
message: String,
source: Error,
},
Lifecycle {
code: i32,
message: String,
server_name: Option<String>,
},
Tool {
code: i32,
message: String,
tool_name: Option<String>,
},
PermissionDenied {
code: i32,
message: String,
tool_name: Option<String>,
},
}Expand description
MCP Error type with structured code and message.
All MCP operation failures return this error type, which contains:
- A numeric error code (following JSON-RPC 2.0 conventions)
- A human-readable error message
- Optional additional data
This satisfies Requirement 8.1: “WHEN an MCP operation fails THEN the System SHALL return a structured error with code and message”
Variants§
Connection
Connection-related errors (establishing, maintaining connections)
Fields
Transport
Transport layer errors (stdio, HTTP, WebSocket communication)
Fields
Protocol
Protocol errors (handshake, version negotiation, message format)
Timeout
Request timeout
Fields
Cancelled
Operation was cancelled
Fields
Server
Server returned an error
Fields
Validation
Validation errors (config, arguments, schema)
Fields
Config
Configuration errors (loading, saving, parsing)
Fields
Io
IO errors
Fields
Serialization
Serialization/deserialization errors
Lifecycle
Lifecycle management errors
Fields
Tool
Tool execution errors
Fields
PermissionDenied
Permission denied errors
Implementations§
Source§impl McpError
impl McpError
Sourcepub fn connection(message: impl Into<String>) -> Self
pub fn connection(message: impl Into<String>) -> Self
Create a connection error
Sourcepub fn connection_with_source(
message: impl Into<String>,
source: impl Error + Send + Sync + 'static,
) -> Self
pub fn connection_with_source( message: impl Into<String>, source: impl Error + Send + Sync + 'static, ) -> Self
Create a connection error with source
Sourcepub fn transport_with_source(
message: impl Into<String>,
source: impl Error + Send + Sync + 'static,
) -> Self
pub fn transport_with_source( message: impl Into<String>, source: impl Error + Send + Sync + 'static, ) -> Self
Create a transport error with source
Sourcepub fn cancelled(message: impl Into<String>, reason: Option<String>) -> Self
pub fn cancelled(message: impl Into<String>, reason: Option<String>) -> Self
Create a cancelled error
Sourcepub fn server(
code: i32,
message: impl Into<String>,
data: Option<Value>,
) -> Self
pub fn server( code: i32, message: impl Into<String>, data: Option<Value>, ) -> Self
Create a server error
Sourcepub fn validation(message: impl Into<String>, errors: Vec<String>) -> Self
pub fn validation(message: impl Into<String>, errors: Vec<String>) -> Self
Create a validation error
Sourcepub fn config_with_source(
message: impl Into<String>,
source: impl Error + Send + Sync + 'static,
) -> Self
pub fn config_with_source( message: impl Into<String>, source: impl Error + Send + Sync + 'static, ) -> Self
Create a config error with source
Sourcepub fn lifecycle(
message: impl Into<String>,
server_name: Option<String>,
) -> Self
pub fn lifecycle( message: impl Into<String>, server_name: Option<String>, ) -> Self
Create a lifecycle error
Sourcepub fn permission_denied(message: impl Into<String>) -> Self
pub fn permission_denied(message: impl Into<String>) -> Self
Create a permission denied error
Trait Implementations§
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 StructuredError
impl From<&McpError> for StructuredError
Auto Trait Implementations§
impl Freeze for McpError
impl !RefUnwindSafe for McpError
impl Send for McpError
impl Sync for McpError
impl Unpin for McpError
impl UnsafeUnpin 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<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.