Skip to main content

ToolRegistry

Struct ToolRegistry 

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

Registry of tools for dynamic dispatch and type-safe native calls.

Implementations§

Source§

impl ToolRegistry

Source

pub fn builder() -> ToolRegistryBuilder

Create a new registry builder.

Source

pub fn list_names(&self) -> Vec<String>

List all tool names in the registry.

Source

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

Get a tool by name.

Source

pub fn subset<'a>( &self, names: impl IntoIterator<Item = &'a str>, ) -> ToolRegistry

Create a subset registry containing only the specified tools.

Tools not found in the registry are silently ignored.

Source

pub async fn dispatch_json( &self, name: &str, args: Value, ctx: &ToolContext, ) -> Result<Value, ToolError>

Dispatch a tool call using JSON arguments.

Source

pub async fn dispatch_json_formatted( &self, name: &str, args: Value, ctx: &ToolContext, text_opts: &TextOptions, ) -> Result<FormattedResult, ToolError>

Dispatch a tool call using JSON arguments, returning both JSON data and formatted text.

This method enables dual output for MCP and NAPI servers. The text is derived from the tool’s TextFormat implementation if available, otherwise it falls back to pretty-printed JSON.

Source

pub fn handle<T: Tool>(&self) -> Result<ToolHandle<T>, ToolError>

Get a type-safe handle for calling a tool natively (zero JSON).

Returns an error if the tool type is not registered.

Source

pub fn contains(&self, name: &str) -> bool

Check if a tool is registered by name.

Source

pub fn len(&self) -> usize

Get the number of registered tools.

Source

pub fn is_empty(&self) -> bool

Check if the registry is empty.

Source

pub fn iter_erased(&self) -> Vec<Arc<dyn ErasedTool>>

Clone and return erased tool entries (Arc) for composition.

This enables merging multiple registries by iterating over their erased tool entries and re-registering them in a new registry.

Source

pub fn merge_all(regs: impl IntoIterator<Item = ToolRegistry>) -> ToolRegistry

Merge multiple registries into one.

Later entries with duplicate names overwrite earlier ones. This is useful for composing domain-specific registries into a unified registry.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.