Compare commits

...
Author SHA1 Message Date
Cline Evaluation c20a181366 Fix MCP Schema support 2025-06-11 13:49:38 +01:00
+48 -26
View File
@@ -16,49 +16,71 @@ const createServerTypeSchema = () => {
// Stdio config (has command field)
BaseConfigSchema.extend({
type: z.literal("stdio").optional(),
transportType: z.string().optional(), // Support legacy field
command: z.string(),
args: z.array(z.string()).optional(),
cwd: z.string().optional(),
env: z.record(z.string()).optional(),
// Explicitly disallow other types' fields
url: z.undefined().optional(),
headers: z.undefined().optional(),
// Allow other fields for backward compatibility
url: z.string().optional(),
headers: z.record(z.string()).optional(),
})
.transform((data) => ({
...data,
type: "stdio" as const,
}))
.refine((data) => data.type === undefined || data.type === "stdio", { message: TYPE_ERROR_MESSAGE }),
.transform((data) => {
// Support both type and transportType fields
const finalType = data.type || (data.transportType === "stdio" ? "stdio" : undefined) || "stdio"
return {
...data,
type: finalType as "stdio",
// Remove the legacy field after transformation
transportType: undefined,
}
})
.refine((data) => data.type === "stdio", { message: TYPE_ERROR_MESSAGE }),
// SSE config (has url field)
BaseConfigSchema.extend({
type: z.literal("sse").optional(),
transportType: z.string().optional(), // Support legacy field
url: z.string().url("URL must be a valid URL format"),
headers: z.record(z.string()).optional(),
// Explicitly disallow other types' fields
command: z.undefined().optional(),
args: z.undefined().optional(),
env: z.undefined().optional(),
// Allow other fields for backward compatibility
command: z.string().optional(),
args: z.array(z.string()).optional(),
env: z.record(z.string()).optional(),
})
.transform((data) => ({
...data,
type: "sse" as const,
}))
.refine((data) => data.type === undefined || data.type === "sse", { message: TYPE_ERROR_MESSAGE }),
.transform((data) => {
// Support both type and transportType fields
const finalType = data.type || (data.transportType === "sse" ? "sse" : undefined) || "sse"
return {
...data,
type: finalType as "sse",
// Remove the legacy field after transformation
transportType: undefined,
}
})
.refine((data) => data.type === "sse", { message: TYPE_ERROR_MESSAGE }),
// Streamable HTTP config (has url field)
BaseConfigSchema.extend({
type: z.literal("streamableHttp").optional(),
transportType: z.string().optional(), // Support legacy field
url: z.string().url("URL must be a valid URL format"),
headers: z.record(z.string()).optional(),
// Explicitly disallow other types' fields
command: z.undefined().optional(),
args: z.undefined().optional(),
env: z.undefined().optional(),
// Allow other fields for backward compatibility
command: z.string().optional(),
args: z.array(z.string()).optional(),
env: z.record(z.string()).optional(),
})
.transform((data) => ({
...data,
type: "streamableHttp" as const,
}))
.refine((data) => data.type === undefined || data.type === "streamableHttp", {
.transform((data) => {
// Support both type and transportType fields
// Note: legacy transportType was "http" not "streamableHttp"
const finalType = data.type || (data.transportType === "http" ? "streamableHttp" : undefined) || "streamableHttp"
return {
...data,
type: finalType as "streamableHttp",
// Remove the legacy field after transformation
transportType: undefined,
}
})
.refine((data) => data.type === "streamableHttp", {
message: TYPE_ERROR_MESSAGE,
}),
])