GeezerVison is showing github.com — fix(server): MCP tools no longer advertise non-string enums that Gemi… · ChrisjanWust/t3code@9504f65
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/mcp/advertisedJsonSchema.test.ts +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,6 +3,7 @@ import * as Schema from "effect/Schema"; | 3 | 3 | import { Tool } from "effect/ai"; | 4 | 4 |
| 5 | 5 | import { advertisedJsonSchema } from "./advertisedJsonSchema.ts"; | | 6 | +import { ThemeToolkit } from "./toolkits/theme/tools.ts"; | 6 | 7 |
| 7 | 8 | it("drops JSON noise, merges tagged unions, and keeps null where it is required", () => { | 8 | 9 | const Every = Schema.Struct({ ms: Schema.Int }); | @@ -43,3 +44,18 @@ it("drops JSON noise, merges tagged unions, and keeps null where it is required" | 43 | 44 | required: ["beforeRunId", "every"], | 44 | 45 | }); | 45 | 46 | }); | | 47 | + | | 48 | +it("advertises only string enum values, which Gemini requires", () => { | | 49 | + const enumValues: Array<unknown> = []; | | 50 | + const collect = (node: unknown): void => { | | 51 | + if (Array.isArray(node)) return node.forEach(collect); | | 52 | + if (typeof node !== "object" || node === null) return; | | 53 | + for (const [key, value] of Object.entries(node)) { | | 54 | + if (key === "enum" && Array.isArray(value)) enumValues.push(...value); | | 55 | + else collect(value); | | 56 | + } | | 57 | + }; | | 58 | + collect(advertisedJsonSchema(ThemeToolkit.tools.t3_theme_set)); | | 59 | + | | 60 | + expect(enumValues.filter((value) => typeof value !== "string")).toEqual([]); | | 61 | +}); |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/mcp/advertisedJsonSchema.ts +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -21,6 +21,10 @@ const SAFE_INTEGER_BOUNDS: Record<string, number> = { | 21 | 21 | minimum: Number.MIN_SAFE_INTEGER, | 22 | 22 | }; | 23 | 23 |
| | 24 | +// Gemini rejects function declarations whose enums hold anything but strings. | | 25 | +const isNonStringEnum = (key: string, value: Json) => | | 26 | + key === "enum" && Array.isArray(value) && value.some((item) => typeof item !== "string"); | | 27 | + | 24 | 28 | const tagOf = (branch: JsonObject, key: string): Json => { | 25 | 29 | const property = Predicate.isObject(branch.properties) ? branch.properties[key] : undefined; | 26 | 30 | return Predicate.isObject(property) && Array.isArray(property.enum) && property.enum.length === 1 | @@ -75,6 +79,7 @@ const compact = (schema: Json, optional: boolean): Json => { | 75 | 79 | for (const [key, value] of Object.entries(schema)) { | 76 | 80 | if (key === "additionalProperties" && value === true) continue; | 77 | 81 | if (SAFE_INTEGER_BOUNDS[key] === value) continue; | | 82 | + if (isNonStringEnum(key, value)) continue; | 78 | 83 | result[key] = | 79 | 84 | key === "properties" && Predicate.isObject(value) | 80 | 85 | ? Object.fromEntries( | |
Collapse file Copy file name to clipboard +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | { | 2 | 2 | "claudeSystemAppendBytes": 5930, | 3 | 3 | "codexAdditionalContextBytes": 7324, | 4 | | - "mcpToolListJsonBytes": 49749 | | 4 | + "mcpToolListJsonBytes": 49738 | 5 | 5 | } |
|