pub struct McpToolRegistry<Counterpart: Role> { /* private fields */ }schemars only.Expand description
Runtime-neutral registry for MCP tools.
Implementations§
Source§impl<Counterpart: Role> McpToolRegistry<Counterpart>
impl<Counterpart: Role> McpToolRegistry<Counterpart>
Sourcepub fn set_instructions(&mut self, instructions: impl ToString)
pub fn set_instructions(&mut self, instructions: impl ToString)
Set the server instructions that are provided to the client.
Sourcepub fn instructions(&self) -> Option<&str>
pub fn instructions(&self) -> Option<&str>
Server instructions provided to the client.
Sourcepub fn register_tool(&mut self, tool: impl McpTool<Counterpart> + 'static)
pub fn register_tool(&mut self, tool: impl McpTool<Counterpart> + 'static)
Register a tool.
Sourcepub fn tools(&self) -> impl Iterator<Item = &RegisteredMcpTool<Counterpart>>
pub fn tools(&self) -> impl Iterator<Item = &RegisteredMcpTool<Counterpart>>
Return all registered tools in registration order.
Sourcepub fn enabled_tools(
&self,
) -> impl Iterator<Item = &RegisteredMcpTool<Counterpart>>
pub fn enabled_tools( &self, ) -> impl Iterator<Item = &RegisteredMcpTool<Counterpart>>
Return enabled registered tools in registration order.
Sourcepub fn tool(&self, name: &str) -> Option<&RegisteredMcpTool<Counterpart>>
pub fn tool(&self, name: &str) -> Option<&RegisteredMcpTool<Counterpart>>
Return a registered tool by name, even if it is disabled.
Sourcepub fn enabled_tool(
&self,
name: &str,
) -> Option<&RegisteredMcpTool<Counterpart>>
pub fn enabled_tool( &self, name: &str, ) -> Option<&RegisteredMcpTool<Counterpart>>
Return an enabled tool by name.
Sourcepub fn contains_tool(&self, name: &str) -> bool
pub fn contains_tool(&self, name: &str) -> bool
Check whether a tool is registered.
Sourcepub fn add_tool_admission<F>(
&mut self,
name: &str,
admit: F,
to_future_hack: impl for<'a> Fn(&'a F, McpAdmission) -> BoxFuture<'a, Result<(), McpRejection>> + Send + Sync + 'static,
) -> Result<(), UnknownToolError>
Available on crate feature unstable_mcp_over_acp only.
pub fn add_tool_admission<F>( &mut self, name: &str, admit: F, to_future_hack: impl for<'a> Fn(&'a F, McpAdmission) -> BoxFuture<'a, Result<(), McpRejection>> + Send + Sync + 'static, ) -> Result<(), UnknownToolError>
unstable_mcp_over_acp only.Adds an admission check for one registered tool, for a tool that
cannot state its rule in McpTool::admit, such as a function tool.
The check is an async closure of the request. Pass
mcp_admission! as the last argument.
The check runs after the tool’s own McpTool::admit and after the
checks added for the tool before. Registering another tool under the
same name removes it.
§Errors
Returns UnknownToolError if no tool with this name is registered.
Sourcepub fn admit(
&self,
request: McpAdmission,
) -> BoxFuture<'_, Result<(), McpRejection>>
Available on crate feature unstable_mcp_over_acp only.
pub fn admit( &self, request: McpAdmission, ) -> BoxFuture<'_, Result<(), McpRejection>>
unstable_mcp_over_acp only.Decides whether a request to a server built from this registry is admitted.
For a tools/call request that names an enabled tool, this is that
tool’s RegisteredMcpTool::admit. Every other request is admitted,
including a call of a tool that is unknown or disabled.
§Errors
The future returns the tool’s McpRejection.
Sourcepub fn disable_all_tools(&mut self)
pub fn disable_all_tools(&mut self)
Disable all tools. After calling this, only tools explicitly enabled
with enable_tool will be available.
Sourcepub fn enable_all_tools(&mut self)
pub fn enable_all_tools(&mut self)
Enable all tools. After calling this, all tools will be available
except those explicitly disabled with disable_tool.
Sourcepub fn disable_tool(&mut self, name: &str) -> Result<(), UnknownToolError>
pub fn disable_tool(&mut self, name: &str) -> Result<(), UnknownToolError>
Disable a specific tool by name.
§Errors
Returns UnknownToolError if no tool with this name is registered.
Sourcepub fn enable_tool(&mut self, name: &str) -> Result<(), UnknownToolError>
pub fn enable_tool(&mut self, name: &str) -> Result<(), UnknownToolError>
Enable a specific tool by name.
§Errors
Returns UnknownToolError if no tool with this name is registered.