pub struct ToolRegistry { /* private fields */ }Expand description
Tool Registry
Manages all available tools in the system, including both native tools and MCP tools. Native tools have higher priority than MCP tools with the same name.
Requirements: 2.1, 2.2, 2.3
Implementations§
Source§impl ToolRegistry
impl ToolRegistry
Sourcepub fn with_managers(
permission_manager: Arc<ToolPermissionManager>,
audit_logger: Arc<AuditLogger>,
) -> Self
pub fn with_managers( permission_manager: Arc<ToolPermissionManager>, audit_logger: Arc<AuditLogger>, ) -> Self
Create a new tool registry with permission manager and audit logger
Sourcepub fn set_permission_manager(&mut self, manager: Arc<ToolPermissionManager>)
pub fn set_permission_manager(&mut self, manager: Arc<ToolPermissionManager>)
Set the permission manager
Sourcepub fn set_audit_logger(&mut self, logger: Arc<AuditLogger>)
pub fn set_audit_logger(&mut self, logger: Arc<AuditLogger>)
Set the audit logger
Sourcepub fn permission_manager(&self) -> Option<&Arc<ToolPermissionManager>>
pub fn permission_manager(&self) -> Option<&Arc<ToolPermissionManager>>
Get the permission manager
Sourcepub fn audit_logger(&self) -> Option<&Arc<AuditLogger>>
pub fn audit_logger(&self) -> Option<&Arc<AuditLogger>>
Get the audit logger
Source§impl ToolRegistry
impl ToolRegistry
Sourcepub fn register(&mut self, tool: Box<dyn Tool>)
pub fn register(&mut self, tool: Box<dyn Tool>)
Register a native tool
Native tools have higher priority than MCP tools with the same name. If a native tool with the same name already exists, it will be replaced.
§Arguments
tool- The tool to register
Requirements: 2.1
Sourcepub fn register_mcp(&mut self, name: String, tool: McpToolWrapper)
pub fn register_mcp(&mut self, name: String, tool: McpToolWrapper)
Register an MCP tool
MCP tools have lower priority than native tools. If a native tool with the same name exists, the MCP tool will be shadowed.
§Arguments
name- The tool nametool- The MCP tool wrapper
Requirements: 11.4
Sourcepub fn unregister_mcp(&mut self, name: &str) -> Option<McpToolWrapper>
pub fn unregister_mcp(&mut self, name: &str) -> Option<McpToolWrapper>
Sourcepub fn contains_native(&self, name: &str) -> bool
pub fn contains_native(&self, name: &str) -> bool
Check if a native tool is registered
Sourcepub fn contains_mcp(&self, name: &str) -> bool
pub fn contains_mcp(&self, name: &str) -> bool
Check if an MCP tool is registered
Sourcepub fn native_tool_count(&self) -> usize
pub fn native_tool_count(&self) -> usize
Get the number of registered native tools
Sourcepub fn mcp_tool_count(&self) -> usize
pub fn mcp_tool_count(&self) -> usize
Get the number of registered MCP tools
Sourcepub fn tool_count(&self) -> usize
pub fn tool_count(&self) -> usize
Get the total number of registered tools
Source§impl ToolRegistry
impl ToolRegistry
Sourcepub fn get_all(&self) -> Vec<&dyn Tool>
pub fn get_all(&self) -> Vec<&dyn Tool>
Get all registered tools
Returns all tools with native tools taking priority over MCP tools with the same name.
§Returns
A vector of references to all registered tools
Requirements: 2.3
Sourcepub fn get_definitions(&self) -> Vec<ToolDefinition>
pub fn get_definitions(&self) -> Vec<ToolDefinition>
Get all tool definitions for LLM consumption
Returns definitions for all tools, with native tools taking priority over MCP tools with the same name.
§Returns
A vector of tool definitions
Requirements: 2.4
Sourcepub fn native_tool_names(&self) -> Vec<&str>
pub fn native_tool_names(&self) -> Vec<&str>
Get all native tool names
Sourcepub fn mcp_tool_names(&self) -> Vec<&str>
pub fn mcp_tool_names(&self) -> Vec<&str>
Get all MCP tool names
Sourcepub fn tool_names(&self) -> Vec<&str>
pub fn tool_names(&self) -> Vec<&str>
Get all tool names (unique, native tools shadow MCP tools)
Source§impl ToolRegistry
impl ToolRegistry
Sourcepub async fn execute(
&self,
name: &str,
params: Value,
context: &ToolContext,
on_permission_request: Option<PermissionRequestCallback>,
) -> Result<ToolResult, ToolError>
pub async fn execute( &self, name: &str, params: Value, context: &ToolContext, on_permission_request: Option<PermissionRequestCallback>, ) -> Result<ToolResult, ToolError>
Execute a tool by name with permission checking and audit logging
This method:
- Looks up the tool by name
- Performs permission check (if permission manager is configured)
- Handles permission request callback for ‘Ask’ behavior
- Executes the tool
- Records audit log (if audit logger is configured)
§Arguments
name- The tool name to executeparams- The tool parameterscontext- The execution contexton_permission_request- Optional callback for permission requests
§Returns
Ok(ToolResult)- The execution resultErr(ToolError)- If the tool is not found, permission denied, or execution fails
Requirements: 2.5, 2.6, 8.1, 8.2
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ToolRegistry
impl !RefUnwindSafe for ToolRegistry
impl Send for ToolRegistry
impl Sync for ToolRegistry
impl Unpin for ToolRegistry
impl UnsafeUnpin for ToolRegistry
impl !UnwindSafe for ToolRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.