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
This commit is contained in:
Jason
2025-11-14 13:01:47 +08:00
parent 7ae2a9f556
commit ac09551563
2 changed files with 60 additions and 4 deletions

View File

@@ -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<number> {
return await invoke("import_mcp_from_gemini");
},
// ========================================================================
// v3.7.0 新增:统一 MCP 管理 API
// ========================================================================
/**
* 获取所有 MCP 服务器(统一结构)
*/
async getAllServers(): Promise<McpServersMap> {
return await invoke("get_mcp_servers");
},
/**
* 添加或更新 MCP 服务器(统一结构)
*/
async upsertUnifiedServer(server: McpServer): Promise<void> {
return await invoke("upsert_mcp_server", { server });
},
/**
* 删除 MCP 服务器
*/
async deleteUnifiedServer(id: string): Promise<boolean> {
return await invoke("delete_mcp_server", { id });
},
/**
* 切换 MCP 服务器在指定应用的启用状态
*/
async toggleApp(
serverId: string,
app: AppId,
enabled: boolean,
): Promise<void> {
return await invoke("toggle_mcp_app", { serverId, app, enabled });
},
/**
* 手动同步所有启用的 MCP 服务器到对应的应用
*/
async syncAllServers(): Promise<void> {
return await invoke("sync_all_mcp_servers");
},
};