UNPKG

touchdesigner-mcp-server

Version:
76 lines (75 loc) 2.01 kB
import { z } from "zod"; /** * Zod schema for SessionConfig validation */ const SessionConfigSchema = z .object({ cleanupInterval: z.number().int().positive().optional(), enabled: z.boolean(), ttl: z.number().int().positive().optional(), }) .strict(); /** * Zod schema for StdioTransportConfig validation */ const StdioTransportConfigSchema = z .object({ type: z.literal("stdio"), }) .strict(); /** * Zod schema for StreamableHttpTransportConfig validation */ const StreamableHttpTransportConfigSchema = z .object({ endpoint: z .string() .min(1, "Endpoint cannot be empty") .regex(/^\//, "Endpoint must start with /"), host: z.string().min(1, "Host cannot be empty"), port: z .number() .int() .positive() .min(1) .max(65535, "Port must be between 1 and 65535"), retryInterval: z.number().int().positive().optional(), sessionConfig: SessionConfigSchema.optional(), type: z.literal("streamable-http"), }) .strict(); /** * Zod schema for TransportConfig validation (discriminated union) */ export const TransportConfigSchema = z.discriminatedUnion("type", [ StdioTransportConfigSchema, StreamableHttpTransportConfigSchema, ]); /** * Type guard to check if config is StdioTransportConfig */ export function isStdioTransportConfig(config) { return config.type === "stdio"; } /** * Type guard to check if config is StreamableHttpTransportConfig */ export function isStreamableHttpTransportConfig(config) { return config.type === "streamable-http"; } /** * Default values for SessionConfig */ export const DEFAULT_SESSION_CONFIG = { cleanupInterval: 5 * 60 * 1000, // 5 minutes enabled: true, ttl: 60 * 60 * 1000, // 1 hour }; /** * Default values for StreamableHttpTransportConfig (excluding required fields) */ export const DEFAULT_HTTP_CONFIG = { endpoint: "/mcp", host: "127.0.0.1", sessionConfig: DEFAULT_SESSION_CONFIG, };