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§
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>
Sourcefn project_context_targets(
&self,
_context: &ToolContext,
_arguments: &Value,
) -> Result<Vec<PathBuf>, ToolError>
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.
fn permission_requests( &self, context: &ToolContext, arguments: &Value, ) -> Result<Vec<PermissionRequest>, ToolError>
Sourcefn prepare(
&self,
context: &ToolContext,
arguments: &Value,
) -> Result<ToolPreparation, ToolError>
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.
fn advertisement(&self) -> ToolAdvertisement
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".