pub struct Tool {
pub info: ToolInfo,
pub handler: Box<dyn ToolHandler>,
pub enabled: bool,
pub validator: Option<ParameterValidator>,
pub enhanced_metadata: EnhancedToolMetadata,
}
Expand description
A registered tool with its handler, validation, and enhanced metadata
Fields§
§info: ToolInfo
Information about the tool
handler: Box<dyn ToolHandler>
Handler that implements the tool’s functionality
enabled: bool
Whether the tool is currently enabled
validator: Option<ParameterValidator>
Parameter validator for input validation
enhanced_metadata: EnhancedToolMetadata
Enhanced metadata for tool behavior, categorization, and performance
Implementations§
Source§impl Tool
impl Tool
Sourcepub fn new<H>(
name: String,
description: Option<String>,
input_schema: Value,
handler: H,
) -> Selfwhere
H: ToolHandler + 'static,
pub fn new<H>(
name: String,
description: Option<String>,
input_schema: Value,
handler: H,
) -> Selfwhere
H: ToolHandler + 'static,
Create a new tool with the given information and handler
§Arguments
name
- Name of the tooldescription
- Optional description of the toolinput_schema
- JSON schema describing the input parametershandler
- Implementation of the tool’s functionality
Sourcepub fn with_validation<H>(
name: String,
description: Option<String>,
input_schema: Value,
handler: H,
validation_config: ValidationConfig,
) -> Selfwhere
H: ToolHandler + 'static,
pub fn with_validation<H>(
name: String,
description: Option<String>,
input_schema: Value,
handler: H,
validation_config: ValidationConfig,
) -> Selfwhere
H: ToolHandler + 'static,
Create a new tool with custom validation configuration
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check if the tool is enabled
Sourcepub async fn call_unchecked(
&self,
arguments: HashMap<String, Value>,
) -> McpResult<ToolResult>
pub async fn call_unchecked( &self, arguments: HashMap<String, Value>, ) -> McpResult<ToolResult>
Execute the tool without validation or performance tracking (for advanced use cases)
Sourcepub fn validate_parameters(
&self,
arguments: &mut HashMap<String, Value>,
) -> McpResult<()>
pub fn validate_parameters( &self, arguments: &mut HashMap<String, Value>, ) -> McpResult<()>
Validate parameters without executing the tool
Sourcepub fn set_behavior_hints(&mut self, hints: ToolBehaviorHints)
pub fn set_behavior_hints(&mut self, hints: ToolBehaviorHints)
Set behavior hints for the tool
Sourcepub fn behavior_hints(&self) -> &ToolBehaviorHints
pub fn behavior_hints(&self) -> &ToolBehaviorHints
Get behavior hints for the tool
Sourcepub fn set_category(&mut self, category: ToolCategory)
pub fn set_category(&mut self, category: ToolCategory)
Set category for the tool
Sourcepub fn category(&self) -> Option<&ToolCategory>
pub fn category(&self) -> Option<&ToolCategory>
Get category for the tool
Sourcepub fn set_version(&mut self, version: String)
pub fn set_version(&mut self, version: String)
Set version for the tool
Set author for the tool
Get author of the tool
Sourcepub fn deprecate(&mut self, deprecation: ToolDeprecation)
pub fn deprecate(&mut self, deprecation: ToolDeprecation)
Mark tool as deprecated
Sourcepub fn is_deprecated(&self) -> bool
pub fn is_deprecated(&self) -> bool
Check if tool is deprecated
Sourcepub fn deprecation_warning(&self) -> Option<String>
pub fn deprecation_warning(&self) -> Option<String>
Get deprecation warning if tool is deprecated
Sourcepub fn performance_metrics(&self) -> ToolPerformanceMetrics
pub fn performance_metrics(&self) -> ToolPerformanceMetrics
Get performance metrics for the tool
Sourcepub fn add_custom_metadata(&mut self, key: String, value: Value)
pub fn add_custom_metadata(&mut self, key: String, value: Value)
Add custom metadata field
Sourcepub fn get_custom_metadata(&self, key: &str) -> Option<&Value>
pub fn get_custom_metadata(&self, key: &str) -> Option<&Value>
Get custom metadata field
Sourcepub fn matches_category_filter(&self, filter: &CategoryFilter) -> bool
pub fn matches_category_filter(&self, filter: &CategoryFilter) -> bool
Check if tool matches a category filter
Sourcepub fn is_cacheable(&self) -> bool
pub fn is_cacheable(&self) -> bool
Check if tool is suitable for caching based on behavior hints
Sourcepub fn is_destructive(&self) -> bool
pub fn is_destructive(&self) -> bool
Check if tool is destructive
Sourcepub fn is_read_only(&self) -> bool
pub fn is_read_only(&self) -> bool
Check if tool is read-only
Sourcepub fn is_idempotent(&self) -> bool
pub fn is_idempotent(&self) -> bool
Check if tool is idempotent
Sourcepub fn requires_auth(&self) -> bool
pub fn requires_auth(&self) -> bool
Check if tool requires authentication