Skip to content

fix(mcp): make tool schemas compatible with Google Gemini API#106

Open
gabriel-ecegi wants to merge 1 commit intoBeaconBay:mainfrom
blogic-cz:fix/gemini-tool-schema-compatibility
Open

fix(mcp): make tool schemas compatible with Google Gemini API#106
gabriel-ecegi wants to merge 1 commit intoBeaconBay:mainfrom
blogic-cz:fix/gemini-tool-schema-compatibility

Conversation

@gabriel-ecegi
Copy link
Copy Markdown

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:

GenerateContentRequest.tools[0].function_declarations[N].parameters.properties[include_patterns].items: 
  field predicate failed: $type == Type.ARRAY

Fix

Add #[schemars(with = "Vec<String>")] to all 8 Option<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 type Option<Vec<String>> unchanged — fully backward compatible.

Tested

  • google/gemini-3.1-pro-preview — responds correctly
  • google/antigravity-gemini-3-flash — responds correctly
  • ✅ Anthropic models — still work (they were already fine)
  • cargo test passes
  • cargo build --release succeeds

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant