pub struct McpError {
pub code: ErrorCode,
pub message: String,
pub suggestion: Option<String>,
}Expand description
An error type designed for MCP tool responses.
Serializes to JSON with code, message, and an optional suggestion.
The suggestion is aimed at the LLM caller — it tells the model how to retry
or what parameter to fix, reducing round-trips.
Fields§
§code: ErrorCode§message: String§suggestion: Option<String>Implementations§
Source§impl McpError
impl McpError
Sourcepub fn new(code: ErrorCode, message: impl Into<String>) -> Self
pub fn new(code: ErrorCode, message: impl Into<String>) -> Self
Create an error with an auto-generated suggestion based on the error code.
Sourcepub fn with_suggestion(self, suggestion: impl Into<String>) -> Self
pub fn with_suggestion(self, suggestion: impl Into<String>) -> Self
Override the default suggestion with a context-specific one.
Sourcepub fn from_io_error(err: &Error, context: &str) -> Self
pub fn from_io_error(err: &Error, context: &str) -> Self
Maps a filesystem std::io::Error to an McpError, preserving the
distinction between a missing file and a permission problem instead of
collapsing both to ErrorCode::FileNotFound.
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§
impl<T> Allocation for T
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request