Skip to main content

ToolHandler

Trait ToolHandler 

Source
pub trait ToolHandler: Send + Sync {
    // Required methods
    fn kind(&self) -> ToolKind;
    fn handle<'life0, 'async_trait>(
        &'life0 self,
        invocation: ToolInvocation,
    ) -> Pin<Box<dyn Future<Output = Result<ToolOutput, FunctionCallError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn matches_kind(&self, kind: ToolKind) -> bool { ... }
    fn is_mutating(&self) -> bool { ... }
}
Expand description

Trait implemented by concrete tool handlers.

Each registered tool is backed by a handler that reports its kind, whether it is mutating, and performs the actual execution.

Required Methods§

Source

fn kind(&self) -> ToolKind

The ToolKind this handler expects (e.g. Function or Mcp).

Source

fn handle<'life0, 'async_trait>( &'life0 self, invocation: ToolInvocation, ) -> Pin<Box<dyn Future<Output = Result<ToolOutput, FunctionCallError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute the tool with the given invocation context.

Provided Methods§

Source

fn matches_kind(&self, kind: ToolKind) -> bool

Returns true if kind matches this handler’s expected kind.

The default implementation compares against kind().

Source

fn is_mutating(&self) -> bool

Whether this tool performs side-effects that require user approval.

Defaults to false (read-only / safe).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§