#[non_exhaustive]pub enum Error {
JsonRpc(JsonRpcError),
Serialization(Error),
Tool(ToolError),
Transport(String),
SessionExpired,
Internal(String),
}Expand description
tower-mcp error type
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
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)
SessionExpired
The server indicated the session has expired or is not found.
This corresponds to JSON-RPC error code -32005 (SessionNotFound)
or an HTTP 404 response when a session ID was attached.
Clients should re-initialize the connection.
Internal(String)
Implementations§
Source§impl Error
impl Error
Sourcepub fn tool(message: impl Into<String>) -> Error
pub fn tool(message: impl Into<String>) -> Error
Create a simple tool error from a string (for backwards compatibility)
Sourcepub fn tool_with_name(
tool: impl Into<String>,
message: impl Into<String>,
) -> Error
pub fn tool_with_name( tool: impl Into<String>, message: impl Into<String>, ) -> Error
Create a tool error with the tool name
Sourcepub fn tool_from<E>(err: E) -> Errorwhere
E: Display,
pub fn tool_from<E>(err: E) -> Errorwhere
E: Display,
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>(context: impl Into<String>, err: E) -> Errorwhere
E: Display,
pub fn tool_context<E>(context: impl Into<String>, err: E) -> Errorwhere
E: Display,
Create a tool error with context prefix.
This is useful for adding context when converting errors.
For a more ergonomic API, see ResultExt::tool_context which can be
called directly on Result values:
let result: Result<(), std::io::Error> = Err(std::io::Error::other("connection refused"));
result.tool_context("API request failed")?;Sourcepub fn invalid_params(message: impl Into<String>) -> Error
pub fn invalid_params(message: impl Into<String>) -> Error
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)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()