Error

Struct Error 

Source
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: Uuid

Unique identifier for this error instance

§kind: ErrorKind

Error classification

§message: String

Human-readable error message

§context: ErrorContext

Additional contextual information

§source: Option<Box<Error>>

Optional source error that caused this error

§backtrace: Backtrace
Available on debug-assertions enabled only.

Stack trace information (when available)

Implementations§

Source§

impl Error

Source

pub fn new(kind: ErrorKind, message: impl Into<String>) -> Box<Self>

Create a new error with the specified kind and message

Source

pub fn validation(message: impl Into<String>) -> Box<Self>

Create a validation error

Source

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);
Source

pub fn authentication(message: impl Into<String>) -> Box<Self>

Create an authentication error

Source

pub 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()

Create a not found error

Source

pub fn permission_denied(message: impl Into<String>) -> Box<Self>

Create a permission denied error

Source

pub fn bad_request(message: impl Into<String>) -> Box<Self>

Create a bad request error

Source

pub fn internal(message: impl Into<String>) -> Box<Self>

Create an internal error

Source

pub fn transport(message: impl Into<String>) -> Box<Self>

Create a transport error

Source

pub fn serialization(message: impl Into<String>) -> Box<Self>

Create a serialization error

Source

pub fn protocol(message: impl Into<String>) -> Box<Self>

Create a protocol error

Source

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).

Source

pub fn timeout(message: impl Into<String>) -> Box<Self>

Create a timeout error

Source

pub fn unavailable(message: impl Into<String>) -> Box<Self>

Create an unavailable error

Source

pub fn rate_limited(message: impl Into<String>) -> Box<Self>

Create a rate limited error

Source

pub fn configuration(message: impl Into<String>) -> Box<Self>

Create a configuration error

Source

pub fn external_service(message: impl Into<String>) -> Box<Self>

Create an external service error

Source

pub fn cancelled(message: impl Into<String>) -> Box<Self>

Create a cancelled error

Source

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.

Source

pub fn handler(message: impl Into<String>) -> Box<Self>

👎Deprecated since 2.1.0: Use specific error constructors: tool_not_found(), tool_execution_failed(), etc.

Create a handler error - for compatibility with macro-generated code

Source

pub fn security(message: impl Into<String>) -> Box<Self>

Create a security error

Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

pub fn with_context( self: Box<Self>, key: impl Into<String>, value: impl Into<Value>, ) -> Box<Self>

Add context to this error

Source

pub fn with_operation( self: Box<Self>, operation: impl Into<String>, ) -> Box<Self>

Set the operation being performed

Source

pub fn with_component( self: Box<Self>, component: impl Into<String>, ) -> Box<Self>

Set the component where error occurred

Source

pub fn with_request_id( self: Box<Self>, request_id: impl Into<String>, ) -> Box<Self>

Set the request ID for tracing

Source

pub fn with_user_id(self: Box<Self>, user_id: impl Into<String>) -> Box<Self>

Set the user ID

Source

pub fn with_retry_info(self: Box<Self>, retry_info: RetryInfo) -> Box<Self>

Add retry information

Source

pub fn with_source(self: Box<Self>, source: Box<Self>) -> Box<Self>

Chain this error with a source error

Source

pub const fn is_retryable(&self) -> bool

Check if this error is retryable based on its kind

Source

pub const fn is_temporary(&self) -> bool

Check if this error indicates a temporary failure

Source

pub const fn http_status_code(&self) -> u16

Get the HTTP status code equivalent for this error

Source

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 Clone for Error

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Error

Source§

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

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

impl<'de> Deserialize<'de> for Error

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Error

Source§

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

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

impl Error for Error

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 Box<Error>

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Box<Error>

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<RegistryError> for Box<Error>

Source§

fn from(err: RegistryError) -> Self

Converts to this type from the input type.
Source§

impl From<SharedError> for Box<Error>

Source§

fn from(err: SharedError) -> Self

Converts to this type from the input type.
Source§

impl Serialize for Error

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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§

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,