feat: implement MCP UIs

This commit is contained in:
Li Xin
2025-04-24 15:41:33 +08:00
parent d9ffb19950
commit 10b1d63834
32 changed files with 1419 additions and 321 deletions

View File

@@ -0,0 +1,6 @@
// Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
// SPDX-License-Identifier: MIT
export * from "./schema";
export * from "./types";
export * from "./utils";

View File

@@ -0,0 +1,57 @@
// Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
// SPDX-License-Identifier: MIT
import { z } from "zod";
export const MCPConfigSchema = z.object({
mcpServers: z.record(
z.union(
[
z.object({
command: z.string({
message: "`command` must be a string",
}),
args: z
.array(z.string(), {
message: "`args` must be an array of strings",
})
.optional(),
env: z
.record(z.string(), {
message: "`env` must be an object of key-value pairs",
})
.optional(),
}),
z.object({
url: z
.string({
message:
"`url` must be a valid URL starting with http:// or https://",
})
.refine(
(value) => {
try {
const url = new URL(value);
return url.protocol === "http:" || url.protocol === "https:";
} catch {
return false;
}
},
{
message:
"`url` must be a valid URL starting with http:// or https://",
},
),
env: z
.record(z.string(), {
message: "`env` must be an object of key-value pairs",
})
.optional(),
}),
],
{
message: "Invalid server type",
},
),
),
});

43
web/src/core/mcp/types.ts Normal file
View File

@@ -0,0 +1,43 @@
// Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
// SPDX-License-Identifier: MIT
export interface MCPToolMetadata {
name: string;
description: string;
inputSchema?: Record<string, unknown>;
}
export interface GenericMCPServerMetadata<T extends string> {
name: string;
transport: T;
enabled: boolean;
env?: Record<string, string>;
tools: MCPToolMetadata[];
createdAt: number;
updatedAt: number;
}
export interface StdioMCPServerMetadata
extends GenericMCPServerMetadata<"stdio"> {
transport: "stdio";
command: string;
args?: string[];
}
export type SimpleStdioMCPServerMetadata = Omit<
StdioMCPServerMetadata,
"enabled" | "tools" | "createdAt" | "updatedAt"
>;
export interface SSEMCPServerMetadata extends GenericMCPServerMetadata<"sse"> {
transport: "sse";
url: string;
}
export type SimpleSSEMCPServerMetadata = Omit<
SSEMCPServerMetadata,
"enabled" | "tools" | "createdAt" | "updatedAt"
>;
export type MCPServerMetadata = StdioMCPServerMetadata | SSEMCPServerMetadata;
export type SimpleMCPServerMetadata =
| SimpleStdioMCPServerMetadata
| SimpleSSEMCPServerMetadata;

16
web/src/core/mcp/utils.ts Normal file
View File

@@ -0,0 +1,16 @@
// Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
// SPDX-License-Identifier: MIT
import { useSettingsStore } from "../store";
export function findMCPTool(name: string) {
const mcpServers = useSettingsStore.getState().mcp.servers;
for (const server of mcpServers) {
for (const tool of server.tools) {
if (tool.name === name) {
return tool;
}
}
}
return null;
}