refactor(mcp): complete v3.7.0 cleanup - remove legacy code and warnings

This commit finalizes the v3.7.0 unified MCP architecture migration by
removing all deprecated code paths and eliminating compiler warnings.

Frontend Changes (~950 lines removed):
- Remove deprecated components: McpPanel, McpListItem, McpToggle
- Remove deprecated hook: useMcpActions
- Remove unused API methods: importFrom*, syncEnabledTo*, syncAllServers
- Simplify McpFormModal by removing dual-mode logic (unified/legacy)
- Remove syncOtherSide checkbox and conflict detection
- Clean up unused imports and state variables
- Delete associated test files

Backend Changes (~400 lines cleaned):
- Remove unused Tauri commands: import_mcp_from_*, sync_enabled_mcp_to_*
- Delete unused Gemini MCP functions: get_mcp_status, upsert/delete_mcp_server
- Add #[allow(deprecated)] to compatibility layer commands
- Add #[allow(dead_code)] to legacy helper functions for future migration
- Simplify boolean expression in mcp.rs per Clippy suggestion

API Deprecation:
- Mark legacy APIs with @deprecated JSDoc (getConfig, upsertServerInConfig, etc.)
- Preserve backward compatibility for v3.x, planned removal in v4.0

Verification:
-  Zero TypeScript errors (pnpm typecheck)
-  Zero Clippy warnings (cargo clippy)
-  All code formatted (prettier + cargo fmt)
-  Builds successfully

Total cleanup: ~1,350 lines of code removed/marked
Breaking changes: None (all legacy APIs still functional)
This commit is contained in:
Jason
2025-11-14 22:43:25 +08:00
parent fafca841cb
commit 2f18d6ec00
19 changed files with 100 additions and 1420 deletions

View File

@@ -141,7 +141,10 @@ pub async fn open_app_config_folder(handle: AppHandle) -> Result<bool, String> {
pub async fn get_claude_common_config_snippet(
state: tauri::State<'_, crate::store::AppState>,
) -> Result<Option<String>, String> {
let guard = state.config.read().map_err(|e| format!("读取配置锁失败: {e}"))?;
let guard = state
.config
.read()
.map_err(|e| format!("读取配置锁失败: {e}"))?;
Ok(guard.claude_common_config_snippet.clone())
}

View File

@@ -50,6 +50,7 @@ pub struct McpConfigResponse {
use std::str::FromStr;
#[tauri::command]
#[allow(deprecated)] // 兼容层命令,内部调用已废弃的 Service 方法
pub async fn get_mcp_config(
state: State<'_, AppState>,
app: String,
@@ -101,7 +102,8 @@ pub async fn upsert_mcp_server_in_config(
apps.set_enabled_for(&app_ty, true);
// 尝试从 spec 中提取 name否则使用 id
let name = spec.get("name")
let name = spec
.get("name")
.and_then(|v| v.as_str())
.unwrap_or(&id)
.to_string();
@@ -142,6 +144,7 @@ pub async fn delete_mcp_server_in_config(
/// 设置启用状态并同步到客户端配置
#[tauri::command]
#[allow(deprecated)] // 兼容层命令,内部调用已废弃的 Service 方法
pub async fn set_mcp_enabled(
state: State<'_, AppState>,
app: String,
@@ -152,48 +155,6 @@ pub async fn set_mcp_enabled(
McpService::set_enabled(&state, app_ty, &id, enabled).map_err(|e| e.to_string())
}
/// 手动同步:将启用的 MCP 投影到 ~/.claude.json
#[tauri::command]
pub async fn sync_enabled_mcp_to_claude(state: State<'_, AppState>) -> Result<bool, String> {
McpService::sync_enabled(&state, AppType::Claude)
.map(|_| true)
.map_err(|e| e.to_string())
}
/// 手动同步:将启用的 MCP 投影到 ~/.codex/config.toml
#[tauri::command]
pub async fn sync_enabled_mcp_to_codex(state: State<'_, AppState>) -> Result<bool, String> {
McpService::sync_enabled(&state, AppType::Codex)
.map(|_| true)
.map_err(|e| e.to_string())
}
/// 从 ~/.claude.json 导入 MCP 定义到 config.json
#[tauri::command]
pub async fn import_mcp_from_claude(state: State<'_, AppState>) -> Result<usize, String> {
McpService::import_from_claude(&state).map_err(|e| e.to_string())
}
/// 从 ~/.codex/config.toml 导入 MCP 定义到 config.json
#[tauri::command]
pub async fn import_mcp_from_codex(state: State<'_, AppState>) -> Result<usize, String> {
McpService::import_from_codex(&state).map_err(|e| e.to_string())
}
/// 手动同步:将启用的 MCP 投影到 ~/.gemini/settings.json
#[tauri::command]
pub async fn sync_enabled_mcp_to_gemini(state: State<'_, AppState>) -> Result<bool, String> {
McpService::sync_enabled(&state, AppType::Gemini)
.map(|_| true)
.map_err(|e| e.to_string())
}
/// 从 ~/.gemini/settings.json 导入 MCP 定义到 config.json
#[tauri::command]
pub async fn import_mcp_from_gemini(state: State<'_, AppState>) -> Result<usize, String> {
McpService::import_from_gemini(&state).map_err(|e| e.to_string())
}
// ============================================================================
// v3.7.0 新增:统一 MCP 管理命令
// ============================================================================
@@ -219,10 +180,7 @@ pub async fn upsert_mcp_server(
/// 删除 MCP 服务器
#[tauri::command]
pub async fn delete_mcp_server(
state: State<'_, AppState>,
id: String,
) -> Result<bool, String> {
pub async fn delete_mcp_server(state: State<'_, AppState>, id: String) -> Result<bool, String> {
McpService::delete_server(&state, &id).map_err(|e| e.to_string())
}
@@ -237,9 +195,3 @@ pub async fn toggle_mcp_app(
let app_ty = AppType::from_str(&app).map_err(|e| e.to_string())?;
McpService::toggle_app(&state, &server_id, app_ty, enabled).map_err(|e| e.to_string())
}
/// 手动同步所有启用的 MCP 服务器到对应的应用
#[tauri::command]
pub async fn sync_all_mcp_servers(state: State<'_, AppState>) -> Result<(), String> {
McpService::sync_all_enabled(&state).map_err(|e| e.to_string())
}