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.
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>) -> 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'");