ToolHandler

Trait ToolHandler 

Source
pub trait ToolHandler: Send + Sync {
    // Required methods
    fn list_tools(
        &self,
        ctx: &Context<'_>,
    ) -> impl Future<Output = Result<Vec<Tool>, McpError>> + Send;
    fn call_tool(
        &self,
        name: &str,
        args: Value,
        ctx: &Context<'_>,
    ) -> impl Future<Output = Result<ToolOutput, McpError>> + Send;

    // Provided method
    fn on_tools_changed(&self) -> impl Future<Output = ()> + Send { ... }
}
Expand description

Handler for tool-related operations.

Implement this trait to expose tools that AI assistants can call.

Required Methods§

Source

fn list_tools( &self, ctx: &Context<'_>, ) -> impl Future<Output = Result<Vec<Tool>, McpError>> + Send

List all available tools.

This is called when the client requests the tool list.

Source

fn call_tool( &self, name: &str, args: Value, ctx: &Context<'_>, ) -> impl Future<Output = Result<ToolOutput, McpError>> + Send

Call a tool with the given arguments.

§Arguments
  • name - The name of the tool to call
  • args - The arguments as a JSON value
  • ctx - The request context

Provided Methods§

Source

fn on_tools_changed(&self) -> impl Future<Output = ()> + Send

Called when a tool’s definition has changed.

Override this to dynamically add/remove/update tools.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T: ToolHandler> ToolHandler for Arc<T>

Source§

fn list_tools( &self, ctx: &Context<'_>, ) -> impl Future<Output = Result<Vec<Tool>, McpError>> + Send

Source§

fn call_tool( &self, name: &str, args: Value, ctx: &Context<'_>, ) -> impl Future<Output = Result<ToolOutput, McpError>> + Send

Source§

fn on_tools_changed(&self) -> impl Future<Output = ()> + Send

Implementors§