pub struct DynamicToolRegistry { /* private fields */ }Expand description
T-010: concrete dynamic registry.
Thread-safe (Arc<RwLock<...>> internals) so it can be shared
between axum handlers in tokitai-mcp-server and a long-running
admin endpoint that adds/removes tools at runtime.
Tool definitions live in an Inner struct behind an Arc<RwLock>.
Per-tenant overrides are layered on top: enable_for /
disable_for mutate a HashMap<tenant, HashSet<tool_name>>. A
tool is visible to a tenant when:
- it is globally registered, AND
- the tenant has no entry in the overrides map (default-allow), OR
- the tenant’s entry contains the tool name.
Note: when a tenant’s first override is a disable_for, that flips
the default-allow to default-deny for that tenant. Callers wanting
to keep default-allow semantics should enable_for every global
tool after the first disable_for.
Implementations§
Source§impl DynamicToolRegistry
impl DynamicToolRegistry
Sourcepub fn new() -> Self
pub fn new() -> Self
Create an empty registry.
§Example
use tokitai_core::DynamicToolRegistry;
let reg = DynamicToolRegistry::new();
assert!(reg.list_global().is_empty());Sourcepub fn list_global(&self) -> Vec<String>
pub fn list_global(&self) -> Vec<String>
List the names of all globally-registered tools, in insertion order (HashMap ordering is unspecified, but the set itself is deterministic).
Sourcepub fn contains(&self, name: &str) -> bool
pub fn contains(&self, name: &str) -> bool
Return true if name is currently registered (globally).
Sourcepub fn definition(&self, name: &str) -> Option<ToolDefinition>
pub fn definition(&self, name: &str) -> Option<ToolDefinition>
Return the ToolDefinition for a globally-registered tool,
or None if it is not registered.
Sourcepub fn clear(&self)
pub fn clear(&self)
Drop all globally-registered tools and per-tenant overrides. Useful for tests and for “reset to known state” admin flows.
Sourcepub fn call_for_tenant(
&self,
name: &str,
tenant: Option<&str>,
args: &Value,
) -> Result<Value, ToolError>
pub fn call_for_tenant( &self, name: &str, tenant: Option<&str>, args: &Value, ) -> Result<Value, ToolError>
Invoke name honouring tenant’s visibility rules.
Returns ToolError::NotFound when the tool is not visible to
tenant (whether because it was never registered, or because
the tenant’s override set excludes it).
Trait Implementations§
Source§impl CapabilityManifestProvider for DynamicToolRegistry
T-023: dynamic registries inherit the trait’s default
(empty) capability manifest. Operators who need a
per-tenant capability allowlist for a dynamic registry can
wrap it in a McpServerBuilder::with_tool(registry) and
configure the allowlist on the builder. The static
#[tool] macro path is the primary T-023 surface; the
dynamic path is left as a follow-up (the per-tenant gating
already provides a richer policy surface than the static
manifest, so collapsing the two would be a net loss).
impl CapabilityManifestProvider for DynamicToolRegistry
T-023: dynamic registries inherit the trait’s default
(empty) capability manifest. Operators who need a
per-tenant capability allowlist for a dynamic registry can
wrap it in a McpServerBuilder::with_tool(registry) and
configure the allowlist on the builder. The static
#[tool] macro path is the primary T-023 surface; the
dynamic path is left as a follow-up (the per-tenant gating
already provides a richer policy surface than the static
manifest, so collapsing the two would be a net loss).
Source§fn capability_manifest() -> &'static [(&'static str, &'static [&'static str])]
fn capability_manifest() -> &'static [(&'static str, &'static [&'static str])]
(tool_name, requires) slice for
this provider. The slice is &'static so no allocation
happens on the hot path.Source§impl Clone for DynamicToolRegistry
impl Clone for DynamicToolRegistry
Source§fn clone(&self) -> DynamicToolRegistry
fn clone(&self) -> DynamicToolRegistry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Default for DynamicToolRegistry
impl Default for DynamicToolRegistry
Source§fn default() -> DynamicToolRegistry
fn default() -> DynamicToolRegistry
Source§impl DynamicToolProvider for DynamicToolRegistry
impl DynamicToolProvider for DynamicToolRegistry
Source§fn add_tool(
&mut self,
name: &str,
definition: ToolDefinition,
handler: DynamicHandler,
)
fn add_tool( &mut self, name: &str, definition: ToolDefinition, handler: DynamicHandler, )
name. Replaces any existing registration
under the same name. Returns the registration’s ToolDefinition
for inspection / chaining. Read moreSource§fn remove_tool(&mut self, name: &str) -> bool
fn remove_tool(&mut self, name: &str) -> bool
true when the
tool existed and was removed; false when no such tool was
registered.Source§fn enable_for(&mut self, name: &str, tenant: &str)
fn enable_for(&mut self, name: &str, tenant: &str)
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. Read moreSource§fn disable_for(&mut self, name: &str, tenant: &str)
fn disable_for(&mut self, name: &str, tenant: &str)
name for a specific tenant. Has no effect on the
global registry; other tenants keep their visibility.Source§fn visible_tools(&self, tenant: Option<&str>) -> Vec<ToolDefinition>
fn visible_tools(&self, tenant: Option<&str>) -> Vec<ToolDefinition>
tenant (or, when tenant is None,
every globally-registered tool). Useful for diagnostics / REST
/tools endpoints.Source§impl ToolCaller for DynamicToolRegistry
impl ToolCaller for DynamicToolRegistry
Source§impl ToolProvider for DynamicToolRegistry
impl ToolProvider for DynamicToolRegistry
Source§fn tool_definitions() -> &'static [ToolDefinition]
fn tool_definitions() -> &'static [ToolDefinition]
The compile-time static slice is empty by design — the
registry is purely runtime. Servers that need the list call
DynamicToolProvider::visible_tools instead.