fix(provider): sync MCP config for all apps on provider switch

Previously, only Codex provider switches triggered MCP synchronization,
which could cause MCP configuration loss when switching Claude or Gemini
providers.

Changes:
- Enable MCP sync for all app types (Claude, Codex, Gemini) during provider switch
- Migrate to v3.7.0 unified MCP sync mechanism using McpService::sync_all_enabled()
- Replace app-specific sync_enabled_to_codex() with unified sync for all apps
- Remove unused mcp module import

This ensures MCP servers remain properly configured across all applications
after provider switches, preventing configuration loss.
This commit is contained in:
Jason
2025-11-17 23:17:21 +08:00
parent 67bd8f5c11
commit a00eb764f7

View File

@@ -11,7 +11,6 @@ use crate::config::{
write_json_file, write_text_file,
};
use crate::error::AppError;
use crate::mcp;
use crate::provider::{Provider, ProviderMeta, UsageData, UsageResult};
use crate::settings::{self, CustomEndpoint};
use crate::store::AppState;
@@ -547,11 +546,9 @@ impl ProviderService {
fn apply_post_commit(state: &AppState, action: &PostCommitAction) -> Result<(), AppError> {
Self::write_live_snapshot(&action.app_type, &action.provider)?;
if action.sync_mcp {
let config_clone = {
let guard = state.config.read().map_err(AppError::from)?;
guard.clone()
};
mcp::sync_enabled_to_codex(&config_clone)?;
// 使用 v3.7.0 统一的 MCP 同步机制,支持所有应用
use crate::services::mcp::McpService;
McpService::sync_all_enabled(state)?;
}
if action.refresh_snapshot {
Self::refresh_provider_snapshot(state, &action.app_type, &action.provider.id)?;
@@ -1248,7 +1245,7 @@ impl ProviderService {
app_type: app_type_clone.clone(),
provider,
backup,
sync_mcp: matches!(app_type_clone, AppType::Codex),
sync_mcp: true, // v3.7.0: 所有应用切换时都同步 MCP防止配置丢失
refresh_snapshot: true,
};