feat(mcp): implement unified MCP management for v3.7.0
BREAKING CHANGE: Migrate from app-specific MCP storage to unified structure ## Phase 1: Data Structure Migration - Add McpApps struct with claude/codex/gemini boolean fields - Add McpServer struct for unified server definition - Add migration logic in MultiAppConfig::migrate_mcp_to_unified() - Integrate automatic migration into MultiAppConfig::load() - Support backward compatibility through Optional fields ## Phase 2: Backend Services Refactor - Completely rewrite services/mcp.rs for unified management: * get_all_servers() - retrieve all MCP servers * upsert_server() - add/update unified server * delete_server() - remove server * toggle_app() - enable/disable server for specific app * sync_all_enabled() - sync to all live configs - Add single-server sync functions to mcp.rs: * sync_single_server_to_claude/codex/gemini() * remove_server_from_claude/codex/gemini() - Add read_mcp_servers_map() to claude_mcp.rs and gemini_mcp.rs - Add new Tauri commands to commands/mcp.rs: * get_mcp_servers, upsert_mcp_server, delete_mcp_server * toggle_mcp_app, sync_all_mcp_servers - Register new commands in lib.rs ## Migration Strategy - Detects old structure (mcp.claude/codex/gemini.servers) - Merges into unified mcp.servers with apps markers - Handles conflicts by merging enabled apps - Clears old structures after migration - Saves migrated config automatically ## Known Issues - Old commands still need compatibility layer (WIP) - toml_edit type conversion needs fixing (WIP) - Frontend not yet implemented (Phase 3 pending) Related: v3.6.2 -> v3.7.0
This commit is contained in:
@@ -143,3 +143,53 @@ pub async fn sync_enabled_mcp_to_gemini(state: State<'_, AppState>) -> Result<bo
|
||||
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 管理命令
|
||||
// ============================================================================
|
||||
|
||||
use crate::app_config::McpServer;
|
||||
|
||||
/// 获取所有 MCP 服务器(统一结构)
|
||||
#[tauri::command]
|
||||
pub async fn get_mcp_servers(
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<HashMap<String, McpServer>, String> {
|
||||
McpService::get_all_servers(&state).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// 添加或更新 MCP 服务器
|
||||
#[tauri::command]
|
||||
pub async fn upsert_mcp_server(
|
||||
state: State<'_, AppState>,
|
||||
server: McpServer,
|
||||
) -> Result<(), String> {
|
||||
McpService::upsert_server(&state, server).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// 删除 MCP 服务器
|
||||
#[tauri::command]
|
||||
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())
|
||||
}
|
||||
|
||||
/// 切换 MCP 服务器在指定应用的启用状态
|
||||
#[tauri::command]
|
||||
pub async fn toggle_mcp_app(
|
||||
state: State<'_, AppState>,
|
||||
server_id: String,
|
||||
app: String,
|
||||
enabled: bool,
|
||||
) -> Result<(), String> {
|
||||
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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user