diff --git a/src/lib/tauri-api.ts b/src/lib/tauri-api.ts index c040cfc..c78b1bc 100644 --- a/src/lib/tauri-api.ts +++ b/src/lib/tauri-api.ts @@ -1,6 +1,6 @@ import { invoke } from "@tauri-apps/api/core"; import { listen, UnlistenFn } from "@tauri-apps/api/event"; -import { Provider, Settings, CustomEndpoint } from "../types"; +import { Provider, Settings, CustomEndpoint, McpStatus, McpServer } from "../types"; // 应用类型 export type AppType = "claude" | "codex"; @@ -279,6 +279,69 @@ export const tauriAPI = { } }, + // Claude MCP:获取状态(settings.local.json + mcp.json) + getClaudeMcpStatus: async (): Promise => { + try { + return await invoke("get_claude_mcp_status"); + } catch (error) { + console.error("获取 MCP 状态失败:", error); + throw error; + } + }, + + // Claude MCP:读取 mcp.json 文本 + readClaudeMcpConfig: async (): Promise => { + try { + return await invoke("read_claude_mcp_config"); + } catch (error) { + console.error("读取 mcp.json 失败:", error); + throw error; + } + }, + + // Claude MCP:设置项目级启用开关 + setClaudeMcpEnableAllProjects: async (enable: boolean): Promise => { + try { + return await invoke("set_claude_mcp_enable_all_projects", { enable }); + } catch (error) { + console.error("写入 settings.local.json 失败:", error); + throw error; + } + }, + + // Claude MCP:新增/更新服务器定义 + upsertClaudeMcpServer: async ( + id: string, + spec: McpServer | Record, + ): Promise => { + try { + return await invoke("upsert_claude_mcp_server", { id, spec }); + } catch (error) { + console.error("保存 MCP 服务器失败:", error); + throw error; + } + }, + + // Claude MCP:删除服务器定义 + deleteClaudeMcpServer: async (id: string): Promise => { + try { + return await invoke("delete_claude_mcp_server", { id }); + } catch (error) { + console.error("删除 MCP 服务器失败:", error); + throw error; + } + }, + + // Claude MCP:校验命令是否在 PATH 中 + validateMcpCommand: async (cmd: string): Promise => { + try { + return await invoke("validate_mcp_command", { cmd }); + } catch (error) { + console.error("校验 MCP 命令失败:", error); + return false; + } + }, + // ours: 第三方/自定义供应商——测速与端点管理 // 第三方/自定义供应商:批量测试端点延迟 testApiEndpoints: async ( diff --git a/src/types.ts b/src/types.ts index 3a4e0f1..f34294b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -52,3 +52,23 @@ export interface Settings { // Codex 自定义端点列表 customEndpointsCodex?: Record; } + +// MCP 服务器定义(宽松:允许扩展字段) +export interface McpServer { + type: "stdio" | "sse"; + command: string; + args?: string[]; + env?: Record; + cwd?: string; + [key: string]: any; +} + +// MCP 配置状态 +export interface McpStatus { + settingsLocalPath: string; + settingsLocalExists: boolean; + enableAllProjectMcpServers: boolean; + mcpJsonPath: string; + mcpJsonExists: boolean; + serverCount: number; +} diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts index 2a8f5a3..73408e5 100644 --- a/src/vite-env.d.ts +++ b/src/vite-env.d.ts @@ -1,6 +1,6 @@ /// -import { Provider, Settings, CustomEndpoint } from "./types"; +import { Provider, Settings, CustomEndpoint, McpStatus } from "./types"; import { AppType } from "./lib/tauri-api"; import type { UnlistenFn } from "@tauri-apps/api/event"; @@ -61,6 +61,16 @@ declare global { official: boolean; }) => Promise; isClaudePluginApplied: () => Promise; + // Claude MCP + getClaudeMcpStatus: () => Promise; + readClaudeMcpConfig: () => Promise; + setClaudeMcpEnableAllProjects: (enable: boolean) => Promise; + upsertClaudeMcpServer: ( + id: string, + spec: Record, + ) => Promise; + deleteClaudeMcpServer: (id: string) => Promise; + validateMcpCommand: (cmd: string) => Promise; testApiEndpoints: ( urls: string[], options?: { timeoutSecs?: number },