Skip to main content

claude_rust_tools/
lib.rs

1pub mod application;
2pub mod domain;
3pub mod infrastructure;
4
5pub use application::ToolRegistry;
6pub use infrastructure::{
7    AskUserTool, BashTool, BriefTool, ConfigTool, CronCreateTool, CronDeleteTool,
8    EnterPlanModeTool, EnterWorktreeTool, ExitPlanModeTool, ExitWorktreeTool,
9    FileEditTool, FileWriteTool, GlobTool, GrepTool, LSPTool, ListMcpResourcesTool,
10    NotebookEditTool, PowerShellTool, REPLTool, ReadMcpResourceTool, ReadTool,
11    RemoteTriggerTool, SendMessageTool, SkillTool, SleepTool, SyntheticOutputTool,
12    TaskCreateTool, TaskGetTool, TaskListTool, TaskOutputTool, TaskStopTool, TaskUpdateTool,
13    TeamCreateTool, TeamDeleteTool, TodoReadTool, TodoWriteTool, ToolSearchTool,
14    WebFetchTool, WebSearchTool,
15    task_manager, todo_store,
16};
17
18pub async fn load_mcp_tools(cwd: &str) -> Vec<std::sync::Arc<dyn claude_rust_types::Tool>> {
19    use infrastructure::mcp_client::McpClient;
20    use infrastructure::mcp_config::load_mcp_configs;
21    use infrastructure::mcp_tool::McpDynamicTool;
22    use std::sync::Arc;
23    use tokio::sync::Mutex;
24
25    let mut tools: Vec<Arc<dyn claude_rust_types::Tool>> = Vec::new();
26    for (server_name, entry) in load_mcp_configs(cwd) {
27        let mut client = match McpClient::start(&server_name, &entry).await {
28            Ok(c) => c,
29            Err(e) => { tracing::warn!("MCP '{server_name}' start failed: {e}"); continue; }
30        };
31        let tool_list = match client.list_tools().await {
32            Ok(t) => t,
33            Err(e) => { tracing::warn!("MCP '{server_name}' list_tools failed: {e}"); continue; }
34        };
35        let shared = Arc::new(Mutex::new(client));
36        for (raw_name, description, schema) in tool_list {
37            let tool_name = format!("mcp__{server_name}__{raw_name}");
38            tools.push(Arc::new(McpDynamicTool {
39                tool_name,
40                tool_description: description,
41                tool_schema: schema,
42                client: shared.clone(),
43                raw_name,
44            }));
45        }
46        tracing::info!("MCP '{server_name}' loaded {} tools", tools.len());
47    }
48    tools
49}