Gemini API rejects JSON Schema containing $ref references #8609

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

Originally created by @high726 on GitHub (Feb 5, 2026).

Originally assigned to: @thdxr on GitHub.

Problem

Gemini API rejects schemas containing $ref alongside other fields, causing errors like:

$ref 'QuestionOption' was set alongside unsupported fields. 
If a schema node has $ref set, then only description and default can be set alongside it

This happens when MCP tools use JSON Schema with $ref references to $defs/definitions.

Expected Behavior

OpenCode should expand $ref references before sending schemas to Gemini API.

Related Issues

Related PRs

  • #11968 - Applies schema transformation to MCP tools (complementary fix)
Originally created by @high726 on GitHub (Feb 5, 2026). Originally assigned to: @thdxr on GitHub. ## Problem Gemini API rejects schemas containing `$ref` alongside other fields, causing errors like: ``` $ref 'QuestionOption' was set alongside unsupported fields. If a schema node has $ref set, then only description and default can be set alongside it ``` This happens when MCP tools use JSON Schema with `$ref` references to `$defs`/`definitions`. ## Expected Behavior OpenCode should expand `$ref` references before sending schemas to Gemini API. ## Related Issues - google-gemini/gemini-cli#13326 - Gemini API rejects MCP tool schemas with `$defs` references - #5832 - Error with Gemini models when MCP enabled - #8417 - Gemini Bad Request with Github Copilot ## Related PRs - #11968 - Applies schema transformation to MCP tools (complementary fix)
yindo added the zen label 2026-02-16 18:10:23 -05:00
Author
Owner

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

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

  • #5832: Error with Gemini models when MCP enabled
  • #8417: Gemini Bad Request with Github Copilot (MCP tools fail with Gemini)
  • #7791: Schema.ref 'QuestionInfo' was set alongside unsupported fields (almost identical error message)
  • #11413: "question" tool schema causes "400 Bad Request" with Gemini/Vertex AI

Additionally, #11968 is a related PR that applies schema transformation to MCP tools - you may want to verify if extending that fix to handle $ref expansion would solve this issue.

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Feb 5, 2026): This issue might be a duplicate of existing issues. Please check: - #5832: Error with Gemini models when MCP enabled - #8417: Gemini Bad Request with Github Copilot (MCP tools fail with Gemini) - #7791: Schema.ref 'QuestionInfo' was set alongside unsupported fields (almost identical error message) - #11413: "question" tool schema causes "400 Bad Request" with Gemini/Vertex AI Additionally, #11968 is a related PR that applies schema transformation to MCP tools - you may want to verify if extending that fix to handle `$ref` expansion would solve this issue. Feel free to ignore if none of these address your specific case.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8609