Skip to main content

ToolError

Struct ToolError 

Source
pub struct ToolError { /* private fields */ }
Expand description

An error raised by a tool, resource or prompt handler.

  • ToolError::user errors are shown to the client: as an isError tool result (so the model can correct itself), or as a -32602 error for resources and prompts. Use them for invalid input or business-rule violations.
  • Any other error (? on a std::error::Error) is logged with full detail on the server, and the client receives a generic message.

Implementations§

Source§

impl ToolError

Source

pub fn user(message: impl Into<Cow<'static, str>>) -> Self

An error whose message is shown to the model.

Source

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.

Source

pub fn invalid_argument(message: impl Into<String>) -> Self

Invalid input, with a client-safe explanation (shown to the client).

Source

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.

Source

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.

Source

pub fn internal( error: impl Into<Box<dyn Error + Send + Sync + 'static>>, ) -> Self

An internal error: logged on the server, hidden from the client.

Source

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.

Trait Implementations§

Source§

impl Debug for ToolError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ToolError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl IntoToolError for ToolError

Source§

fn into_tool_error(self) -> ToolError

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more