Skip to content

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

@ChickenBreast-ky

Description

@ChickenBreast-ky

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions