Skip to main content

Tool

Trait Tool 

Source
pub trait Tool: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn description(&self) -> &str;
    fn input_schema(&self) -> Value;
    fn effect(&self, arguments: &Value) -> Result<ToolEffect, ToolError>;
    fn execute<'a>(
        &'a self,
        context: &'a ToolContext,
        arguments: Value,
    ) -> BoxFuture<'a, Result<ToolOutput, ToolError>>;

    // Provided methods
    fn irreversible(&self, _arguments: &Value) -> Result<bool, ToolError> { ... }
    fn project_context_targets(
        &self,
        _context: &ToolContext,
        _arguments: &Value,
    ) -> Result<Vec<PathBuf>, ToolError> { ... }
    fn permission_requests(
        &self,
        context: &ToolContext,
        arguments: &Value,
    ) -> Result<Vec<PermissionRequest>, ToolError> { ... }
    fn prepare(
        &self,
        context: &ToolContext,
        arguments: &Value,
    ) -> Result<ToolPreparation, ToolError> { ... }
    fn advertisement(&self) -> ToolAdvertisement { ... }
}
Expand description

Runtime-extensible tool contract. Validation, effect classification, and execution stay together so registry metadata cannot drift from behavior.

Required Methods§

Source

fn name(&self) -> &str

Source

fn description(&self) -> &str

Source

fn input_schema(&self) -> Value

Source

fn effect(&self, arguments: &Value) -> Result<ToolEffect, ToolError>

Source

fn execute<'a>( &'a self, context: &'a ToolContext, arguments: Value, ) -> BoxFuture<'a, Result<ToolOutput, ToolError>>

Provided Methods§

Source

fn irreversible(&self, _arguments: &Value) -> Result<bool, ToolError>

Source

fn project_context_targets( &self, _context: &ToolContext, _arguments: &Value, ) -> Result<Vec<PathBuf>, ToolError>

Filesystem targets used to select nested project instructions.

This is separate from permission targets: command permission matches human command text while its project-context target is the canonical cwd, and network tools intentionally expose no filesystem target.

Source

fn permission_requests( &self, context: &ToolContext, arguments: &Value, ) -> Result<Vec<PermissionRequest>, ToolError>

Source

fn prepare( &self, context: &ToolContext, arguments: &Value, ) -> Result<ToolPreparation, ToolError>

Produces the authorization contract for a call. Most tools execute directly after permission evaluation; TOCTOU-sensitive mutations override this to return an owned, one-shot prepared action.

Source

fn advertisement(&self) -> ToolAdvertisement

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§