Skip to content

bug: Gemini API + MCP: Type validation failed on tool_calls (invalid_union) #7535

@7032x

Description

@7032x

Description

Using Gemini API models (e.g., gemini-2.5-flash) on Linux Debian Gnome (flathub version) with any MCP Server enabled (Google Search, Sequential Thinking) causes immediate generation failure when a tool is invoked.

The application throws a Type validation failed error targeting the index field within choices[0].delta.tool_calls. It appears the validation schema for tool calls is incompatible with the specific response structure returned by the Gemini API adapter.

Note: Disabling "Stream" in the assistant settings does not resolve the issue.

Steps to Reproduce

  1. Select a Gemini model via API.
  2. Enable any MCP Server (e.g., Google Search).
  3. Send a prompt that triggers a tool call (e.g., "Search for the next lottery date").
  4. Error occurs immediately.

Error Log

Error generating response
Type validation failed: Value: {"choices":[{"delta":{"role":"assistant","tool_calls":[{"function":{"arguments":"...","name":"google_search"},"id":"...","type":"function"}]},"finish_reason":"tool_calls","index":0}],"created":...}
Error message: [{"code":"invalid_union","errors":[[{"expected":"number","code":"invalid_type","path":["choices",0,"delta","tool_calls",0,"index"],"message":"Invalid input"}]],[{"expected":"object","code":"invalid_type","path":["error"],"message":"Invalid input"}]],"path":[],"message":"Invalid input"}]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions