1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! Base tool trait definition
use async_trait::async_trait;
use crate::mcp::registry::{ToolContext, ToolResult};
/// Tool trait for MCP-compatible tools
///
/// Tools implement this trait to provide functionality that can be
/// invoked by Claude or other agents.
#[async_trait]
pub trait Tool: Send + Sync + std::fmt::Debug {
/// Get the tool name
fn name(&self) -> &str;
/// Get the tool description
fn description(&self) -> &str;
/// Get the JSON Schema for the tool's input parameters
fn input_schema(&self) -> serde_json::Value;
/// Execute the tool with the given input
async fn execute(&self, input: serde_json::Value, context: &ToolContext) -> ToolResult;
/// Check if this tool requires permission before execution
fn requires_permission(&self) -> bool {
true
}
/// Get the tool category/kind
fn kind(&self) -> ToolKind {
ToolKind::Other
}
}
/// Tool categories for UI display
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ToolKind {
/// File reading operations
Read,
/// File editing/writing operations
Edit,
/// Command execution
Execute,
/// Search operations
Search,
/// Network/fetch operations
Fetch,
/// Thinking/planning operations
Think,
/// Other operations
Other,
}
impl ToolKind {
/// Get a human-readable label for the kind
pub fn label(&self) -> &'static str {
match self {
ToolKind::Read => "Read",
ToolKind::Edit => "Edit",
ToolKind::Execute => "Execute",
ToolKind::Search => "Search",
ToolKind::Fetch => "Fetch",
ToolKind::Think => "Think",
ToolKind::Other => "Tool",
}
}
}