import { z } from "zod";
const StdioServerConfigSchema = z.object({
transport: z.literal("stdio"),
command: z.string(),
args: z.array(z.string()).optional().default([]),
env: z.record(z.string(), z.string()).optional(),
});
const SseServerConfigSchema = z.object({
transport: z.literal("sse"),
url: z.string().url(),
headers: z.record(z.string(), z.string()).optional(),
});
const StreamableHttpServerConfigSchema = z.object({
transport: z.literal("streamable-http"),
url: z.string().url(),
headers: z.record(z.string(), z.string()).optional(),
});
const ServerConfigSchema = z.discriminatedUnion("transport", [
StdioServerConfigSchema,
SseServerConfigSchema,
StreamableHttpServerConfigSchema,
]);
const AuthEndpointConfigSchema = z.object({
enabled: z.boolean().default(false),
token: z.string().optional(),
});
const AuthConfigSchema = z.object({
default: AuthEndpointConfigSchema.default({ enabled: false }),
endpoints: z.record(z.string(), AuthEndpointConfigSchema).default({}),
});
const ReconnectConfigSchema = z.object({
maxAttempts: z.number().int().min(0).default(3),
initialDelayMs: z.number().int().min(100).default(1000),
maxDelayMs: z.number().int().min(1000).default(30000),
});
const HubConfigSchema = z.object({
port: z.number().int().min(1).max(65535).default(7070),
auth: AuthConfigSchema.default({
default: { enabled: false },
endpoints: {},
}),
reconnect: ReconnectConfigSchema.default({
maxAttempts: 3,
initialDelayMs: 1000,
maxDelayMs: 30000,
}),
idleTimeoutMs: z.number().int().min(0).default(300000),
});
export const AppConfigSchema = z.object({
servers: z.record(z.string(), ServerConfigSchema),
groups: z.record(z.string(), z.array(z.string())).default({}),
hub: HubConfigSchema.default({
port: 7070,
auth: {
default: { enabled: false },
endpoints: {},
},
reconnect: {
maxAttempts: 3,
initialDelayMs: 1000,
maxDelayMs: 30000,
},
idleTimeoutMs: 300000,
}),
});
export type ServerConfig = z.infer<typeof ServerConfigSchema>;
export type StdioServerConfig = z.infer<typeof StdioServerConfigSchema>;
export type SseServerConfig = z.infer<typeof SseServerConfigSchema>;
export type StreamableHttpServerConfig = z.infer<typeof StreamableHttpServerConfigSchema>;
export type AuthConfig = z.infer<typeof AuthConfigSchema>;
export type AuthEndpointConfig = z.infer<typeof AuthEndpointConfigSchema>;
export type ReconnectConfig = z.infer<typeof ReconnectConfigSchema>;
export type HubConfig = z.infer<typeof HubConfigSchema>;
export type AppConfig = z.infer<typeof AppConfigSchema>;