Skip to main content

ToolSource

Trait ToolSource 

Source
pub trait ToolSource: Send + Sync {
    // Required methods
    fn specs(&self) -> Vec<ToolSpec>;
    fn get(&self, name: &ToolName) -> Option<Arc<dyn Tool>>;

    // Provided methods
    fn drain_catalog_events(&self) -> Vec<ToolCatalogEvent> { ... }
    fn prefixed(self, prefix: impl Into<String>) -> Prefixed<Self>
       where Self: Sized { ... }
    fn filtered<F>(self, predicate: F) -> Filtered<Self, F>
       where Self: Sized,
             F: Fn(&ToolName) -> bool + Send + Sync + 'static { ... }
    fn renamed<I>(self, mapping: I) -> Renamed<Self>
       where Self: Sized,
             I: IntoIterator<Item = (ToolName, ToolName)> { ... }
}
Expand description

Read-side contract for a federated tool catalog.

A BasicToolExecutor composes one or more ToolSources — typically a frozen ToolRegistry of native tools alongside one or more CatalogReaders owned by subsystems (MCP server manager, skill watcher, plugin loader). Each source manages its own lifecycle and concurrency story; the executor only reads.

Required Methods§

Source

fn specs(&self) -> Vec<ToolSpec>

Returns the current spec for every tool in this source.

Source

fn get(&self, name: &ToolName) -> Option<Arc<dyn Tool>>

Looks up a tool by name, returning None if not present.

Provided Methods§

Source

fn drain_catalog_events(&self) -> Vec<ToolCatalogEvent>

Drains pending catalog change events. Static sources return an empty list; dynamic sources surface added/removed/changed batches that the loop forwards to the model on the next turn.

Source

fn prefixed(self, prefix: impl Into<String>) -> Prefixed<Self>
where Self: Sized,

Wraps this source so every advertised tool name is prefixed with <prefix>_. Useful for mounting the same source under multiple namespaces, or for avoiding collisions between MCP catalogs.

Lookups strip the prefix before delegating, and the wrapped tool’s spec() reports the public (prefixed) name so the model and the tool see consistent names.

To wrap an Arc<dyn ToolSource> instead, use Prefixed::new.

Source

fn filtered<F>(self, predicate: F) -> Filtered<Self, F>
where Self: Sized, F: Fn(&ToolName) -> bool + Send + Sync + 'static,

Wraps this source so only tools whose name passes predicate are advertised and resolvable. Tools rejected by the predicate are invisible to the model and return None on lookup.

To wrap an Arc<dyn ToolSource> instead, use Filtered::new.

Source

fn renamed<I>(self, mapping: I) -> Renamed<Self>
where Self: Sized, I: IntoIterator<Item = (ToolName, ToolName)>,

Wraps this source with a name remapping. Each (original, new) pair in mapping causes the tool to be advertised as new and resolved from new back to original on lookup. Tools not in the mapping pass through unchanged.

To wrap an Arc<dyn ToolSource> instead, use Renamed::new.

Implementations on Foreign Types§

Source§

impl<S> ToolSource for Arc<S>
where S: ToolSource + ?Sized,

Implementors§

Source§

impl ToolSource for CatalogReader

Source§

impl ToolSource for ToolRegistry

Source§

impl<S> ToolSource for Prefixed<S>
where S: ToolSource,

Source§

impl<S> ToolSource for Renamed<S>
where S: ToolSource,

Source§

impl<S, F> ToolSource for Filtered<S, F>
where S: ToolSource, F: Fn(&ToolName) -> bool + Send + Sync + 'static,