feat(mcp): add front-end API wrappers and types
- Add McpServer and McpStatus types - Add window.api wrappers for MCP commands - Extend vite-env.d.ts global typings for MCP APIs
This commit is contained in:
@@ -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<McpStatus> => {
|
||||
try {
|
||||
return await invoke<McpStatus>("get_claude_mcp_status");
|
||||
} catch (error) {
|
||||
console.error("获取 MCP 状态失败:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
// Claude MCP:读取 mcp.json 文本
|
||||
readClaudeMcpConfig: async (): Promise<string | null> => {
|
||||
try {
|
||||
return await invoke<string | null>("read_claude_mcp_config");
|
||||
} catch (error) {
|
||||
console.error("读取 mcp.json 失败:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
// Claude MCP:设置项目级启用开关
|
||||
setClaudeMcpEnableAllProjects: async (enable: boolean): Promise<boolean> => {
|
||||
try {
|
||||
return await invoke<boolean>("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<string, any>,
|
||||
): Promise<boolean> => {
|
||||
try {
|
||||
return await invoke<boolean>("upsert_claude_mcp_server", { id, spec });
|
||||
} catch (error) {
|
||||
console.error("保存 MCP 服务器失败:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
// Claude MCP:删除服务器定义
|
||||
deleteClaudeMcpServer: async (id: string): Promise<boolean> => {
|
||||
try {
|
||||
return await invoke<boolean>("delete_claude_mcp_server", { id });
|
||||
} catch (error) {
|
||||
console.error("删除 MCP 服务器失败:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
// Claude MCP:校验命令是否在 PATH 中
|
||||
validateMcpCommand: async (cmd: string): Promise<boolean> => {
|
||||
try {
|
||||
return await invoke<boolean>("validate_mcp_command", { cmd });
|
||||
} catch (error) {
|
||||
console.error("校验 MCP 命令失败:", error);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
// ours: 第三方/自定义供应商——测速与端点管理
|
||||
// 第三方/自定义供应商:批量测试端点延迟
|
||||
testApiEndpoints: async (
|
||||
|
||||
20
src/types.ts
20
src/types.ts
@@ -52,3 +52,23 @@ export interface Settings {
|
||||
// Codex 自定义端点列表
|
||||
customEndpointsCodex?: Record<string, CustomEndpoint>;
|
||||
}
|
||||
|
||||
// MCP 服务器定义(宽松:允许扩展字段)
|
||||
export interface McpServer {
|
||||
type: "stdio" | "sse";
|
||||
command: string;
|
||||
args?: string[];
|
||||
env?: Record<string, string>;
|
||||
cwd?: string;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
// MCP 配置状态
|
||||
export interface McpStatus {
|
||||
settingsLocalPath: string;
|
||||
settingsLocalExists: boolean;
|
||||
enableAllProjectMcpServers: boolean;
|
||||
mcpJsonPath: string;
|
||||
mcpJsonExists: boolean;
|
||||
serverCount: number;
|
||||
}
|
||||
|
||||
12
src/vite-env.d.ts
vendored
12
src/vite-env.d.ts
vendored
@@ -1,6 +1,6 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
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<boolean>;
|
||||
isClaudePluginApplied: () => Promise<boolean>;
|
||||
// Claude MCP
|
||||
getClaudeMcpStatus: () => Promise<McpStatus>;
|
||||
readClaudeMcpConfig: () => Promise<string | null>;
|
||||
setClaudeMcpEnableAllProjects: (enable: boolean) => Promise<boolean>;
|
||||
upsertClaudeMcpServer: (
|
||||
id: string,
|
||||
spec: Record<string, any>,
|
||||
) => Promise<boolean>;
|
||||
deleteClaudeMcpServer: (id: string) => Promise<boolean>;
|
||||
validateMcpCommand: (cmd: string) => Promise<boolean>;
|
||||
testApiEndpoints: (
|
||||
urls: string[],
|
||||
options?: { timeoutSecs?: number },
|
||||
|
||||
Reference in New Issue
Block a user