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

工具 trait

定义 MCP 工具的基本接口,包括获取工具定义和执行工具。

§实现

所有工具都需要实现此 trait 才能注册到 ToolRegistry

Required Methods§

Source

fn definition(&self) -> McpTool

获取工具定义

返回工具的元数据,包括名称、描述、参数等。

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,

执行工具

§参数
  • arguments - 工具参数(JSON 格式)
§返回值

返回工具执行结果或错误

Implementors§