claude_code_acp/mcp/tools/
base.rs

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