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, EnterPlanModeTool, ExitPlanModeTool, FileEditTool, FileWriteTool,
8    GlobTool, GrepTool, ReadTool, TodoReadTool, TodoWriteTool, WebFetchTool, WebSearchTool,
9};
10
11pub async fn load_mcp_tools(cwd: &str) -> Vec<std::sync::Arc<dyn claude_rust_types::Tool>> {
12    use infrastructure::mcp_client::McpClient;
13    use infrastructure::mcp_config::load_mcp_configs;
14    use infrastructure::mcp_tool::McpDynamicTool;
15    use std::sync::Arc;
16    use tokio::sync::Mutex;
17
18    let mut tools: Vec<Arc<dyn claude_rust_types::Tool>> = Vec::new();
19    for (server_name, entry) in load_mcp_configs(cwd) {
20        let mut client = match McpClient::start(&server_name, &entry).await {
21            Ok(c) => c,
22            Err(e) => { tracing::warn!("MCP '{server_name}' start failed: {e}"); continue; }
23        };
24        let tool_list = match client.list_tools().await {
25            Ok(t) => t,
26            Err(e) => { tracing::warn!("MCP '{server_name}' list_tools failed: {e}"); continue; }
27        };
28        let shared = Arc::new(Mutex::new(client));
29        for (raw_name, description, schema) in tool_list {
30            let tool_name = format!("mcp__{server_name}__{raw_name}");
31            tools.push(Arc::new(McpDynamicTool {
32                tool_name,
33                tool_description: description,
34                tool_schema: schema,
35                client: shared.clone(),
36                raw_name,
37            }));
38        }
39        tracing::info!("MCP '{server_name}' loaded {} tools", tools.len());
40    }
41    tools
42}