#7071·spring-ai

Google GenAI: tool schemas with $defs fail; send them via FunctionDeclaration.parametersJsonSchema

Author: mandsCreated Sep 29, 2026Updated Sep 29, 2026
Labelsstatus: waiting-for-triage

Problem

GoogleGenAiToolCallingManager converts every tool input schema to the OpenAPI-subset Schema and sends it as FunctionDeclaration.parameters. JsonSchemaConverter.convertToOpenApiSchema rejects any schema with $defs:

java.lang.IllegalArgumentException: Google's Structured Output schema doesn't support $defs property
	at org.springframework.ai.google.genai.schema.JsonSchemaConverter.convertToOpenApiSchema(JsonSchemaConverter.java:66)
	at org.springframework.ai.google.genai.schema.GoogleGenAiToolCallingManager.lambda$resolveToolDefinitions$0(GoogleGenAiToolCallingManager.java:77)

MCP tool schemas use $defs / $ref routinely, including Google's own hosted Workspace MCP servers (gmailmcp.googleapis.com and siblings) and Maps (#5640). One such tool in the request fails the whole chat call, so a Gemini agent cannot use these servers at all. The block was added on purpose (#5211) because the OpenAPI subset has no references.

Repro

Spring AI 2.0.1 (also 2.1.0-M1; the schema package is unchanged), spring-ai-starter-model-google-genai, an MCP client connected to https://gmailmcp.googleapis.com/mcp/v1, the MCP tool callbacks passed to ChatClient. The first model call throws the exception above.

Proposal

The Gemini API has a JSON Schema field for exactly this: FunctionDeclaration.parametersJsonSchema (mutually exclusive with parameters; see the Java GenAI SDK's FunctionDeclaration), and Google announced JSON Schema support including $ref across current models. Send tool input schemas through parametersJsonSchema as they are, instead of converting them, either always or behind an option.

Related

  • #5640: the same failure from the Google Maps MCP server; open, no reply.
  • #5888 / #6035: the producer-side twin (nested $defs from JsonSchemaGenerator), fixed by hoisting $defs; #5888 names #5640 as the consumer side of the same root cause.
  • #5211: where $defs / $ref were forbidden in JsonSchemaConverter.

Our workaround

A ToolCallback decorator whose getToolDefinition() returns the input schema with the top-level $defs removed and each #/$defs/X reference replaced by a copy of X. It cannot represent recursive types.

(issue generated with AI assistance)

Source: spring-projects/spring-ai