From e77eab211605442328fc2b3e04f8662682af2742 Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 13 Oct 2025 23:22:21 +0800 Subject: [PATCH] feat(mcp): auto-sync enabled MCP servers to app config on upsert When upserting an MCP server that is enabled, automatically sync it to the corresponding app's live configuration (Claude or Codex) without requiring manual action. --- src-tauri/src/commands.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 66ca39b..e0012bc 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -850,6 +850,24 @@ pub async fn upsert_mcp_server_in_config( let changed = crate::mcp::upsert_in_config_for(&mut cfg, &app_ty, &id, spec)?; drop(cfg); state.save()?; + + let cfg2 = state + .config + .lock() + .map_err(|e| format!("获取锁失败: {}", e))?; + let should_sync = cfg2 + .mcp_for(&app_ty) + .servers + .get(&id) + .and_then(|entry| entry.get("enabled")) + .and_then(|v| v.as_bool()) + .unwrap_or(false); + if should_sync { + match app_ty { + crate::app_config::AppType::Claude => crate::mcp::sync_enabled_to_claude(&cfg2)?, + crate::app_config::AppType::Codex => crate::mcp::sync_enabled_to_codex(&cfg2)?, + } + } Ok(changed) }