@@ -36,8 +36,42 @@ export type McpConnection = {
3636 transport : StdioClientTransport
3737}
3838
39+ export type McpTransportType = "stdio" | "sse"
40+
41+ export type McpServerConfig = {
42+ transportType : McpTransportType
43+ autoApprove ?: string [ ]
44+ disabled ?: boolean
45+ timeout ?: number
46+ } & (
47+ | {
48+ // Stdio specific
49+ transportType : "stdio"
50+ command : string
51+ args ?: string [ ]
52+ env ?: Record < string , string >
53+ }
54+ | {
55+ // SSE specific
56+ transportType : "sse"
57+ url : string
58+ headers ?: Record < string , string >
59+ withCredentials ?: boolean
60+ }
61+ )
62+
3963const AutoApproveSchema = z . array ( z . string ( ) ) . default ( [ ] )
4064
65+ const SseConfigSchema = z . object ( {
66+ transportType : z . literal ( "sse" ) ,
67+ url : z . string ( ) . url ( ) ,
68+ headers : z . record ( z . string ( ) ) . optional ( ) ,
69+ withCredentials : z . boolean ( ) . optional ( ) . default ( false ) ,
70+ autoApprove : AutoApproveSchema . optional ( ) ,
71+ disabled : z . boolean ( ) . optional ( ) ,
72+ timeout : z . number ( ) . min ( MIN_MCP_TIMEOUT_SECONDS ) . optional ( ) . default ( DEFAULT_MCP_TIMEOUT_SECONDS ) ,
73+ } )
74+
4175const StdioConfigSchema = z . object ( {
4276 command : z . string ( ) ,
4377 args : z . array ( z . string ( ) ) . optional ( ) ,
@@ -47,8 +81,13 @@ const StdioConfigSchema = z.object({
4781 timeout : z . number ( ) . min ( MIN_MCP_TIMEOUT_SECONDS ) . optional ( ) . default ( DEFAULT_MCP_TIMEOUT_SECONDS ) ,
4882} )
4983
84+ const ServerConfigSchema = z . discriminatedUnion ( "transportType" , [
85+ StdioConfigSchema . extend ( { transportType : z . literal ( "stdio" ) } ) ,
86+ SseConfigSchema ,
87+ ] )
88+
5089const McpSettingsSchema = z . object ( {
51- mcpServers : z . record ( StdioConfigSchema ) ,
90+ mcpServers : z . record ( ServerConfigSchema ) ,
5291} )
5392
5493export class McpHub {
0 commit comments