pub trait DynamicToolProvider {
// Required methods
fn add_tool(
&mut self,
name: &str,
definition: ToolDefinition,
handler: Arc<dyn Fn(&Value) -> Result<Value, ToolError> + Send + Sync>,
);
fn remove_tool(&mut self, name: &str) -> bool;
fn enable_for(&mut self, name: &str, tenant: &str);
fn disable_for(&mut self, name: &str, tenant: &str);
fn visible_tools(&self, tenant: Option<&str>) -> Vec<ToolDefinition>;
}Expand description
T-010: trait for runtime-mutable tool registries.
Distinct from the compile-time crate::ToolProvider trait.
Existing macro-generated providers do not implement this — the
macro’s whole value proposition is “schema is fixed at compile
time.” DynamicToolProvider is opt-in: callers who need
mutability build a DynamicToolRegistry (or implement this
trait themselves) and serve tools through it.
The trait surface is deliberately small and matches the pain points in PP-B1:
add_tool/remove_tool— global registration, takes effect for every caller.enable_for/disable_for— per-tenant overrides layered on top of the global registry.
Per-call dispatch (call_tool) goes through the existing
crate::ToolCaller trait; DynamicToolRegistry implements
both.
Required Methods§
Sourcefn add_tool(
&mut self,
name: &str,
definition: ToolDefinition,
handler: Arc<dyn Fn(&Value) -> Result<Value, ToolError> + Send + Sync>,
)
fn add_tool( &mut self, name: &str, definition: ToolDefinition, handler: Arc<dyn Fn(&Value) -> Result<Value, ToolError> + Send + Sync>, )
Register a tool under name. Replaces any existing registration
under the same name. Returns the registration’s ToolDefinition
for inspection / chaining.
handler is the closure that actually runs when the tool is
invoked; it receives the JSON args object and must return either
the result JSON or a ToolError.
Sourcefn remove_tool(&mut self, name: &str) -> bool
fn remove_tool(&mut self, name: &str) -> bool
Remove a tool from the global registry. Returns true when the
tool existed and was removed; false when no such tool was
registered.
Sourcefn enable_for(&mut self, name: &str, tenant: &str)
fn enable_for(&mut self, name: &str, tenant: &str)
Enable name for a specific tenant. The tool must already be
in the global registry (use DynamicToolProvider::add_tool
first); this method only flips the per-tenant visibility flag.
A tenant id is any &str the caller picks (user id, API key,
session id, etc.); it is opaque to the registry.
Sourcefn disable_for(&mut self, name: &str, tenant: &str)
fn disable_for(&mut self, name: &str, tenant: &str)
Disable name for a specific tenant. Has no effect on the
global registry; other tenants keep their visibility.
Sourcefn visible_tools(&self, tenant: Option<&str>) -> Vec<ToolDefinition>
fn visible_tools(&self, tenant: Option<&str>) -> Vec<ToolDefinition>
List the tools visible to tenant (or, when tenant is None,
every globally-registered tool). Useful for diagnostics / REST
/tools endpoints.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".