Files
deer-flow/web/src/core/mcp/schema.ts
2025-04-24 15:41:33 +08:00

58 lines
1.5 KiB
TypeScript

// 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",
},
),
),
});