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:
@@ -231,6 +231,27 @@ pub fn validate_command_in_path(cmd: &str) -> Result<bool, AppError> {
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
/// 读取 ~/.claude.json 中的 mcpServers 映射
|
||||
pub fn read_mcp_servers_map() -> Result<std::collections::HashMap<String, Value>, AppError> {
|
||||
let path = user_config_path();
|
||||
if !path.exists() {
|
||||
return Ok(std::collections::HashMap::new());
|
||||
}
|
||||
|
||||
let root = read_json_value(&path)?;
|
||||
let servers = root
|
||||
.get("mcpServers")
|
||||
.and_then(|v| v.as_object())
|
||||
.map(|obj| {
|
||||
obj.iter()
|
||||
.map(|(k, v)| (k.clone(), v.clone()))
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
Ok(servers)
|
||||
}
|
||||
|
||||
/// 将给定的启用 MCP 服务器映射写入到用户级 ~/.claude.json 的 mcpServers 字段
|
||||
/// 仅覆盖 mcpServers,其他字段保持不变
|
||||
pub fn set_mcp_servers_map(
|
||||
|
||||
Reference in New Issue
Block a user