Repository navigation
Conversation
Google AI Studio rejects any function-declaration enum member that
stringifies to "", e.g.:
GenerateContentRequest.tools[0].function_declarations[N].parameters
.properties[field].enum[0]: cannot be empty
MCP servers commonly model an "unset"/"clear this field" option as a
literal "" enum member (distinct from omitting the argument, which
means "leave unchanged"). That's valid JSON Schema and works fine
against Anthropic/OpenAI, but Gemini validates the entire tools[]
array up front on every generateContent call, so a single tool with
this shape breaks every request on that turn, not just calls to the
offending tool.
Strip "" out of enum arrays in the Gemini tool-schema sanitizer (plain
enums and enums nested inside anyOf/oneOf/allOf branches, since
sanitizeNode already recurses into those). If stripping empties the
enum entirely, drop the constraint and fall back to the bare type.
Reproduced against a real-world MCP server (personas_create /
personas_update / personas_add_detail tools using "" as an explicit
clear-field sentinel) that reliably 400s every Gemini turn while
connected.
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Closes #33316
Type of change
What does this PR do?
Gemini's function-calling schema validator rejects any
enummember that's an empty string (enum[0]: cannot be empty). Some MCP servers use""as a sentinel for "unset"/"clear this field" on a string enum, which is valid JSON Schema but breaks every turn on a Gemini model once that server is connected — Gemini validates the wholetools[]array up front, not just the tool being called. That's what #33316 hit (link.any_of[0].enum[0]from a Canva MCP tool), though it got triaged as a Canva/$ref-specific issue at the time.packages/llm/src/protocols/utils/gemini-tool-schema.tsalready sanitizes several Gemini-incompatible schema shapes for MCP tools. This adds one more: strip""out ofenumarrays (including ones nested insideanyOf/oneOf/allOf), and drop the enum constraint entirely if that empties it.How did you verify your code works?
Added a test to
packages/llm/test/tool-schema-projection.test.tscovering a plain enum with a""sentinel, the same sentinel nested in ananyOfnullable branch, and an enum that's only[""]. Ran the fullpackages/llmtest suite (299 pass, 0 fail) andbun run typecheck, both clean.Screenshots / recordings
N/A, no UI change.
Checklist