pub struct ToolAnnotationsMap { /* private fields */ }Expand description
A map of tool names to their annotations, for use by middleware.
This is automatically inserted into RouterRequest::extensions for
tools/call requests, allowing middleware to inspect tool safety hints
(e.g., read_only_hint, destructive_hint) without needing direct
access to the router’s tool registry.
§Example
use tower_mcp::router::ToolAnnotationsMap;
use tower_mcp::protocol::McpRequest;
// In a middleware Service::call():
fn call(&mut self, req: RouterRequest) -> Self::Future {
if let McpRequest::CallTool(params) = &req.inner {
if let Some(map) = req.extensions.get::<ToolAnnotationsMap>() {
let annotations = map.get(¶ms.name);
// Check annotations.read_only_hint, destructive_hint, etc.
}
}
self.inner.call(req)
}Implementations§
Source§impl ToolAnnotationsMap
impl ToolAnnotationsMap
Sourcepub fn get(&self, tool_name: &str) -> Option<&ToolAnnotations>
pub fn get(&self, tool_name: &str) -> Option<&ToolAnnotations>
Look up annotations for a tool by name.
Returns None if the tool has no annotations or doesn’t exist.
Sourcepub fn is_read_only(&self, tool_name: &str) -> bool
pub fn is_read_only(&self, tool_name: &str) -> bool
Check if a tool is read-only (does not modify state).
Returns false if the tool has no annotations or doesn’t exist
(the MCP spec default for readOnlyHint is false).
Sourcepub fn is_destructive(&self, tool_name: &str) -> bool
pub fn is_destructive(&self, tool_name: &str) -> bool
Check if a tool may have destructive effects.
Returns true if the tool has no annotations or doesn’t exist
(the MCP spec default for destructiveHint is true).
Sourcepub fn is_idempotent(&self, tool_name: &str) -> bool
pub fn is_idempotent(&self, tool_name: &str) -> bool
Check if a tool is idempotent.
Returns false if the tool has no annotations or doesn’t exist
(the MCP spec default for idempotentHint is false).
Trait Implementations§
Source§impl Clone for ToolAnnotationsMap
impl Clone for ToolAnnotationsMap
Source§fn clone(&self) -> ToolAnnotationsMap
fn clone(&self) -> ToolAnnotationsMap
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more