Skip to main content

stynx_code_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, OptionalQuestionBridge, PowerShellTool, QuestionBridge, QuestionRequest,
11    REPLTool, ReadMcpResourceTool, ReadTool, RemoteTriggerTool, SendMessageTool, SharedQuestionBridge,
12    SkillTool, SleepTool, SyntheticOutputTool, TaskCreateTool, TaskGetTool, TaskListTool,
13    TaskOutputTool, TaskStopTool, TaskUpdateTool, TeamCreateTool, TeamDeleteTool, TodoReadTool,
14    TodoWriteTool, ToolSearchTool, WebFetchTool, WebSearchTool, task_manager, todo_store,
15};
16
17pub async fn load_mcp_tools(cwd: &str) -> Vec<std::sync::Arc<dyn stynx_code_types::Tool>> {
18    use infrastructure::mcp_client::McpClient;
19    use infrastructure::mcp_config::load_mcp_configs;
20    use infrastructure::mcp_tool::McpDynamicTool;
21    use std::sync::Arc;
22    use tokio::sync::Mutex;
23
24    let mut tools: Vec<Arc<dyn stynx_code_types::Tool>> = Vec::new();
25    for (server_name, entry) in load_mcp_configs(cwd) {
26        let mut client = match McpClient::start(&server_name, &entry).await {
27            Ok(c) => c,
28            Err(e) => { tracing::warn!("MCP '{server_name}' start failed: {e}"); continue; }
29        };
30        let tool_list = match client.list_tools().await {
31            Ok(t) => t,
32            Err(e) => { tracing::warn!("MCP '{server_name}' list_tools failed: {e}"); continue; }
33        };
34        let shared = Arc::new(Mutex::new(client));
35        for (raw_name, description, schema) in tool_list {
36            let tool_name = format!("mcp__{server_name}__{raw_name}");
37            tools.push(Arc::new(McpDynamicTool {
38                tool_name,
39                tool_description: description,
40                tool_schema: schema,
41                client: shared.clone(),
42                raw_name,
43            }));
44        }
45        tracing::info!("MCP '{server_name}' loaded {} tools", tools.len());
46    }
47    tools
48}