|
1 | | -import { z } from "zod"; |
2 | | - |
3 | | -const AutoApproveSchema: z.ZodDefault<z.ZodArray<z.ZodString, "many">> = z |
4 | | - .array(z.string()).default([]); |
5 | | - |
6 | | -const BaseConfigSchema: z.ZodObject<Record<string, z.ZodTypeAny>> = z.object({ |
7 | | - autoApprove: AutoApproveSchema.optional(), |
8 | | - disabled: z.boolean().optional(), |
9 | | - disabledReason: z.string().optional(), |
10 | | - toolCallTimeout: z.number().optional(), |
11 | | -}); |
12 | | - |
13 | | -export const SseConfigSchema: z.ZodObject<Record<string, z.ZodTypeAny>> = |
14 | | - BaseConfigSchema.extend({ |
15 | | - url: z.string().url(), |
16 | | - transportType: z.literal("sse").optional(), |
17 | | - headers: z.record(z.string()).optional(), |
18 | | - }); |
19 | | - |
20 | | -export const StreamableHTTPSchema: z.ZodObject<Record<string, z.ZodTypeAny>> = |
21 | | - BaseConfigSchema.extend({ |
22 | | - url: z.string().url(), |
23 | | - transportType: z.literal("streamable-http").optional(), |
24 | | - headers: z.record(z.string()).optional(), |
25 | | - }); |
26 | | - |
27 | | -export const StdioConfigSchema: z.ZodObject<Record<string, z.ZodTypeAny>> = |
28 | | - BaseConfigSchema.extend({ |
29 | | - command: z.string(), |
30 | | - args: z.array(z.string()).optional(), |
31 | | - env: z.record(z.string()).optional(), |
32 | | - transportType: z.literal("stdio").optional(), |
33 | | - }); |
34 | | - |
35 | | -export const InMemoryConfigSchema: z.ZodObject<Record<string, z.ZodTypeAny>> = |
36 | | - BaseConfigSchema.extend({ |
37 | | - transportType: z.literal("memory"), |
38 | | - server: z.any(), // Server instance from @modelcontextprotocol/sdk |
39 | | - }); |
40 | | - |
41 | | -export const ServerConfigSchema: z.ZodTypeAny = z.union([ |
42 | | - StdioConfigSchema, |
43 | | - SseConfigSchema, |
44 | | - StreamableHTTPSchema, |
45 | | - InMemoryConfigSchema, |
46 | | -]); |
47 | | - |
48 | | -export const McpSettingsSchema: z.ZodObject<Record<string, z.ZodTypeAny>> = z |
49 | | - .object({ |
50 | | - mcpServers: z.record(ServerConfigSchema), |
51 | | - }); |
52 | | - |
53 | | -// Use the input types (pre-transform) so plain config objects in examples |
54 | | -// that don't include the added `transportType` property still type-check. |
55 | | -// Allow either the raw input (what users write in examples/configs) or the |
56 | | -// transformed/inferred type (which includes the added `transportType` fields). |
| 1 | +// Pure TypeScript type definitions - no Zod dependency needed |
| 2 | +interface BaseServerConfig { |
| 3 | + autoApprove?: string[]; |
| 4 | + disabled?: boolean; |
| 5 | + disabledReason?: string; |
| 6 | + toolCallTimeout?: number; |
| 7 | +} |
| 8 | + |
| 9 | +export interface StdioServerConfig extends BaseServerConfig { |
| 10 | + command: string; |
| 11 | + args?: string[]; |
| 12 | + env?: Record<string, string>; |
| 13 | + transportType?: "stdio"; |
| 14 | +} |
| 15 | + |
| 16 | +export interface SseServerConfig extends BaseServerConfig { |
| 17 | + url: string; |
| 18 | + transportType?: "sse"; |
| 19 | + headers?: Record<string, string>; |
| 20 | +} |
| 21 | + |
| 22 | +export interface StreamableHTTPServerConfig extends BaseServerConfig { |
| 23 | + url: string; |
| 24 | + transportType?: "streamable-http"; |
| 25 | + headers?: Record<string, string>; |
| 26 | +} |
| 27 | + |
| 28 | +export interface InMemoryServerConfig extends BaseServerConfig { |
| 29 | + transportType: "memory"; |
| 30 | + server: any; // Server instance from @modelcontextprotocol/sdk |
| 31 | +} |
| 32 | + |
| 33 | +// Use explicit union type for better type inference |
57 | 34 | export type McpServerConfig = |
58 | | - | z.input<typeof ServerConfigSchema> |
59 | | - | z.infer<typeof ServerConfigSchema>; |
60 | | -export type MCPSetting = |
61 | | - | z.input<typeof McpSettingsSchema> |
62 | | - | z.infer<typeof McpSettingsSchema>; |
| 35 | + | StdioServerConfig |
| 36 | + | SseServerConfig |
| 37 | + | StreamableHTTPServerConfig |
| 38 | + | InMemoryServerConfig; |
| 39 | + |
| 40 | +export type MCPSetting = { |
| 41 | + mcpServers: Record<string, McpServerConfig>; |
| 42 | +}; |
0 commit comments