Skip to content

Commit b0de639

Browse files
arafatkatzeCline Evaluation
andauthored
Fix MCP Schema support (RooCodeInc#4166)
Co-authored-by: Cline Evaluation <[email protected]>
1 parent a6c33af commit b0de639

File tree

1 file changed

+48
-26
lines changed

1 file changed

+48
-26
lines changed

src/services/mcp/schemas.ts

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,71 @@ const createServerTypeSchema = () => {
1616
// Stdio config (has command field)
1717
BaseConfigSchema.extend({
1818
type: z.literal("stdio").optional(),
19+
transportType: z.string().optional(), // Support legacy field
1920
command: z.string(),
2021
args: z.array(z.string()).optional(),
2122
cwd: z.string().optional(),
2223
env: z.record(z.string()).optional(),
23-
// Explicitly disallow other types' fields
24-
url: z.undefined().optional(),
25-
headers: z.undefined().optional(),
24+
// Allow other fields for backward compatibility
25+
url: z.string().optional(),
26+
headers: z.record(z.string()).optional(),
2627
})
27-
.transform((data) => ({
28-
...data,
29-
type: "stdio" as const,
30-
}))
31-
.refine((data) => data.type === undefined || data.type === "stdio", { message: TYPE_ERROR_MESSAGE }),
28+
.transform((data) => {
29+
// Support both type and transportType fields
30+
const finalType = data.type || (data.transportType === "stdio" ? "stdio" : undefined) || "stdio"
31+
return {
32+
...data,
33+
type: finalType as "stdio",
34+
// Remove the legacy field after transformation
35+
transportType: undefined,
36+
}
37+
})
38+
.refine((data) => data.type === "stdio", { message: TYPE_ERROR_MESSAGE }),
3239
// SSE config (has url field)
3340
BaseConfigSchema.extend({
3441
type: z.literal("sse").optional(),
42+
transportType: z.string().optional(), // Support legacy field
3543
url: z.string().url("URL must be a valid URL format"),
3644
headers: z.record(z.string()).optional(),
37-
// Explicitly disallow other types' fields
38-
command: z.undefined().optional(),
39-
args: z.undefined().optional(),
40-
env: z.undefined().optional(),
45+
// Allow other fields for backward compatibility
46+
command: z.string().optional(),
47+
args: z.array(z.string()).optional(),
48+
env: z.record(z.string()).optional(),
4149
})
42-
.transform((data) => ({
43-
...data,
44-
type: "sse" as const,
45-
}))
46-
.refine((data) => data.type === undefined || data.type === "sse", { message: TYPE_ERROR_MESSAGE }),
50+
.transform((data) => {
51+
// Support both type and transportType fields
52+
const finalType = data.type || (data.transportType === "sse" ? "sse" : undefined) || "sse"
53+
return {
54+
...data,
55+
type: finalType as "sse",
56+
// Remove the legacy field after transformation
57+
transportType: undefined,
58+
}
59+
})
60+
.refine((data) => data.type === "sse", { message: TYPE_ERROR_MESSAGE }),
4761
// Streamable HTTP config (has url field)
4862
BaseConfigSchema.extend({
4963
type: z.literal("streamableHttp").optional(),
64+
transportType: z.string().optional(), // Support legacy field
5065
url: z.string().url("URL must be a valid URL format"),
5166
headers: z.record(z.string()).optional(),
52-
// Explicitly disallow other types' fields
53-
command: z.undefined().optional(),
54-
args: z.undefined().optional(),
55-
env: z.undefined().optional(),
67+
// Allow other fields for backward compatibility
68+
command: z.string().optional(),
69+
args: z.array(z.string()).optional(),
70+
env: z.record(z.string()).optional(),
5671
})
57-
.transform((data) => ({
58-
...data,
59-
type: "streamableHttp" as const,
60-
}))
61-
.refine((data) => data.type === undefined || data.type === "streamableHttp", {
72+
.transform((data) => {
73+
// Support both type and transportType fields
74+
// Note: legacy transportType was "http" not "streamableHttp"
75+
const finalType = data.type || (data.transportType === "http" ? "streamableHttp" : undefined) || "streamableHttp"
76+
return {
77+
...data,
78+
type: finalType as "streamableHttp",
79+
// Remove the legacy field after transformation
80+
transportType: undefined,
81+
}
82+
})
83+
.refine((data) => data.type === "streamableHttp", {
6284
message: TYPE_ERROR_MESSAGE,
6385
}),
6486
])

0 commit comments

Comments
 (0)