[bug] Gemini API rejects MCP tool schemas with properties/required on non-object types #8388

Closed
opened 2026-02-16 18:09:50 -05:00 by yindo · 1 comment
Owner

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

Originally assigned to: @thdxr on GitHub.

Description

When using MCP servers (e.g., Notion MCP) with Gemini models, the API returns a 400 error because some tool schemas have properties or required fields on non-object types.

Error Message

Bad Request: {
  "error": {
    "code": 400,
    "message": "* GenerateContentRequest.tools[0].function_declarations[80].parameters.properties[data].properties: only allowed for OBJECT type
* GenerateContentRequest.tools[0].function_declarations[80].parameters.properties[data].required: only allowed for OBJECT type",
    "status": "INVALID_ARGUMENT"
  }
}

Steps to Reproduce

  1. Enable Notion MCP (or other MCP servers with similar schema patterns)
  2. Use a Gemini model (e.g., gemini-3-flash-preview)
  3. Send any message
  4. Error occurs on requests with larger tool sets

Expected Behavior

Tool schemas should be sanitized to remove properties and required from non-object types before sending to Gemini API.

Current Behavior

The sanitizeGemini function in transform.ts handles enum conversion and required field filtering, but doesn't strip properties/required from non-object types.

Proposed Solution

Add to sanitizeGemini:

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

Related Issues

Environment

  • opencode version: latest
  • MCP: Notion MCP
  • Model: gemini-3-flash-preview
Originally created by @ChickenBreast-ky on GitHub (Feb 2, 2026). Originally assigned to: @thdxr on GitHub. ## Description When using MCP servers (e.g., Notion MCP) with Gemini models, the API returns a 400 error because some tool schemas have `properties` or `required` fields on non-object types. ## Error Message ``` Bad Request: { "error": { "code": 400, "message": "* GenerateContentRequest.tools[0].function_declarations[80].parameters.properties[data].properties: only allowed for OBJECT type * GenerateContentRequest.tools[0].function_declarations[80].parameters.properties[data].required: only allowed for OBJECT type", "status": "INVALID_ARGUMENT" } } ``` ## Steps to Reproduce 1. Enable Notion MCP (or other MCP servers with similar schema patterns) 2. Use a Gemini model (e.g., gemini-3-flash-preview) 3. Send any message 4. Error occurs on requests with larger tool sets ## Expected Behavior Tool schemas should be sanitized to remove `properties` and `required` from non-object types before sending to Gemini API. ## Current Behavior The `sanitizeGemini` function in `transform.ts` handles enum conversion and required field filtering, but doesn't strip `properties`/`required` from non-object types. ## Proposed Solution Add to `sanitizeGemini`: ```typescript if (result.type && result.type !== "object") { delete result.properties delete result.required } ``` ## Related Issues - Similar to #3140, #8036 ## Environment - opencode version: latest - MCP: Notion MCP - Model: gemini-3-flash-preview
yindo closed this issue 2026-02-16 18:09:50 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Feb 2, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #3140: AI_APICallError with Gemini API - properties/required validation issue
  • #4512: sanitize tools for Gemini 3 compatibility (addresses same root cause)
  • #5832: Error with Gemini models when MCP enabled
  • #8184: Strict JSON Schema validation fail - missing required field in empty tool parameters
  • #9233: LiteLLM Proxy: Vertex AI Gemini models fail for tools with empty parameters

These issues all relate to the same root cause: Gemini API's strict validation that only allows properties and required fields on OBJECT type parameters.

Feel free to ignore if your specific case differs from these.

@github-actions[bot] commented on GitHub (Feb 2, 2026): This issue might be a duplicate of existing issues. Please check: - #3140: AI_APICallError with Gemini API - properties/required validation issue - #4512: sanitize tools for Gemini 3 compatibility (addresses same root cause) - #5832: Error with Gemini models when MCP enabled - #8184: Strict JSON Schema validation fail - missing required field in empty tool parameters - #9233: LiteLLM Proxy: Vertex AI Gemini models fail for tools with empty parameters These issues all relate to the same root cause: Gemini API's strict validation that only allows `properties` and `required` fields on OBJECT type parameters. Feel free to ignore if your specific case differs from these.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8388