Skip to content

Commit 069b949

Browse files
committed
fix(provider): infer type 'object' for schemas with properties but missing type in Gemini sanitization
Follow-up to anomalyco#11888. sanitizeGemini strips properties/required from non-object types, but misses the case where type is entirely undefined. MCP tools like Notion define schemas with properties/required but no type field, causing Gemini API 400 errors. This fix infers type 'object' when properties or required exist but type is missing, per JSON Schema's implicit object semantics. Fixes anomalyco#13148
1 parent ef5ec5d commit 069b949

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

‎packages/opencode/src/provider/transform.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,12 @@ export namespace ProviderTransform {
792792
}
793793
}
794794

795+
// Infer type "object" when properties/required exist but type is missing
796+
// (common in MCP tool schemas like Notion MCP)
797+
if (!result.type && (result.properties || result.required)) {
798+
result.type = "object"
799+
}
800+
795801
// Remove properties/required from non-object types (Gemini rejects these)
796802
if (result.type && result.type !== "object") {
797803
delete result.properties

‎packages/opencode/test/provider/transform.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,49 @@ describe("ProviderTransform.schema - gemini non-object properties removal", () =
398398
expect(result.properties.data.required).toEqual(["name"])
399399
})
400400

401+
test("infers type 'object' when properties exist but type is missing", () => {
402+
const schema = {
403+
type: "object",
404+
properties: {
405+
data: {
406+
description: "The data",
407+
properties: { page_id: { type: "string" } },
408+
required: ["page_id"],
409+
},
410+
},
411+
} as any
412+
413+
const result = ProviderTransform.schema(geminiModel, schema) as any
414+
415+
expect(result.properties.data.type).toBe("object")
416+
expect(result.properties.data.properties).toBeDefined()
417+
expect(result.properties.data.required).toEqual(["page_id"])
418+
})
419+
420+
test("infers type 'object' for array items with properties but no type", () => {
421+
const schema = {
422+
type: "object",
423+
properties: {
424+
title: {
425+
type: "array",
426+
items: {
427+
properties: {
428+
annotations: {
429+
type: "object",
430+
properties: { bold: { type: "boolean" } },
431+
},
432+
},
433+
},
434+
},
435+
},
436+
} as any
437+
438+
const result = ProviderTransform.schema(geminiModel, schema) as any
439+
440+
expect(result.properties.title.items.type).toBe("object")
441+
expect(result.properties.title.items.properties).toBeDefined()
442+
})
443+
401444
test("does not affect non-gemini providers", () => {
402445
const openaiModel = {
403446
providerID: "openai",

0 commit comments

Comments
 (0)