From ac095515635c4dddd2fa42ba5ab9233adcb14ce0 Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 14 Nov 2025 13:01:47 +0800 Subject: [PATCH] feat(frontend): add unified MCP types and API layer for v3.7.0 ## Type Definitions - Update McpServer interface with new apps field (McpApps) - Add McpApps interface for multi-app enable state - Add McpServersMap type for server collections - Mark enabled field as deprecated (use apps instead) - Maintain backward compatibility with optional fields ## API Layer Updates - Add unified MCP management methods to mcpApi: * getAllServers() - retrieve all servers with apps state * upsertUnifiedServer() - add/update server with apps * deleteUnifiedServer() - remove server * toggleApp() - enable/disable server for specific app * syncAllServers() - sync all enabled servers to live configs - Import new McpServersMap type ## Code Organization - Keep all types in src/types.ts (removed duplicate types/mcp.ts) - Follow existing project structure conventions Related: v3.7.0 unified MCP management --- src/lib/api/mcp.ts | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/types.ts | 20 ++++++++++++++++---- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/src/lib/api/mcp.ts b/src/lib/api/mcp.ts index dd8fbb4..bba7f12 100644 --- a/src/lib/api/mcp.ts +++ b/src/lib/api/mcp.ts @@ -3,6 +3,7 @@ import type { McpConfigResponse, McpServer, McpServerSpec, + McpServersMap, McpStatus, } from "@/types"; import type { AppId } from "./types"; @@ -94,4 +95,47 @@ export const mcpApi = { async importFromGemini(): Promise { return await invoke("import_mcp_from_gemini"); }, + + // ======================================================================== + // v3.7.0 新增:统一 MCP 管理 API + // ======================================================================== + + /** + * 获取所有 MCP 服务器(统一结构) + */ + async getAllServers(): Promise { + return await invoke("get_mcp_servers"); + }, + + /** + * 添加或更新 MCP 服务器(统一结构) + */ + async upsertUnifiedServer(server: McpServer): Promise { + return await invoke("upsert_mcp_server", { server }); + }, + + /** + * 删除 MCP 服务器 + */ + async deleteUnifiedServer(id: string): Promise { + return await invoke("delete_mcp_server", { id }); + }, + + /** + * 切换 MCP 服务器在指定应用的启用状态 + */ + async toggleApp( + serverId: string, + app: AppId, + enabled: boolean, + ): Promise { + return await invoke("toggle_mcp_app", { serverId, app, enabled }); + }, + + /** + * 手动同步所有启用的 MCP 服务器到对应的应用 + */ + async syncAllServers(): Promise { + return await invoke("sync_all_mcp_servers"); + }, }; diff --git a/src/types.ts b/src/types.ts index 79bd382..9fb64c8 100644 --- a/src/types.ts +++ b/src/types.ts @@ -125,20 +125,32 @@ export interface McpServerSpec { [key: string]: any; } -// MCP 服务器条目(含元信息) +// v3.7.0: MCP 服务器应用启用状态 +export interface McpApps { + claude: boolean; + codex: boolean; + gemini: boolean; +} + +// MCP 服务器条目(v3.7.0 统一结构) export interface McpServer { id: string; - name?: string; + name: string; + server: McpServerSpec; + apps: McpApps; // v3.7.0: 标记应用到哪些客户端 description?: string; tags?: string[]; homepage?: string; docs?: string; - enabled?: boolean; - server: McpServerSpec; + // 兼容旧字段(v3.6.x 及以前) + enabled?: boolean; // 已废弃,v3.7.0 使用 apps 字段 source?: string; [key: string]: any; } +// MCP 服务器映射(id -> McpServer) +export type McpServersMap = Record; + // MCP 配置状态 export interface McpStatus { userConfigPath: string;