pub enum Error {
Protocol {
code: ErrorCode,
message: String,
data: Option<Value>,
},
Transport(TransportError),
Serialization(Error),
Validation(String),
Authentication(String),
Timeout(u64),
UnsupportedCapability(String),
Internal(String),
NotFound(String),
InvalidState(String),
Cancelled,
Other(Error),
}Expand description
Main error type for MCP operations.
Variants§
Protocol
JSON-RPC protocol errors
Fields
Transport(TransportError)
Transport-level errors
Serialization(Error)
Serialization/deserialization errors
Validation(String)
Validation errors
Authentication(String)
Authentication errors
Timeout(u64)
Timeout errors
UnsupportedCapability(String)
Capability errors
Internal(String)
Internal errors
NotFound(String)
Resource not found
InvalidState(String)
Invalid state
Cancelled
Cancelled operation
Other(Error)
Other errors
Implementations§
Source§impl Error
impl Error
Sourcepub fn protocol(code: ErrorCode, message: impl Into<String>) -> Self
pub fn protocol(code: ErrorCode, message: impl Into<String>) -> Self
Create a protocol error with the given code and message.
Sourcepub fn protocol_msg(message: impl Into<String>) -> Self
pub fn protocol_msg(message: impl Into<String>) -> Self
Create a protocol error with just a message (defaults to InternalError code).
Sourcepub fn protocol_with_data(
code: ErrorCode,
message: impl Into<String>,
data: Value,
) -> Self
pub fn protocol_with_data( code: ErrorCode, message: impl Into<String>, data: Value, ) -> Self
Create a protocol error with additional data.
Sourcepub fn validation(message: impl Into<String>) -> Self
pub fn validation(message: impl Into<String>) -> Self
Create a validation error.
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 invalid_params(message: impl Into<String>) -> Self
pub fn invalid_params(message: impl Into<String>) -> Self
Create an invalid params error.
Sourcepub fn authentication(message: impl Into<String>) -> Self
pub fn authentication(message: impl Into<String>) -> Self
Create an authentication error.
Sourcepub fn capability(message: impl Into<String>) -> Self
pub fn capability(message: impl Into<String>) -> Self
Create a capability error.
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 from_jsonrpc_error(error: JSONRPCError) -> Self
pub fn from_jsonrpc_error(error: JSONRPCError) -> Self
Create from JSON-RPC error.
Sourcepub fn is_error_code(&self, code: ErrorCode) -> bool
pub fn is_error_code(&self, code: ErrorCode) -> bool
Check if this is a protocol error with a specific code.
Sourcepub fn error_code(&self) -> Option<ErrorCode>
pub fn error_code(&self) -> Option<ErrorCode>
Get the error code if this is a protocol error.