Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix: preserve full validation for annotated schema dependencies

Afloat569a4646860b
diff --git a/server/mcp-schema-dependencies.test.ts b/server/mcp-schema-dependencies.test.ts
new file mode 100644
index 0000000000..3d747737f9
--- /dev/null
+++ b/server/mcp-schema-dependencies.test.ts
@@ -0,0 +1,41 @@
+import { describe, expect, it } from "vitest";
+
+import { compileServerToolSchema, serverToolValidator } from "./mcp-schema-validator.ts";
+
+const schema = {
+ $schema: "http://json-schema.org/draft-07/schema#", type: "object",
+ properties: { country: { type: "string" }, postal: { type: "string" } },
+ dependencies: {
+ country: {
+ properties: { postal: { type: "string", pattern: "^[0-9]{5}$", example: "12345" } },
+ required: ["postal"],
+ },
+ postal: ["country"],
+ },
+};
+
+describe("annotations inside draft-07 schema dependencies", () => {
+ it("compiles the schema after removing non-asserting generator hints", () => {
+ const validate = compileServerToolSchema(schema);
+ expect(validate({ country: "US", postal: "12345" })).toBe(true);
+ expect(validate({ country: "US", postal: "letters" })).toBe(false);
+ expect(validate({ country: "US" })).toBe(false);
+ expect(validate({ postal: "12345" })).toBe(false);
+ expect(validate({})).toBe(true);
+ });
+
+ it("keeps the server tool on full validation instead of dropping its pattern", () => {
+ const checked = serverToolValidator(schema);
+ expect(checked.check).toBe("full");
+ expect(checked.validate({ country: "US", postal: "letters" })).toBe(false);
+ });
+
+ it("does not remove dependency property names that also name annotations", () => {
+ const validate = compileServerToolSchema({
+ type: "object", properties: { example: { type: "boolean" }, detail: { type: "string" } },
+ dependencies: { example: { required: ["detail"], "x-generator-note": "required together" } },
+ });
+ expect(validate({ example: true })).toBe(false);
+ expect(validate({ example: true, detail: "present" })).toBe(true);
+ });
+});
diff --git a/server/mcp-schema-validator.ts b/server/mcp-schema-validator.ts
index 99f9defbce..e94341eac2 100644
--- a/server/mcp-schema-validator.ts
+++ b/server/mcp-schema-validator.ts
@@ -89,7 +89,7 @@ export function serverToolValidator(schema: Record<string, unknown>): { validate
* Code's editor hints. Vendor `x-` extensions too, except the two compileToolSchema checks. */
const NON_ASSERTIONS = new Set(["example", "discriminator", "externalDocs", "xml", "markdownDescription", "markdownEnumDescriptions", "enumDescriptions"]);
const CHECKED_EXTENSIONS = new Set(["x-mcp-header", "x-google-enum-descriptions"]);
-const SCHEMA_KEYWORD_MAPS = ["properties", "$defs", "definitions", "dependentSchemas", "patternProperties"];
+const SCHEMA_KEYWORD_MAPS = ["properties", "$defs", "definitions", "dependencies", "dependentSchemas", "patternProperties"];
function localRefsOnly(schema: unknown, depth = 0): boolean {
if (Array.isArray(schema)) return schema.every((child) => localRefsOnly(child, depth + 1));