Skip to main content

ToolDyn

Trait ToolDyn 

Source
pub trait ToolDyn: WasmCompatSend + WasmCompatSync {
    // Required methods
    fn name(&self) -> String;
    fn description(&self) -> String;
    fn parameters(&self) -> Value;
    fn call<'a>(
        &'a self,
        args: String,
    ) -> WasmBoxedFuture<'a, Result<String, ToolError>>;

    // Provided methods
    fn call_with_extensions<'a>(
        &'a self,
        args: String,
        _extensions: &'a ToolCallExtensions,
    ) -> WasmBoxedFuture<'a, Result<String, ToolError>> { ... }
    fn call_structured<'a>(
        &'a self,
        args: String,
        extensions: &'a ToolCallExtensions,
    ) -> WasmBoxedFuture<'a, ToolExecutionResult> { ... }
}
Expand description

Wrapper trait to allow for dynamic dispatch of simple tools.

This is the object-safe erased form of Tool: it exposes the same flat metadata and string-based execution methods for runtime dispatch.

Required Methods§

Source

fn name(&self) -> String

Returns the tool name used for dispatch and provider advertisement.

Source

fn description(&self) -> String

Model-facing description of what the tool does.

Source

fn parameters(&self) -> Value

JSON Schema for the tool arguments.

Source

fn call<'a>( &'a self, args: String, ) -> WasmBoxedFuture<'a, Result<String, ToolError>>

Calls the tool with JSON-encoded arguments and returns model-facing text.

Provided Methods§

Source

fn call_with_extensions<'a>( &'a self, args: String, _extensions: &'a ToolCallExtensions, ) -> WasmBoxedFuture<'a, Result<String, ToolError>>

Dynamic dispatch variant of tool execution with per-call runtime extensions.

The default ignores the extensions and delegates to ToolDyn::call. The blanket impl for Tool types overrides this to thread the extensions through to Tool::call_with_extensions.

Source

fn call_structured<'a>( &'a self, args: String, extensions: &'a ToolCallExtensions, ) -> WasmBoxedFuture<'a, ToolExecutionResult>

Execute the tool with per-call extensions, returning a structured ToolExecutionResult (model output + ToolOutcome + result extensions).

This is the structured dynamic boundary the agent loop drives: the result flows through to the StepEvent::ToolResult hook event. Unlike call it never returns a bare error — a failure is carried as ToolOutcome::Error inside the result, with the model-visible message on ToolExecutionResult::model_output.

The default wraps call_with_extensions: an Ok output becomes a ToolOutcome::Success; a ToolError is classified (ToolError::JsonError as ToolFailureKind::InvalidArgs, otherwise ToolFailureKind::Other). The blanket impl for Tool types overrides this to route through Tool::call_structured and Tool::classify_error; a manual ToolDyn impl should override it to emit precise outcomes (e.g. a real timeout).

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl ToolDyn for McpTool

Available on crate feature rmcp only.
Source§

impl<T: Tool> ToolDyn for T