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