pub struct ToolRegistry { /* private fields */ }Expand description
Registry of tools for dynamic dispatch and type-safe native calls.
Implementations§
Source§impl ToolRegistry
impl ToolRegistry
Sourcepub fn builder() -> ToolRegistryBuilder
pub fn builder() -> ToolRegistryBuilder
Create a new registry builder.
Sourcepub fn list_names(&self) -> Vec<String>
pub fn list_names(&self) -> Vec<String>
List all tool names in the registry.
Sourcepub fn subset<'a>(
&self,
names: impl IntoIterator<Item = &'a str>,
) -> ToolRegistry
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.
Sourcepub async fn dispatch_json(
&self,
name: &str,
args: Value,
ctx: &ToolContext,
) -> Result<Value, ToolError>
pub async fn dispatch_json( &self, name: &str, args: Value, ctx: &ToolContext, ) -> Result<Value, ToolError>
Dispatch a tool call using JSON arguments.
Sourcepub async fn dispatch_json_formatted(
&self,
name: &str,
args: Value,
ctx: &ToolContext,
text_opts: &TextOptions,
) -> Result<FormattedResult, ToolError>
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.
Sourcepub fn handle<T: Tool>(&self) -> Result<ToolHandle<T>, ToolError>
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.
Sourcepub fn iter_erased(&self) -> Vec<Arc<dyn ErasedTool>>
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.
Sourcepub fn merge_all(regs: impl IntoIterator<Item = ToolRegistry>) -> ToolRegistry
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.