fix(mcp): make tool schemas compatible with Google Gemini API#106
Open
gabriel-ecegi wants to merge 1 commit intoBeaconBay:mainfrom
Open
fix(mcp): make tool schemas compatible with Google Gemini API#106gabriel-ecegi wants to merge 1 commit intoBeaconBay:mainfrom
gabriel-ecegi wants to merge 1 commit intoBeaconBay:mainfrom
Conversation
The Gemini API rejects JSON Schema union types like ["array", "null"] in tool function declarations. This causes 400 Bad Request errors when any MCP client with CK tools tries to use Gemini models. Add #[schemars(with = "Vec<String>")] to all Option<Vec<String>> fields in the 4 search request structs (Semantic, Regex, Hybrid, Lexical). This generates "type": "array" instead of "type": ["array", "null"] while keeping the Rust type unchanged for backward compatibility. Fixes: Gemini 3 Flash, Gemini 3.1 Pro, and other Google models failing with tool schema validation errors on include_patterns/exclude_patterns.
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.
Summary
The Google Gemini API rejects JSON Schema union types like
["array", "null"]in tool function declarations, causing 400 Bad Request errors when any MCP client with CK tools tries to use Gemini models.Problem
When CK's MCP server exposes tool schemas to LLM providers,
Option<Vec<String>>fields (include_patterns,exclude_patterns) generate:{ "type": ["array", "null"], "items": { "type": "string" } }This is valid JSON Schema but Gemini's API validates strictly:
Fix
Add
#[schemars(with = "Vec<String>")]to all 8Option<Vec<String>>fields across the 4 search request structs (SemanticSearchRequest,RegexSearchRequest,HybridSearchRequest,LexicalSearchRequest).This generates
"type": "array"instead of"type": ["array", "null"]while keeping the Rust typeOption<Vec<String>>unchanged — fully backward compatible.Tested
google/gemini-3.1-pro-preview— responds correctlygoogle/antigravity-gemini-3-flash— responds correctlycargo testpassescargo build --releasesucceeds