claude_rust_types/domain/
tool.rs1use claude_rust_errors::AppResult;
2use serde_json::Value;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum PermissionLevel {
6 ReadOnly,
7 Dangerous,
8}
9
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum InterruptBehavior {
12 Cancel,
13 Block,
14}
15
16#[derive(Debug, Clone, Copy)]
17pub struct SearchReadInfo {
18 pub is_search: bool,
19 pub is_read: bool,
20 pub is_list: bool,
21}
22
23#[derive(Debug)]
24pub enum ValidationResult {
25 Ok,
26 Error { message: String, error_code: i32 },
27}
28
29#[async_trait::async_trait]
30pub trait Tool: Send + Sync {
31 fn name(&self) -> &str;
33 fn description(&self) -> &str;
34 fn input_schema(&self) -> Value;
35 fn permission_level(&self) -> PermissionLevel;
36 async fn execute(&self, input: Value) -> AppResult<String>;
37
38 fn aliases(&self) -> &[&str] { &[] }
40 fn search_hint(&self) -> Option<&str> { None }
41 fn is_mcp(&self) -> bool { false }
42 fn is_lsp(&self) -> bool { false }
43 fn should_defer(&self) -> bool { false }
44 fn always_load(&self) -> bool { false }
45
46 fn is_read_only(&self, _input: &Value) -> bool { false }
48 fn is_destructive(&self, _input: &Value) -> bool { false }
49 fn is_concurrent_safe(&self, _input: &Value) -> bool { false }
50 fn is_enabled(&self) -> bool { true }
51 fn interrupt_behavior(&self) -> InterruptBehavior { InterruptBehavior::Block }
52 fn requires_user_interaction(&self) -> bool { false }
53 fn is_open_world(&self, _input: &Value) -> bool { false }
54
55 fn is_search_or_read_command(&self, _input: &Value) -> SearchReadInfo {
57 SearchReadInfo { is_search: false, is_read: false, is_list: false }
58 }
59
60 fn max_result_size_chars(&self) -> usize { 100_000 }
62 fn strict(&self) -> bool { false }
63
64 fn backfill_observable_input(&self, _input: &mut Value) {}
66 async fn validate_input(&self, _input: &Value) -> ValidationResult {
67 ValidationResult::Ok
68 }
69 fn get_path(&self, _input: &Value) -> Option<String> { None }
70
71 fn user_facing_name(&self, _input: &Value) -> String { self.name().to_string() }
73 fn get_tool_use_summary(&self, _input: &Value) -> Option<String> { None }
74 fn get_activity_description(&self, _input: &Value) -> Option<String> { None }
75}