pub enum Error {
JsonRpc(JsonRpcError),
Serialization(Error),
Tool(ToolError),
Transport(String),
Internal(String),
}Expand description
tower-mcp error type
Variants§
JsonRpc(JsonRpcError)
Serialization(Error)
Tool(ToolError)
A tool execution error.
When returned from a tool handler, this variant is mapped to JSON-RPC
error code -32603 (Internal Error) in the router’s Service::call
implementation. The ToolError message becomes the JSON-RPC error message.
Transport(String)
Internal(String)
Implementations§
Source§impl Error
impl Error
Sourcepub fn tool(message: impl Into<String>) -> Self
pub fn tool(message: impl Into<String>) -> Self
Create a simple tool error from a string (for backwards compatibility)
Sourcepub fn tool_with_name(
tool: impl Into<String>,
message: impl Into<String>,
) -> Self
pub fn tool_with_name( tool: impl Into<String>, message: impl Into<String>, ) -> Self
Create a tool error with the tool name
Sourcepub fn tool_from<E: Display>(err: E) -> Self
pub fn tool_from<E: Display>(err: E) -> Self
Create a tool error from any Display type.
This is useful for converting errors in a map_err chain:
let result: Result<(), std::io::Error> = Err(std::io::Error::other("oops"));
result.map_err(Error::tool_from)?;Sourcepub fn tool_context<E: Display>(context: impl Into<String>, err: E) -> Self
pub fn tool_context<E: Display>(context: impl Into<String>, err: E) -> Self
Create a tool error with context prefix.
This is useful for adding context when converting errors:
let result: Result<(), std::io::Error> = Err(std::io::Error::other("connection refused"));
result.map_err(|e| Error::tool_context("API request failed", e))?;Sourcepub fn invalid_params(message: impl Into<String>) -> Self
pub fn invalid_params(message: impl Into<String>) -> Self
Create a JSON-RPC “Invalid params” error (-32602).
Shorthand for Error::JsonRpc(JsonRpcError::invalid_params(msg)).
let err = Error::invalid_params("missing required field 'name'");Trait Implementations§
Source§impl Error for Error
impl Error for Error
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()
Source§impl From<JsonRpcError> for Error
impl From<JsonRpcError> for Error
Source§fn from(err: JsonRpcError) -> Self
fn from(err: JsonRpcError) -> Self
Converts to this type from the input type.
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> 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