|
| 1 | +// Client-side MCP types - separated from server implementation |
| 2 | +import { z } from 'zod'; |
| 3 | +import type { ToolSet } from 'ai'; |
| 4 | + |
| 5 | +export const stdioServerConfigSchema = z |
| 6 | + .object({ |
| 7 | + type: z.enum(['stdio']).optional(), |
| 8 | + command: z.string().min(1, 'Command cannot be empty'), |
| 9 | + args: z.array(z.string()).optional(), |
| 10 | + cwd: z.string().optional(), |
| 11 | + env: z.record(z.string()).optional(), |
| 12 | + }) |
| 13 | + .transform((data) => ({ |
| 14 | + ...data, |
| 15 | + type: 'stdio' as const, |
| 16 | + })); |
| 17 | + |
| 18 | +export const sseServerConfigSchema = z |
| 19 | + .object({ |
| 20 | + type: z.enum(['sse']).optional(), |
| 21 | + url: z.string().url('URL must be a valid URL format'), |
| 22 | + headers: z.record(z.string()).optional(), |
| 23 | + }) |
| 24 | + .transform((data) => ({ |
| 25 | + ...data, |
| 26 | + type: 'sse' as const, |
| 27 | + })); |
| 28 | + |
| 29 | +export const streamableHTTPServerConfigSchema = z |
| 30 | + .object({ |
| 31 | + type: z.enum(['streamable-http']).optional(), |
| 32 | + url: z.string().url('URL must be a valid URL format'), |
| 33 | + headers: z.record(z.string()).optional(), |
| 34 | + }) |
| 35 | + .transform((data) => ({ |
| 36 | + ...data, |
| 37 | + type: 'streamable-http' as const, |
| 38 | + })); |
| 39 | + |
| 40 | +export const mcpServerConfigSchema = z.union([ |
| 41 | + stdioServerConfigSchema, |
| 42 | + sseServerConfigSchema, |
| 43 | + streamableHTTPServerConfigSchema, |
| 44 | +]); |
| 45 | + |
| 46 | +export const mcpConfigSchema = z.object({ |
| 47 | + mcpServers: z.record(z.string(), mcpServerConfigSchema), |
| 48 | +}); |
| 49 | + |
| 50 | +export type MCPServerConfig = z.infer<typeof mcpServerConfigSchema>; |
| 51 | +export type MCPConfig = z.infer<typeof mcpConfigSchema>; |
| 52 | + |
| 53 | +// Server status types |
| 54 | +export type MCPServerAvailable = { |
| 55 | + status: 'available'; |
| 56 | + tools: ToolSet; |
| 57 | + config: MCPServerConfig; |
| 58 | +}; |
| 59 | + |
| 60 | +export type MCPServerUnavailable = { |
| 61 | + status: 'unavailable'; |
| 62 | + error: string; |
| 63 | + config: MCPServerConfig; |
| 64 | +}; |
| 65 | + |
| 66 | +export type MCPServerConnecting = { |
| 67 | + status: 'connecting'; |
| 68 | + config: MCPServerConfig; |
| 69 | + retryCount: number; |
| 70 | + lastAttempt: Date; |
| 71 | +}; |
| 72 | + |
| 73 | +export type MCPServer = MCPServerAvailable | MCPServerUnavailable | MCPServerConnecting; |
| 74 | + |
| 75 | +export type MCPServerTools = Record<string, MCPServer>; |
0 commit comments