pub struct ToolError { /* private fields */ }Expand description
An error raised by a tool, resource or prompt handler.
ToolError::usererrors are shown to the client: as anisErrortool result (so the model can correct itself), or as a-32602error for resources and prompts. Use them for invalid input or business-rule violations.- Any other error (
?on astd::error::Error) is logged with full detail on the server, and the client receives a generic message.
Implementations§
Source§impl ToolError
impl ToolError
Sourcepub fn user(message: impl Into<Cow<'static, str>>) -> Self
pub fn user(message: impl Into<Cow<'static, str>>) -> Self
An error whose message is shown to the model.
Sourcepub fn not_found() -> Self
pub fn not_found() -> Self
The requested item does not exist. From a resource handler, this is
the specification’s resource-not-found error (-32602 with
data.uri); from a tool, an isError result.
Sourcepub fn invalid_argument(message: impl Into<String>) -> Self
pub fn invalid_argument(message: impl Into<String>) -> Self
Invalid input, with a client-safe explanation (shown to the client).
Sourcepub fn protocol(error: McpError) -> Self
pub fn protocol(error: McpError) -> Self
A protocol-level (JSON-RPC) error instead of a tool result. Use it for conditions the specification defines as protocol errors, such as a missing client capability.
Sourcepub fn missing_client_capability(required: &ClientCapabilities) -> Self
pub fn missing_client_capability(required: &ClientCapabilities) -> Self
The request needs client capabilities the client did not declare:
a -32021 JSON-RPC error (HTTP 400) listing them, as the
specification requires. See Ctx::client_capabilities.
Sourcepub fn internal(
error: impl Into<Box<dyn Error + Send + Sync + 'static>>,
) -> Self
pub fn internal( error: impl Into<Box<dyn Error + Send + Sync + 'static>>, ) -> Self
An internal error: logged on the server, hidden from the client.
Sourcepub fn invalid_arguments(error: &Error) -> Self
pub fn invalid_arguments(error: &Error) -> Self
The arguments did not match the tool’s input schema. The message comes from the deserializer and only describes the client’s own input.