Skip to main content

MCPError

Enum MCPError 

Source
pub enum MCPError {
Show 19 variants Io { message: String, }, Json { message: String, }, Transport(String), TransportConnectionFailed { message: String, }, TransportDisconnected, Protocol(String), InvalidRequest(String), MethodNotFound(String), InvalidParams { method: String, message: String, }, InternalError(String), ConnectionClosed, Timeout { duration: Duration, request_id: String, }, RequestNotFound(String), HandlerError { handler_type: String, message: String, }, ResourceNotFound { uri: String, }, ToolExecutionFailed { tool: String, message: String, }, MessageTooLarge { size: usize, max_size: usize, }, InvalidMessageFormat { message: String, }, CodecError { message: String, },
}

Variants§

§

Io

Fields

§message: String
§

Json

Fields

§message: String
§

Transport(String)

§

TransportConnectionFailed

Fields

§message: String
§

TransportDisconnected

§

Protocol(String)

§

InvalidRequest(String)

§

MethodNotFound(String)

§

InvalidParams

Fields

§method: String
§message: String
§

InternalError(String)

§

ConnectionClosed

§

Timeout

Fields

§duration: Duration
§request_id: String
§

RequestNotFound(String)

§

HandlerError

Fields

§handler_type: String
§message: String
§

ResourceNotFound

Fields

§

ToolExecutionFailed

Fields

§tool: String
§message: String
§

MessageTooLarge

Fields

§size: usize
§max_size: usize
§

InvalidMessageFormat

Fields

§message: String
§

CodecError

Fields

§message: String

Implementations§

Source§

impl MCPError

Source

pub fn invalid_params( method: impl Into<String>, message: impl Into<String>, ) -> Self

Create an InvalidParams error with method context

Examples found in repository?
examples/error_handling.rs (line 72)
70    async fn execute(&self, arguments: Option<serde_json::Value>) -> Result<Vec<Content>> {
71        let args = arguments
72            .ok_or_else(|| MCPError::invalid_params("strict_tool", "Missing arguments object"))?;
73
74        let required_field = args
75            .get("required_field")
76            .and_then(|v| v.as_str())
77            .ok_or_else(|| {
78                MCPError::invalid_params(
79                    "strict_tool",
80                    "Missing or invalid 'required_field' parameter",
81                )
82            })?;
83
84        Ok(vec![Content::Text(TextContent {
85            text: format!("Received: {required_field}"),
86            annotations: None,
87        })])
88    }
Source

pub fn timeout(duration: Duration, request_id: impl Into<String>) -> Self

Create a Timeout error with duration and request context

Source

pub fn handler_error( handler_type: impl Into<String>, message: impl Into<String>, ) -> Self

Create a HandlerError with type context

Source

pub fn tool_execution_failed( tool: impl Into<String>, message: impl Into<String>, ) -> Self

Create a ToolExecutionFailed error

Examples found in repository?
examples/error_handling.rs (lines 35-38)
34    async fn execute(&self, _arguments: Option<serde_json::Value>) -> Result<Vec<Content>> {
35        Err(MCPError::tool_execution_failed(
36            "always_fail",
37            "This tool always fails for testing purposes",
38        ))
39    }
Source

pub fn is_retryable(&self) -> bool

Check if this error is retryable

Examples found in repository?
examples/timeout_client.rs (line 88)
76async fn test_broken_operation(client: &mut MCPClient) -> Result<()> {
77    info!("\n=== Testing Broken Operation ===");
78    info!("This operation always fails with a non-retryable error.");
79    info!("Should fail immediately without retries...");
80
81    match client.call_tool("broken_operation".to_string(), None).await {
82        Ok(_) => {
83            error!("✗ Unexpected success");
84        }
85        Err(e) => {
86            info!("✓ Expected non-retryable error: {}", e);
87            // Verify it's actually non-retryable
88            if e.is_retryable() {
89                error!("Error was retryable when it shouldn't be: {:?}", e);
90            }
91        }
92    }
93
94    Ok(())
95}

Trait Implementations§

Source§

impl Clone for MCPError

Source§

fn clone(&self) -> MCPError

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MCPError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for MCPError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for MCPError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for MCPError

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for MCPError

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more