fix(gemini): coerce boolean JSON-schema sub-schemas for genai compatibility#3634
Merged
Merged
Conversation
…bility
MCP tool input schemas are full JSON Schema, where any sub-schema position
(a "properties" value, "items", an "anyOf" entry, ...) may be a bare boolean:
true = "any value validates", false = "nothing validates". Gemini's Schema type
is an OpenAPI 3.0 subset with no boolean-schema form, so genai unmarshals every
sub-schema into a *genai.Schema and hard-fails on a JSON boolean:
json: cannot unmarshal bool into Go struct field Schema.properties of type genai.Schema
A Go any/interface{} field in an MCP tool's input struct is the common source:
schema generators such as google/jsonschema-go render an unconstrained field as
the boolean `true` schema, so any MCP server exposing such a tool is otherwise
unusable with Gemini.
Add normalizeBooleanSchemas to the ConvertParametersToSchema pipeline, alongside
the existing type-array and enum normalizers: recursively coerce boolean
sub-schemas to an empty object schema {} in every schema-bearing position,
leaving additionalProperties booleans untouched (genai ignores the keyword).
Signed-off-by: Eron Wright <eronwright@gmail.com>
Sayt-0
approved these changes
Jul 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
MCP tool input schemas are full JSON Schema, where any sub-schema position — a
propertiesvalue,items, ananyOfentry, etc. — may be a bare boolean:true= "any value validates",false= "nothing validates". Gemini'sSchematype is an OpenAPI-3.0 subset with no boolean-schema form, sogenaiunmarshals every sub-schema into a*genai.Schemaand hard-fails on a JSON boolean:This kills the run before the first model call. A Go
any/interface{}field in an MCP tool's input struct is the common source: schema generators such asgoogle/jsonschema-go(used by mcp-go and the official MCP Go SDK) render an unconstrained field as the booleantrueschema, so any MCP server exposing such a tool is otherwise unusable with Gemini.Fix
Adds
normalizeBooleanSchemasto the existingConvertParametersToSchemanormalization pipeline (alongside the type-array and enum normalizers already there): recursively coerce boolean sub-schemas to an empty object schema{}in every schema-bearing position (properties/items/anyOf/…), leavingadditionalPropertiesbooleans untouched (genai ignores the keyword).{}preserves "any value" while staying parseable by genai.Tests
Adds
pkg/model/provider/gemini/schema_boolean_test.go:TestConvertParametersToSchema_BooleanSubSchema— a schema with boolean sub-schemas (theany-field shape) now converts without error.TestNormalizeBooleanSchemas— booleans coerced in nested positions;additionalPropertiesbooleans preserved.