Skip to main content

DynamicToolRegistry

Struct DynamicToolRegistry 

Source
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:

  1. it is globally registered, AND
  2. the tenant has no entry in the overrides map (default-allow), OR
  3. 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

Source

pub fn new() -> Self

Create an empty registry.

§Example
use tokitai_core::DynamicToolRegistry;

let reg = DynamicToolRegistry::new();
assert!(reg.list_global().is_empty());
Source

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).

Source

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

Return true if name is currently registered (globally).

Source

pub fn definition(&self, name: &str) -> Option<ToolDefinition>

Return the ToolDefinition for a globally-registered tool, or None if it is not registered.

Source

pub fn clear(&self)

Drop all globally-registered tools and per-tenant overrides. Useful for tests and for “reset to known state” admin flows.

Source

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).

Source§

fn capability_manifest() -> &'static [(&'static str, &'static [&'static str])]

Return the aggregated (tool_name, requires) slice for this provider. The slice is &'static so no allocation happens on the hot path.
Source§

impl Clone for DynamicToolRegistry

Source§

fn clone(&self) -> DynamicToolRegistry

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 DynamicToolRegistry

Source§

fn default() -> DynamicToolRegistry

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

impl DynamicToolProvider for DynamicToolRegistry

Source§

fn add_tool( &mut self, name: &str, definition: ToolDefinition, handler: DynamicHandler, )

Register a tool under name. Replaces any existing registration under the same name. Returns the registration’s ToolDefinition for inspection / chaining. Read more
Source§

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.
Source§

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. Read more
Source§

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.
Source§

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.
Source§

impl ToolCaller for DynamicToolRegistry

Source§

fn call_tool(&self, name: &str, args: &Value) -> Result<Value, ToolError>

Invoke a tool by name with the given JSON args. Read more
Source§

impl ToolProvider for DynamicToolRegistry

Source§

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.

Source§

fn tool_count() -> usize

Number of tools produced by this provider.
Source§

fn find_tool(name: &str) -> Option<&'static ToolDefinition>

Look up a tool definition by its name.

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> 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> 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 = 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.