Skip to main content

ToolRegistry

Struct ToolRegistry 

Source
pub struct ToolRegistry { /* private fields */ }
Expand description

Registry of available tools. Maintains a name→tool map and a cached JSON schema array that gets sent to the API. Thread-safe via Arc<RwLock<ToolRegistry>>.

Implementations§

Source§

impl ToolRegistry

Source

pub fn new() -> Self

Source

pub fn empty() -> Self

Empty registry for tests and narrow embedded runtimes that want to opt in to specific tools explicitly.

Source

pub fn disable(&mut self, names: &[String])

Remove built-in tools by runtime name (config disabled_tools).

Compatibility wrapper over Self::try_disable; the only failure mode is catalog generation exhaustion, on which this fails closed by panicking with the registry left fully unchanged.

Source

pub fn try_disable(&mut self, names: &[String]) -> Result<(), CatalogError>

Fallible disable: remove built-in tools by runtime name, then rebuild the cached schema, name maps, and capability catalog. Unknown names are ignored; a call that removes nothing is a no-op and does not advance the catalog generation. A call that removes tools advances the catalog generation strictly past its prior value, so grants issued against removed capabilities cannot stay valid.

The rebuilt candidate is fully constructed and generation-rebased BEFORE it is committed to self: on any failure the live registry (tools, schema, catalog entries, generation) is left untouched, so a generation-exhausted disable can never leave a generation-rewound, partially changed registry behind a non-poisoning lock.

Source

pub fn without_subagent() -> Self

Registry without subagent tool — used for subagent runtimes to prevent recursion.

Source

pub fn without_subagent_with_extensions(extension_tools: &ToolRegistry) -> Self

Built-in subagent registry plus extension tools merged in from a shared registry. Used by subagents that need to invoke extension-provided tools while still excluding the recursive subagent_* tools.

Only tools whose Tool::extension_id() returns Some(_) are merged; built-ins inside extension_tools are ignored to avoid duplicating or shadowing the canonical built-in instances.

Source

pub fn register(&mut self, tool: Arc<dyn Tool>)

Register an additional tool at runtime (e.g. MCP tools, custom tools). If a tool with the same name exists, it is replaced.

Compatibility wrapper over Self::try_register. The only failure mode is catalog generation exhaustion (a u64 mutation counter), which is unreachable in practice; if it ever occurs this wrapper fails closed by panicking rather than exposing a tool the catalog could not record. Callers that can surface errors should prefer Self::try_register.

Source

pub fn try_register(&mut self, tool: Arc<dyn Tool>) -> Result<(), CatalogError>

Fallible registration: catalog the tool first (fail-closed — on error nothing is mutated and no schema is exposed), then insert it into the live map and rebuild the exposed schema. Replacing a tool whose capability identity changes drops the stale catalog entry in the same generation advance.

Source

pub fn try_register_batch( &mut self, tool_list: Vec<Arc<dyn Tool>>, ) -> Result<usize, CatalogError>

Atomically register a whole batch (Task 19 boot-time dormant MCP entries). STRICTLY ADDITIVE: before any mutation, every member’s runtime name AND capability identity is preflighted against both the live registry and the rest of the batch — an existing tool can never be replaced through a batch, and two members whose distinct identities collapse onto one runtime name (e.g. ext__ separator collisions) are rejected typed. Only after preflight is the FULL candidate registry built (per-tool catalog mutations plus a single schema rebuild) and committed on complete success. Any failure rejects the ENTIRE batch and leaves the live registry — tools, schema, catalog entries, and generation — byte-identically unchanged; no partial batch can ever be observed. Never invokes any tool, factory, extension handler, or MCP connection.

Source

pub fn catalog(&self) -> &ToolCatalog

Read-only view of the capability catalog. Reading never mutates registry state; the exposed tools_schema() stays byte-identical.

Source

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

Source

pub fn runtime_name_for_api<'a>(&'a self, name: &'a str) -> &'a str

Source

pub fn resolve_wire_call(&self, wire_name: &str) -> Option<ResolvedToolCall>

Atomic wire-name resolution for the execution gate (Task 16): map the incoming API/wire name through the deterministic sanitized-name reverse mapping to the exact live runtime tool, then derive its catalog crate::tools::catalog::ToolId from the resolved tool instance itself — never from the alias string. Because this runs on one &self borrow (i.e. under the caller’s registry read lock), the resolution, the catalog reachable via Self::catalog, and any subsequent implementation acquisition observe one consistent registry snapshot.

Source

pub fn translate_input_for_api_tool( &self, tool_name: &str, input: Value, ) -> Value

Source

pub fn tools_schema(&self) -> Arc<Vec<Value>> ⓘ

Source

pub fn session_tools_schema( &self, session: &SessionToolSet, ) -> SessionSchemaProjection

Deterministic session schema projection (Task 17, spec §7.7): select from the EXISTING cached exposed schema exactly the entries whose capability identity is core or exactly-activated in session, preserving cached byte ordering, API-safe names, and collision suffixes. Pure read: no catalog insertion, no schema rebuild, no factory invocation, no process/network. Default runtime exposure (tools_schema) is unaffected until Task 18 opts in.

Drift handling (per-tool digest + provenance validation fix): catalog generation drift does NOT fail the whole projection — an unrelated background mutation must not blank a session’s entire tool schema. Instead the projection is validated per tool: entries whose CURRENT catalog record digest AND trust provenance match the session’s pins are included; entries whose record drifted (changed digest, changed provenance — even an internally coherent one) or vanished (uncataloged) are dropped fail-closed and REPORTED in the returned SessionSchemaProjection::dropped list — they would be denied by the execution gate anyway, so advertising them would be dishonest.

Source

pub fn tool_names_for_extension(&self, extension_id: &str) -> Vec<String>

Return runtime names of tools owned by the given extension id, sorted ascending. Built-in tools (which return None from Tool::extension_id) are excluded.

Source

pub fn iter_tools_sorted(&self) -> Vec<&Arc<dyn Tool>>

Iterate all registered tools, sorted by name for deterministic output. Used by synaps tools export to build the static schema manifest.

Trait Implementations§

Source§

impl Clone for ToolRegistry

Source§

fn clone(&self) -> ToolRegistry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for ToolRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more