feat(mcp): use project config as SSOT and sync enabled servers to ~/.claude.json
- Add McpConfig to MultiAppConfig and persist MCP servers in ~/.cc-switch/config.json - Add Tauri commands: get_mcp_config, upsert_mcp_server_in_config, delete_mcp_server_in_config, set_mcp_enabled, sync_enabled_mcp_to_claude, import_mcp_from_claude - Only write enabled MCPs to ~/.claude.json (mcpServers) and strip UI-only fields (enabled/source) - Frontend: update API wrappers and MCP panel to read/write via config.json; seed presets on first open; import from ~/.claude.json - Fix warnings (remove unused mut, dead code) - Verified with cargo check and pnpm typecheck
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
CustomEndpoint,
|
||||
McpStatus,
|
||||
McpServer,
|
||||
McpConfigResponse,
|
||||
} from "../types";
|
||||
|
||||
// 应用类型
|
||||
@@ -338,6 +339,64 @@ export const tauriAPI = {
|
||||
}
|
||||
},
|
||||
|
||||
// 新:config.json 为 SSOT 的 MCP API
|
||||
getMcpConfig: async (): Promise<McpConfigResponse> => {
|
||||
try {
|
||||
return await invoke<McpConfigResponse>("get_mcp_config");
|
||||
} catch (error) {
|
||||
console.error("获取 MCP 配置失败:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
upsertMcpServerInConfig: async (
|
||||
id: string,
|
||||
spec: McpServer | Record<string, any>,
|
||||
): Promise<boolean> => {
|
||||
try {
|
||||
return await invoke<boolean>("upsert_mcp_server_in_config", { id, spec });
|
||||
} catch (error) {
|
||||
console.error("写入 MCP(config.json)失败:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
deleteMcpServerInConfig: async (id: string): Promise<boolean> => {
|
||||
try {
|
||||
return await invoke<boolean>("delete_mcp_server_in_config", { id });
|
||||
} catch (error) {
|
||||
console.error("删除 MCP(config.json)失败:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
setMcpEnabled: async (id: string, enabled: boolean): Promise<boolean> => {
|
||||
try {
|
||||
return await invoke<boolean>("set_mcp_enabled", { id, enabled });
|
||||
} catch (error) {
|
||||
console.error("设置 MCP 启用状态失败:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
syncEnabledMcpToClaude: async (): Promise<boolean> => {
|
||||
try {
|
||||
return await invoke<boolean>("sync_enabled_mcp_to_claude");
|
||||
} catch (error) {
|
||||
console.error("同步启用 MCP 到 .claude.json 失败:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
importMcpFromClaude: async (): Promise<number> => {
|
||||
try {
|
||||
return await invoke<number>("import_mcp_from_claude");
|
||||
} catch (error) {
|
||||
console.error("从 ~/.claude.json 导入 MCP 失败:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
// ours: 第三方/自定义供应商——测速与端点管理
|
||||
// 第三方/自定义供应商:批量测试端点延迟
|
||||
testApiEndpoints: async (
|
||||
|
||||
Reference in New Issue
Block a user