pub struct Error {
pub id: Uuid,
pub kind: ErrorKind,
pub message: String,
pub context: ErrorContext,
pub source: Option<Box<Error>>,
pub backtrace: Backtrace,
}Expand description
Comprehensive error type with rich context information
Fields§
§id: UuidUnique identifier for this error instance
kind: ErrorKindError classification
message: StringHuman-readable error message
context: ErrorContextAdditional contextual information
source: Option<Box<Error>>Optional source error that caused this error
backtrace: BacktraceStack trace information (when available)
Implementations§
Source§impl Error
impl Error
Sourcepub fn new(kind: ErrorKind, message: impl Into<String>) -> Box<Self>
pub fn new(kind: ErrorKind, message: impl Into<String>) -> Box<Self>
Create a new error with the specified kind and message
Sourcepub fn validation(message: impl Into<String>) -> Box<Self>
pub fn validation(message: impl Into<String>) -> Box<Self>
Create a validation error
Sourcepub fn invalid_params(message: impl Into<String>) -> Box<Self>
pub fn invalid_params(message: impl Into<String>) -> Box<Self>
Create an invalid parameters error (MCP -32602)
This is the standard MCP error code for parameter validation failures, including missing required parameters, invalid types, out-of-range values, or any other parameter-related validation errors.
§Example
use turbomcp_protocol::Error;
let error = Error::invalid_params("Email must be valid");
assert_eq!(error.jsonrpc_error_code(), -32602);Sourcepub fn authentication(message: impl Into<String>) -> Box<Self>
pub fn authentication(message: impl Into<String>) -> Box<Self>
Create an authentication error
Sourcepub fn not_found(message: impl Into<String>) -> Box<Self>
👎Deprecated since 2.1.0: Use specific constructors: tool_not_found(), prompt_not_found(), or resource_not_found()
pub fn not_found(message: impl Into<String>) -> Box<Self>
Create a not found error
Sourcepub fn permission_denied(message: impl Into<String>) -> Box<Self>
pub fn permission_denied(message: impl Into<String>) -> Box<Self>
Create a permission denied error
Sourcepub fn bad_request(message: impl Into<String>) -> Box<Self>
pub fn bad_request(message: impl Into<String>) -> Box<Self>
Create a bad request error
Sourcepub fn serialization(message: impl Into<String>) -> Box<Self>
pub fn serialization(message: impl Into<String>) -> Box<Self>
Create a serialization error
Sourcepub fn rpc(code: i32, message: &str) -> Box<Self>
pub fn rpc(code: i32, message: &str) -> Box<Self>
Create a JSON-RPC error
Maps JSON-RPC error codes to appropriate ErrorKind variants to preserve semantic meaning. Special handling for MCP-specific codes like -1 (user rejection).
Create an unavailable error
Sourcepub fn rate_limited(message: impl Into<String>) -> Box<Self>
pub fn rate_limited(message: impl Into<String>) -> Box<Self>
Create a rate limited error
Sourcepub fn configuration(message: impl Into<String>) -> Box<Self>
pub fn configuration(message: impl Into<String>) -> Box<Self>
Create a configuration error
Sourcepub fn external_service(message: impl Into<String>) -> Box<Self>
pub fn external_service(message: impl Into<String>) -> Box<Self>
Create an external service error
Sourcepub fn user_rejected(message: impl Into<String>) -> Box<Self>
pub fn user_rejected(message: impl Into<String>) -> Box<Self>
Create a user rejected error
Per MCP 2025-06-18 specification, this indicates a user explicitly rejected a request (e.g., declined a sampling request). This is a permanent failure that should not be retried.
Sourcepub fn handler(message: impl Into<String>) -> Box<Self>
👎Deprecated since 2.1.0: Use specific error constructors: tool_not_found(), tool_execution_failed(), etc.
pub fn handler(message: impl Into<String>) -> Box<Self>
Create a handler error - for compatibility with macro-generated code
Sourcepub fn tool_not_found(tool_name: impl Into<String>) -> Box<Self>
pub fn tool_not_found(tool_name: impl Into<String>) -> Box<Self>
Create a tool not found error (MCP error code -32001)
§Example
use turbomcp_protocol::Error;
let error = Error::tool_not_found("calculate");
assert_eq!(error.jsonrpc_error_code(), -32001);Sourcepub fn tool_execution_failed(
tool_name: impl Into<String>,
reason: impl Into<String>,
) -> Box<Self>
pub fn tool_execution_failed( tool_name: impl Into<String>, reason: impl Into<String>, ) -> Box<Self>
Create a tool execution failed error (MCP error code -32002)
§Example
use turbomcp_protocol::Error;
let error = Error::tool_execution_failed("calculate", "Division by zero");
assert_eq!(error.jsonrpc_error_code(), -32002);Sourcepub fn prompt_not_found(prompt_name: impl Into<String>) -> Box<Self>
pub fn prompt_not_found(prompt_name: impl Into<String>) -> Box<Self>
Create a prompt not found error (MCP error code -32003)
§Example
use turbomcp_protocol::Error;
let error = Error::prompt_not_found("code_review");
assert_eq!(error.jsonrpc_error_code(), -32003);Sourcepub fn resource_not_found(uri: impl Into<String>) -> Box<Self>
pub fn resource_not_found(uri: impl Into<String>) -> Box<Self>
Create a resource not found error (MCP error code -32004)
§Example
use turbomcp_protocol::Error;
let error = Error::resource_not_found("file:///docs/api.md");
assert_eq!(error.jsonrpc_error_code(), -32004);Sourcepub fn resource_access_denied(
uri: impl Into<String>,
reason: impl Into<String>,
) -> Box<Self>
pub fn resource_access_denied( uri: impl Into<String>, reason: impl Into<String>, ) -> Box<Self>
Create a resource access denied error (MCP error code -32005)
§Example
use turbomcp_protocol::Error;
let error = Error::resource_access_denied("file:///etc/passwd", "Path outside allowed directory");
assert_eq!(error.jsonrpc_error_code(), -32005);Sourcepub fn capability_not_supported(capability: impl Into<String>) -> Box<Self>
pub fn capability_not_supported(capability: impl Into<String>) -> Box<Self>
Create a capability not supported error (MCP error code -32006)
§Example
use turbomcp_protocol::Error;
let error = Error::capability_not_supported("sampling");
assert_eq!(error.jsonrpc_error_code(), -32006);Sourcepub fn protocol_version_mismatch(
client_version: impl Into<String>,
server_version: impl Into<String>,
) -> Box<Self>
pub fn protocol_version_mismatch( client_version: impl Into<String>, server_version: impl Into<String>, ) -> Box<Self>
Create a protocol version mismatch error (MCP error code -32007)
§Example
use turbomcp_protocol::Error;
let error = Error::protocol_version_mismatch("2024-11-05", "2025-06-18");
assert_eq!(error.jsonrpc_error_code(), -32007);Sourcepub fn server_overloaded() -> Box<Self>
pub fn server_overloaded() -> Box<Self>
Create a server overloaded error (MCP error code -32010)
§Example
use turbomcp_protocol::Error;
let error = Error::server_overloaded();
assert_eq!(error.jsonrpc_error_code(), -32010);Sourcepub fn with_context(
self: Box<Self>,
key: impl Into<String>,
value: impl Into<Value>,
) -> Box<Self>
pub fn with_context( self: Box<Self>, key: impl Into<String>, value: impl Into<Value>, ) -> Box<Self>
Add context to this error
Sourcepub fn with_operation(
self: Box<Self>,
operation: impl Into<String>,
) -> Box<Self>
pub fn with_operation( self: Box<Self>, operation: impl Into<String>, ) -> Box<Self>
Set the operation being performed
Sourcepub fn with_component(
self: Box<Self>,
component: impl Into<String>,
) -> Box<Self>
pub fn with_component( self: Box<Self>, component: impl Into<String>, ) -> Box<Self>
Set the component where error occurred
Sourcepub fn with_request_id(
self: Box<Self>,
request_id: impl Into<String>,
) -> Box<Self>
pub fn with_request_id( self: Box<Self>, request_id: impl Into<String>, ) -> Box<Self>
Set the request ID for tracing
Sourcepub fn with_retry_info(self: Box<Self>, retry_info: RetryInfo) -> Box<Self>
pub fn with_retry_info(self: Box<Self>, retry_info: RetryInfo) -> Box<Self>
Add retry information
Sourcepub fn with_source(self: Box<Self>, source: Box<Self>) -> Box<Self>
pub fn with_source(self: Box<Self>, source: Box<Self>) -> Box<Self>
Chain this error with a source error
Sourcepub const fn is_retryable(&self) -> bool
pub const fn is_retryable(&self) -> bool
Check if this error is retryable based on its kind
Sourcepub const fn is_temporary(&self) -> bool
pub const fn is_temporary(&self) -> bool
Check if this error indicates a temporary failure
Sourcepub const fn http_status_code(&self) -> u16
pub const fn http_status_code(&self) -> u16
Get the HTTP status code equivalent for this error
Sourcepub const fn jsonrpc_error_code(&self) -> i32
pub const fn jsonrpc_error_code(&self) -> i32
Convert to a JSON-RPC error code per MCP 2025-06-18 specification
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Error
impl<'de> Deserialize<'de> for Error
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl From<RegistryError> for Box<Error>
impl From<RegistryError> for Box<Error>
Source§fn from(err: RegistryError) -> Self
fn from(err: RegistryError) -> Self
Source§fn from(err: SharedError) -> Self
fn from(err: SharedError) -> Self
Auto Trait Implementations§
impl !Freeze for Error
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnwindSafe for Error
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)