[bug] Gemini schema sanitization misses properties/required when type is undefined #9079

Open
opened 2026-02-16 18:11:35 -05:00 by yindo · 1 comment
Owner

Originally created by @ChickenBreast-ky on GitHub (Feb 11, 2026).

Originally assigned to: @rekram1-node on GitHub.

Bug Description

sanitizeGemini in transform.ts strips properties and required from non-object types, but misses the case where type is entirely undefined.

This is a follow-up edge case from #11889 / PR #11888.

Root Cause

The current check:

if (result.type && result.type !== "object") {
  delete result.properties
  delete result.required
}

When type is undefined, result.type && ... short-circuits to false, so properties/required are not removed.

Reproduction

MCP tools like Notion MCP define schemas where type is omitted but properties/required are present:

{
  "data": {
    "description": "The data required for updating a page",
    "properties": { "page_id": { "type": "string" } },
    "required": ["page_id"]
  }
}

This causes:

Bad Request: GenerateContentRequest.tools[0].function_declarations[90].parameters.properties[data].properties: only allowed for OBJECT type

Expected Behavior

Schemas with properties/required but no type should be treated as implicit objects (per JSON Schema spec) and have type: "object" added.

Proposed Fix

// Add type "object" for schemas with properties/required but missing type
if (!result.type && (result.properties || result.required)) {
  result.type = "object"
}

Environment

  • OpenCode v1.1.56
  • Notion MCP Server
  • Gemini model (google provider)
Originally created by @ChickenBreast-ky on GitHub (Feb 11, 2026). Originally assigned to: @rekram1-node on GitHub. ## Bug Description `sanitizeGemini` in `transform.ts` strips `properties` and `required` from non-object types, but **misses the case where `type` is entirely undefined**. This is a follow-up edge case from #11889 / PR #11888. ## Root Cause The current check: ```typescript if (result.type && result.type !== "object") { delete result.properties delete result.required } ``` When `type` is `undefined`, `result.type && ...` short-circuits to `false`, so `properties`/`required` are **not removed**. ## Reproduction MCP tools like Notion MCP define schemas where `type` is omitted but `properties`/`required` are present: ```json { "data": { "description": "The data required for updating a page", "properties": { "page_id": { "type": "string" } }, "required": ["page_id"] } } ``` This causes: ``` Bad Request: GenerateContentRequest.tools[0].function_declarations[90].parameters.properties[data].properties: only allowed for OBJECT type ``` ## Expected Behavior Schemas with `properties`/`required` but no `type` should be treated as implicit objects (per JSON Schema spec) and have `type: "object"` added. ## Proposed Fix ```typescript // Add type "object" for schemas with properties/required but missing type if (!result.type && (result.properties || result.required)) { result.type = "object" } ``` ## Environment - OpenCode v1.1.56 - Notion MCP Server - Gemini model (google provider)
Author
Owner

@R44VC0RP commented on GitHub (Feb 11, 2026):

Confirmed — good catch. PR #11888 fixed the case where type is explicitly non-object, but missed when type is undefined.

Your proposed fix is correct. Per JSON Schema spec, a schema with properties/required but no explicit type should be treated as an implicit object. Adding type: "object" in that case fixes the issue.

The relevant code is in packages/opencode/src/provider/transform.ts:796:

if (result.type && result.type !== "object") {
  delete result.properties
  delete result.required
}

Should add before this:

if (!result.type && (result.properties || result.required)) {
  result.type = "object"
}

Feel free to open a PR with tests.

@R44VC0RP commented on GitHub (Feb 11, 2026): Confirmed — good catch. PR #11888 fixed the case where `type` is explicitly non-object, but missed when `type` is `undefined`. Your proposed fix is correct. Per JSON Schema spec, a schema with `properties`/`required` but no explicit `type` should be treated as an implicit object. Adding `type: "object"` in that case fixes the issue. The relevant code is in `packages/opencode/src/provider/transform.ts:796`: ```typescript if (result.type && result.type !== "object") { delete result.properties delete result.required } ``` Should add before this: ```typescript if (!result.type && (result.properties || result.required)) { result.type = "object" } ``` Feel free to open a PR with tests.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#9079