SSE Schema and Types (#2441)
* Types and schemas for SSE connections * changeset
This commit is contained in:
2 files changed
+45
-1
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"claude-dev": minor
|
||||
---
|
||||
|
||||
Added types and schemas for SSE transport MCP connections
|
||||
@@ -36,8 +36,42 @@ export type McpConnection = {
|
||||
transport: StdioClientTransport
|
||||
}
|
||||
|
||||
export type McpTransportType = "stdio" | "sse"
|
||||
|
||||
export type McpServerConfig = {
|
||||
transportType: McpTransportType
|
||||
autoApprove?: string[]
|
||||
disabled?: boolean
|
||||
timeout?: number
|
||||
} & (
|
||||
| {
|
||||
// Stdio specific
|
||||
transportType: "stdio"
|
||||
command: string
|
||||
args?: string[]
|
||||
env?: Record<string, string>
|
||||
}
|
||||
| {
|
||||
// SSE specific
|
||||
transportType: "sse"
|
||||
url: string
|
||||
headers?: Record<string, string>
|
||||
withCredentials?: boolean
|
||||
}
|
||||
)
|
||||
|
||||
const AutoApproveSchema = z.array(z.string()).default([])
|
||||
|
||||
const SseConfigSchema = z.object({
|
||||
transportType: z.literal("sse"),
|
||||
url: z.string().url(),
|
||||
headers: z.record(z.string()).optional(),
|
||||
withCredentials: z.boolean().optional().default(false),
|
||||
autoApprove: AutoApproveSchema.optional(),
|
||||
disabled: z.boolean().optional(),
|
||||
timeout: z.number().min(MIN_MCP_TIMEOUT_SECONDS).optional().default(DEFAULT_MCP_TIMEOUT_SECONDS),
|
||||
})
|
||||
|
||||
const StdioConfigSchema = z.object({
|
||||
command: z.string(),
|
||||
args: z.array(z.string()).optional(),
|
||||
@@ -47,8 +81,13 @@ const StdioConfigSchema = z.object({
|
||||
timeout: z.number().min(MIN_MCP_TIMEOUT_SECONDS).optional().default(DEFAULT_MCP_TIMEOUT_SECONDS),
|
||||
})
|
||||
|
||||
const ServerConfigSchema = z.discriminatedUnion("transportType", [
|
||||
StdioConfigSchema.extend({ transportType: z.literal("stdio") }),
|
||||
SseConfigSchema,
|
||||
])
|
||||
|
||||
const McpSettingsSchema = z.object({
|
||||
mcpServers: z.record(StdioConfigSchema),
|
||||
mcpServers: z.record(ServerConfigSchema),
|
||||
})
|
||||
|
||||
export class McpHub {
|
||||
|
||||
Reference in new issue
Block a user