claude_rust_tools/application/
registry.rs1use std::collections::HashMap;
2use std::sync::Arc;
3
4use claude_rust_types::Tool;
5use serde_json::{Value, json};
6
7pub struct ToolRegistry {
8 tools: HashMap<String, Arc<dyn Tool>>,
9}
10
11impl ToolRegistry {
12 pub fn new() -> Self {
13 Self {
14 tools: HashMap::new(),
15 }
16 }
17
18 pub fn register(&mut self, tool: Arc<dyn Tool>) {
19 self.tools.insert(tool.name().to_string(), tool);
20 }
21
22 pub fn get(&self, name: &str) -> Option<&Arc<dyn Tool>> {
23 self.tools.get(name)
24 }
25
26 pub fn tool_definitions(&self) -> Vec<Value> {
27 self.tools
28 .values()
29 .map(|t| {
30 json!({
31 "name": t.name(),
32 "description": t.description(),
33 "input_schema": t.input_schema(),
34 })
35 })
36 .collect()
37 }
38}
39
40impl Default for ToolRegistry {
41 fn default() -> Self {
42 Self::new()
43 }
44}