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:
@@ -3,6 +3,7 @@ import type {
|
|||||||
McpConfigResponse,
|
McpConfigResponse,
|
||||||
McpServer,
|
McpServer,
|
||||||
McpServerSpec,
|
McpServerSpec,
|
||||||
|
McpServersMap,
|
||||||
McpStatus,
|
McpStatus,
|
||||||
} from "@/types";
|
} from "@/types";
|
||||||
import type { AppId } from "./types";
|
import type { AppId } from "./types";
|
||||||
@@ -94,4 +95,47 @@ export const mcpApi = {
|
|||||||
async importFromGemini(): Promise<number> {
|
async importFromGemini(): Promise<number> {
|
||||||
return await invoke("import_mcp_from_gemini");
|
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");
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
20
src/types.ts
20
src/types.ts
@@ -125,20 +125,32 @@ export interface McpServerSpec {
|
|||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
// MCP 服务器条目(含元信息)
|
// v3.7.0: MCP 服务器应用启用状态
|
||||||
|
export interface McpApps {
|
||||||
|
claude: boolean;
|
||||||
|
codex: boolean;
|
||||||
|
gemini: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
// MCP 服务器条目(v3.7.0 统一结构)
|
||||||
export interface McpServer {
|
export interface McpServer {
|
||||||
id: string;
|
id: string;
|
||||||
name?: string;
|
name: string;
|
||||||
|
server: McpServerSpec;
|
||||||
|
apps: McpApps; // v3.7.0: 标记应用到哪些客户端
|
||||||
description?: string;
|
description?: string;
|
||||||
tags?: string[];
|
tags?: string[];
|
||||||
homepage?: string;
|
homepage?: string;
|
||||||
docs?: string;
|
docs?: string;
|
||||||
enabled?: boolean;
|
// 兼容旧字段(v3.6.x 及以前)
|
||||||
server: McpServerSpec;
|
enabled?: boolean; // 已废弃,v3.7.0 使用 apps 字段
|
||||||
source?: string;
|
source?: string;
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MCP 服务器映射(id -> McpServer)
|
||||||
|
export type McpServersMap = Record<string, McpServer>;
|
||||||
|
|
||||||
// MCP 配置状态
|
// MCP 配置状态
|
||||||
export interface McpStatus {
|
export interface McpStatus {
|
||||||
userConfigPath: string;
|
userConfigPath: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user