Elffuss BraidHub

kikocis/continue public

main · 1.3 KiBRawPermalink
1import z from "zod";
2import { requestOptionsSchema } from "../../schemas/models.js";
3
4const baseMcpServerSchema = z.object({
5 name: z.string(),
6 faviconUrl: z.string().optional(),
7 sourceFile: z.string().optional(), // Added during loading
8 connectionTimeout: z.number().gt(0).optional(),
9});
10
11const stdioMcpServerSchema = baseMcpServerSchema.extend({
12 command: z.string(),
13 type: z.literal("stdio").optional(),
14 args: z.array(z.string()).optional(),
15 env: z.record(z.string()).optional(),
16 cwd: z.string().optional(),
17});
18export type StdioMcpServer = z.infer<typeof stdioMcpServerSchema>;
19
20const sseOrHttpMcpServerSchema = baseMcpServerSchema.extend({
21 url: z.string(), // .url() fails with e.g. IP addresses
22 type: z.union([z.literal("sse"), z.literal("streamable-http")]).optional(),
23 requestOptions: requestOptionsSchema.optional(),
24});
25export type SseMcpServer = z.infer<typeof sseOrHttpMcpServerSchema>;
26export type HttpMcpServer = z.infer<typeof sseOrHttpMcpServerSchema>;
27
28export const mcpServerSchema = z.union([
29 stdioMcpServerSchema,
30 sseOrHttpMcpServerSchema,
31]);
32export type MCPServer = z.infer<typeof mcpServerSchema>;
33
34export const partialMcpServerSchema = z.union([
35 stdioMcpServerSchema.partial(),
36 sseOrHttpMcpServerSchema.partial(),
37]);
38export type PartialMCPServer = z.infer<typeof partialMcpServerSchema>;