Skip to main content

Tool

Trait Tool 

Source
pub trait Tool: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn description(&self) -> &str;
    fn parameters_schema(&self) -> Value;
    fn execute<'life0, 'life1, 'async_trait>(
        &'life0 self,
        params: Value,
        ctx: &'life1 dyn ToolContext,
    ) -> Pin<Box<dyn Future<Output = Result<Value, PluginError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

A tool that can be invoked by an agent or exposed via MCP.

Tools are the primary extension point for adding new capabilities. Each tool declares its name, description, and a JSON Schema for its parameters. The host routes execute() calls based on the tool name.

Required Methods§

Source

fn name(&self) -> &str

Unique tool name (e.g., "web_search", "file_read").

Source

fn description(&self) -> &str

Human-readable description of what the tool does.

Source

fn parameters_schema(&self) -> Value

JSON Schema describing the tool’s parameters.

Returns a serde_json::Value representing a JSON Schema object. The host uses this schema for validation and for MCP tools/list.

Source

fn execute<'life0, 'life1, 'async_trait>( &'life0 self, params: Value, ctx: &'life1 dyn ToolContext, ) -> Pin<Box<dyn Future<Output = Result<Value, PluginError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Execute the tool with the given parameters and context.

params is a JSON object matching parameters_schema(). Returns a JSON value with the tool’s result, or a PluginError.

Implementors§