diff --git a/src-tauri/src/mcp_server.rs b/src-tauri/src/mcp_server.rs index 046d19d..bf19c34 100644 --- a/src-tauri/src/mcp_server.rs +++ b/src-tauri/src/mcp_server.rs @@ -539,6 +539,34 @@ fn tools_list_result() -> Value { }, "required": ["project_id"] } + }, + { + "name": "setup_webhook", + "description": "为项目重新注册 Gitea webhook(订阅 push + pull_request 事件)。等价于炼境 UI「重设」按钮。导入新项目后、或需要更新事件订阅时调用。", + "inputSchema": { + "type": "object", + "properties": { + "project_id": { + "type": "string", + "description": "项目 workspace ID(来自 list_group_projects 的返回结果)" + } + }, + "required": ["project_id"] + } + }, + { + "name": "inject_mcp", + "description": "向项目的 .claude/settings.json 注入炼境 MCP 配置,同时写入 bypassPermissions 和 liangjing.json。等价于炼境 UI「注入 MCP」按钮。导入新项目后或炼境重启后调用。", + "inputSchema": { + "type": "object", + "properties": { + "project_id": { + "type": "string", + "description": "项目 workspace ID(来自 list_group_projects 的返回结果)" + } + }, + "required": ["project_id"] + } } ] }) @@ -623,6 +651,29 @@ async fn tools_call(group_id: &str, params: Option<&Value>) -> Value { let body = args.get("body").and_then(|v| v.as_str()).unwrap_or(""); crate::commands::gitea::gitea_api_create_pull_request(pid, head, base, title, body) } + "setup_webhook" => { + let pid = args.get("project_id").and_then(|v| v.as_str()).unwrap_or(""); + let port = read_port(); + let callback_base = format!("http://127.0.0.1:{}", port); + crate::commands::gitea::gitea_setup_webhook(pid.to_string(), callback_base) + .map(|repo| format!( + "webhook 注册成功:{}/{} hook_id={}", + repo.gitea_owner, repo.gitea_repo_name, + repo.webhook_id.map(|id| id.to_string()).unwrap_or_default() + )) + } + "inject_mcp" => { + let pid = args.get("project_id").and_then(|v| v.as_str()).unwrap_or(""); + let conn = db::pool().get().map_err(|e| e.to_string())?; + let group_id: String = conn.query_row( + "SELECT group_id FROM project_group_map WHERE project_id = ?1 LIMIT 1", + rusqlite::params![pid], + |r| r.get(0), + ).map_err(|_| format!("项目 {} 未加入任何产品组", pid))?; + drop(conn); + crate::mcp_inject::inject_project_mcp(pid, &group_id) + .map(|_| format!("MCP 注入成功:project_id={} group_id={}", pid, group_id)) + } _ => Err(format!("未知工具: {}", tool_name)), }) .await;