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
Json
Transport(String)
TransportConnectionFailed
TransportDisconnected
Protocol(String)
InvalidRequest(String)
MethodNotFound(String)
InvalidParams
InternalError(String)
ConnectionClosed
Timeout
RequestNotFound(String)
HandlerError
ResourceNotFound
ToolExecutionFailed
MessageTooLarge
InvalidMessageFormat
CodecError
Implementations§
Source§impl MCPError
impl MCPError
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 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 }Sourcepub fn timeout(duration: Duration, request_id: impl Into<String>) -> Self
pub fn timeout(duration: Duration, request_id: impl Into<String>) -> Self
Create a Timeout error with duration and request context
Sourcepub fn handler_error(
handler_type: impl Into<String>,
message: impl Into<String>,
) -> Self
pub fn handler_error( handler_type: impl Into<String>, message: impl Into<String>, ) -> Self
Create a HandlerError with type context
Sourcepub fn tool_execution_failed(
tool: impl Into<String>,
message: impl Into<String>,
) -> Self
pub fn tool_execution_failed( tool: impl Into<String>, message: impl Into<String>, ) -> Self
Create a ToolExecutionFailed error
Sourcepub fn is_retryable(&self) -> bool
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 Error for MCPError
impl Error for MCPError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
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
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
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
Mutably borrows from an owned value. Read more