pub struct McpError {
pub kind: McpErrorKind,
pub code: i32,
pub message: String,
pub data: Option<Value>,
}Expand description
Error returned by every tsafe-mcp code path that can fail.
code and message are emitted directly as the JSON-RPC error.code /
error.message. data is the optional error.data object containing
per-error diagnostics (key name, field name, etc).
Fields§
§kind: McpErrorKind§code: i32§message: String§data: Option<Value>Implementations§
Source§impl McpError
impl McpError
Sourcepub fn new<S: Into<String>>(kind: McpErrorKind, detail: S) -> Self
pub fn new<S: Into<String>>(kind: McpErrorKind, detail: S) -> Self
Construct a fresh error using the kind’s default message with an additional human-readable detail appended.
Sourcepub fn kind_only(kind: McpErrorKind) -> Self
pub fn kind_only(kind: McpErrorKind) -> Self
Convenience for “use the default message verbatim” — most kinds in §5.4 have a fixed phrasing.
Sourcepub fn with_data(self, data: Value) -> Self
pub fn with_data(self, data: Value) -> Self
Attach structured data (key name, field path, etc) for the JSON-RPC
error object.
Sourcepub fn to_rpc_error_object(&self) -> Value
pub fn to_rpc_error_object(&self) -> Value
Build the JSON-RPC 2.0 error object for this error.
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