Skip to content

Issue on Gemini when call the Google Map MCP #5640

@thestan12

Description

@thestan12

Description

When using Spring AI with Google GenAI / Gemini and MCP client tools, the application fails before tool execution if one of the MCP tool input schemas contains $defs.

The failure happens while Spring AI converts the tool schema for Google structured output / tool calling.

In my case, the incompatible schema comes from the Google Maps MCP server (https://mapstools.googleapis.com/mcp).

Versions

  • Spring Boot: 4.0.x
  • Spring AI: 2.0.0-M3
  • Model: Google GenAI / Gemini
  • MCP client enabled
  • Transport: streamable-http

What I expected

Spring AI should either:

  • support MCP tool schemas containing $defs, or
  • flatten / dereference them before sending them to Google GenAI, or
  • fail with a clearer compatibility message and ideally allow filtering incompatible tools.

What happened

Application fails when resolving tool definitions for Gemini.

Stack trace excerpt:

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

Additional context

The issue is triggered by the Google Maps MCP server, configured as a streamable HTTP MCP client.

Spring configuration:


spring:
  ai:
    model:
      chat: google-genai
      embedding:
        text: none
    mcp:
      client:
        initialized: false
        streamable-http:
          connections:
            google-maps:
              url: https://mapstools.googleapis.com
              endpoint: /mcp

I also reproduced the issue by creating the MCP client explicitly:

@Bean(name = ["googleMapMcp"])
fun createGoogleMapClient(): McpSyncClient {

    val transport = HttpClientStreamableHttpTransport.builder(mcpUrl)
        .endpoint(endpoint)
        .httpRequestCustomizer { builder, _, _, _, _ ->
            builder.header("X-Goog-Api-Key", apiKey)
        }
        .build()

    val client = McpClient.sync(transport)
        .clientInfo(McpSchema.Implementation("xxxxx-maps-client", "1.0"))
        .build()

    client.initialize()

    return client
}

The problematic schema appears to be produced by the Google Maps MCP tool definition itself, for example with nested $defs such as:

{
  "$defs": {
    "Circle": {
      "description": "A circle defined by center point and radius.",
      "properties": {
        "center": {
          "$ref": "#/$defs/LatLng"
        },
        "radiusMeters": {
          "format": "double",
          "type": "number"
        }
      },
      "required": ["center"],
      "type": "object"
    },
    "LatLng": {
      "description": "An object that represents a latitude/longitude pair.",
      "properties": {
        "latitude": {
          "format": "double",
          "type": "number"
        },
        "longitude": {
          "format": "double",
          "type": "number"
        }
      },
      "type": "object"
    },
    "LocationBias": {
      "description": "The region to bias the search results to.",
      "properties": {
        "circle": {
          "$ref": "#/$defs/Circle"
        }
      },
      "type": "object"
    }
  },
  "type": "object",
  "properties": {
    "languageCode": {
      "type": "string"
    },
    "locationBias": {
      "$ref": "#/$defs/LocationBias"
    },
    "regionCode": {
      "type": "string"
    },
    "textQuery": {
      "type": "string"
    }
  },
  "required": ["textQuery"]
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions