pub struct ToolMetadataRegistry { /* private fields */ }Expand description
Local-only registry holding the full ToolDescriptor for every
tool serve_tool registered on this node. The
tool.metadata.fetch handler reads this registry; serve_tool
writes to it on registration and removes on Drop.
parking_lot::Mutex<HashMap<...>> shape mirrors the existing
cancel_registry + tool_metadata patterns in the codebase
— sync access from the dispatch path, no async lock required.
Caches the snapshot as an Arc<[ToolDescriptor]> so the
announce path (which calls snapshot() every announce — every
capability-version bump) doesn’t re-clone every descriptor when
nothing has changed. Insert/remove invalidate the cache.
Implementations§
Source§impl ToolMetadataRegistry
impl ToolMetadataRegistry
Sourcepub fn new() -> ToolMetadataRegistry
pub fn new() -> ToolMetadataRegistry
Empty registry — what a fresh MeshNode ships with before
any serve_tool call.
Sourcepub fn insert(&self, descriptor: ToolDescriptor) -> Option<ToolDescriptor>
pub fn insert(&self, descriptor: ToolDescriptor) -> Option<ToolDescriptor>
Insert (or replace) the descriptor for name. Returns the
previous entry if one existed — callers can use this for
duplicate-registration diagnostics (the SDK’s serve_tool
rejects duplicate names rather than silently overwriting).
Sourcepub fn get(&self, name: &str) -> Option<ToolDescriptor>
pub fn get(&self, name: &str) -> Option<ToolDescriptor>
Look up the full descriptor for name. None when the
host doesn’t serve this tool. Cloned because the registry
is mutex-protected; the clone is cheap (small heap fields).
Sourcepub fn remove(&self, name: &str) -> Option<ToolDescriptor>
pub fn remove(&self, name: &str) -> Option<ToolDescriptor>
Remove the descriptor for name. Returns the removed entry
if one existed. Called by the SDK’s serve_tool Drop hook.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of registered tools. Useful for the
auto-install branch — the host installs the
tool.metadata.fetch service the first time the registry
goes from empty to non-empty.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
True when no tools are registered. Convenience used by the
same auto-install branch (registry.is_empty() reads
cleaner than len() == 0 at the call site).
Sourcepub fn snapshot(&self) -> Arc<[ToolDescriptor]> ⓘ
pub fn snapshot(&self) -> Arc<[ToolDescriptor]> ⓘ
Snapshot every descriptor as a cached Arc<[ToolDescriptor]>.
First call after an insert/remove rebuilds the cache; later
calls share the same Arc for free.