Skip to content

Commit 2fff1fc

Browse files
authored
chore: error on invalid schema passed to headers and query parameters (#765)
1 parent 313ee7f commit 2fff1fc

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/common/config/configOverrides.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,13 @@ function parseConfigValue(key: keyof typeof UserConfigSchema.shape, value: unkno
118118
throw new Error(`Invalid config key: ${key}`);
119119
}
120120

121-
return fieldSchema.safeParse(value).data;
121+
const result = fieldSchema.safeParse(value);
122+
if (!result.success) {
123+
throw new Error(
124+
`Invalid configuration for the following fields:\n${result.error.issues.map((issue) => `${key} - ${issue.message}`).join("\n")}`
125+
);
126+
}
127+
return result.data;
122128
}
123129

124130
/**

tests/unit/common/config/configOverrides.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ describe("configOverrides", () => {
185185
headers: {
186186
"x-mongodb-mcp-disabled-tools": "tool2",
187187
"x-mongodb-mcp-confirmation-required-tools": "drop-collection",
188-
"x-mongodb-mcp-preview-features": "feature1",
189188
},
190189
};
191190
const result = applyConfigOverrides({ baseConfig: baseConfig as UserConfig, request });
@@ -403,14 +402,15 @@ describe("configOverrides", () => {
403402
});
404403

405404
describe("edge cases", () => {
406-
it("should handle invalid numeric values gracefully", () => {
405+
it("should error with values which do not match the schema", () => {
407406
const request: RequestContext = {
408407
headers: {
409408
"x-mongodb-mcp-idle-timeout-ms": "not-a-number",
410409
},
411410
};
412-
const result = applyConfigOverrides({ baseConfig: baseConfig as UserConfig, request });
413-
expect(result.idleTimeoutMs).toBe(baseConfig.idleTimeoutMs);
411+
expect(() => applyConfigOverrides({ baseConfig: baseConfig as UserConfig, request })).toThrow(
412+
"Invalid configuration for the following fields:\nidleTimeoutMs - Invalid input: expected number, received NaN"
413+
);
414414
});
415415

416416
it("should handle empty string values for arrays", () => {

0 commit comments

Comments
 (0)