mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-25 23:14:46 +08:00
feat: implement MCP UIs
This commit is contained in:
6
web/src/core/mcp/index.ts
Normal file
6
web/src/core/mcp/index.ts
Normal 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";
|
||||
57
web/src/core/mcp/schema.ts
Normal file
57
web/src/core/mcp/schema.ts
Normal 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
43
web/src/core/mcp/types.ts
Normal 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
16
web/src/core/mcp/utils.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user