Skip to main content

Tool

Trait Tool 

Source
pub trait Tool: Send + Sync {
    // Required methods
    fn definition(&self) -> McpTool;
    fn execute<'life0, 'async_trait>(
        &'life0 self,
        arguments: Value,
    ) -> Pin<Box<dyn Future<Output = Result<CallToolResult, CallToolError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Tool trait

Defines the basic interface for MCP tools, including getting tool definition and executing the tool.

§Implementations

All tools need to implement this trait to be registered with ToolRegistry.

Required Methods§

Source

fn definition(&self) -> McpTool

Get tool definition

Returns the tool’s metadata, including name, description, parameters, etc.

Source

fn execute<'life0, 'async_trait>( &'life0 self, arguments: Value, ) -> Pin<Box<dyn Future<Output = Result<CallToolResult, CallToolError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute tool

§Arguments
  • arguments - Tool arguments (JSON format)
§Returns

Returns tool execution result or error

Implementors§