Skip to main content

ToolProvider

Trait ToolProvider 

Source
pub trait ToolProvider: Send + Sync {
    // Required methods
    fn name(&self) -> &'static str;
    fn description(&self) -> &'static str;
    fn can_handle(&self, source: &ToolSource) -> bool;
    fn resolve<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        request: &'life1 ToolResolveRequest<'life2>,
    ) -> Pin<Box<dyn Future<Output = Result<ResolvedTool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn fetch<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        resolved: &'life1 ResolvedTool,
        options: &'life2 ToolOptions,
    ) -> Pin<Box<dyn Future<Output = Result<FetchedTool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn is_cached(&self, resolved: &ResolvedTool, options: &ToolOptions) -> bool;

    // Provided method
    fn check_prerequisites<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Trait for tool providers (GitHub, OCI, Nix).

Each provider implements this trait to handle resolution and fetching of tools from a specific source type. Providers are registered with the ToolRegistry and selected based on the source configuration.

§Example

pub struct GitHubToolProvider { /* ... */ }

#[async_trait]
impl ToolProvider for GitHubToolProvider {
    fn name(&self) -> &'static str { "github" }
    fn description(&self) -> &'static str { "Fetch tools from GitHub releases" }
    // ...
}

Required Methods§

Source

fn name(&self) -> &'static str

Provider name (e.g., “github”, “nix”, “oci”).

This should match the type field in the CUE schema.

Source

fn description(&self) -> &'static str

Human-readable description for help text.

Source

fn can_handle(&self, source: &ToolSource) -> bool

Check if this provider can handle the given source type.

Source

fn resolve<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, request: &'life1 ToolResolveRequest<'life2>, ) -> Pin<Box<dyn Future<Output = Result<ResolvedTool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Resolve a tool specification to a fetchable artifact.

This performs version resolution, platform matching, and returns the concrete artifact reference (image digest, release URL, etc.)

§Arguments
  • request - Resolution parameters including tool name, version, platform, provider-specific config, and optional authentication token
§Errors

Returns an error if resolution fails (version not found, etc.)

Source

fn fetch<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, resolved: &'life1 ResolvedTool, options: &'life2 ToolOptions, ) -> Pin<Box<dyn Future<Output = Result<FetchedTool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Fetch and cache a resolved tool.

Downloads the artifact, extracts binaries, and returns the local path. If the tool is already cached and force_refetch is false, returns the cached path without re-downloading.

§Arguments
  • resolved - A previously resolved tool
  • options - Fetch options (cache dir, force refetch)
§Errors

Returns an error if fetching or extraction fails.

Source

fn is_cached(&self, resolved: &ResolvedTool, options: &ToolOptions) -> bool

Check if a tool is already cached.

Returns true if the tool binary exists in the cache directory.

Provided Methods§

Source

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

Check if provider prerequisites are available.

Called early during runtime activation to fail fast if required dependencies are missing (e.g., Nix CLI not installed).

§Default Implementation

Returns Ok(()) - most providers only need HTTP access.

§Errors

Returns an error with a helpful message if prerequisites are not met.

Implementors§