Skip to content

Gemini provider: tool calls with errors enter infinite retry loop #235

Description

@imtiazqa

When using the Gemini LLM provider, tools that return an error
(isError: true) enter an infinite retry loop instead of returning a
response to the user. The request must be manually cancelled. The same
tools work correctly with the Anthropic provider.

Configuration

llm:
  enabled: true
  provider: gemini
  model: gemini-2.5-flash
  gemini_api_key_file: "/tmp/.gemini-api-key"
  per_attempt_timeout: 60

Tools Tested

Tool Result
list_database_connections Pass
get_schema_info Pass
read_resource Infinite loop
count_rows Infinite loop
query_database Infinite loop

Steps to Reproduce

  1. Configure the server with provider: gemini, model: gemini-2.5-flash
  2. Open the web client and authenticate
  3. Ask: "Read the system info resource"
    → read_resource loops indefinitely
  4. Ask: "How many rows are in the docs table?"
    → count_rows loops indefinitely
  5. Ask: "Query the primary database: SELECT version()"
    → query_database loops indefinitely

Actual Result

Tools enter an infinite retry loop (40+ calls observed) until the
user manually cancels. Example:

read_resource ❌ → read_resource ❌ → read_resource ❌ → ...

Expected Result

All tools return a result and the LLM responds to the user .

Possible Root Cause

The pgedge-go-llm-lib proxy converts MCP tool results into Gemini's
functionResponse format. When a tool returns isError: true, the proxy
likely passes it without Gemini-specific error formatting. Gemini does
not recognize isError: true as a terminal failure and treats it as an
unresolved function call to retry. Anthropic natively understands
isError: true as part of the MCP spec.

Gemini expects errors formatted as:

{
"functionResponse": {
"name": "tool_name",
"response": {
"error": "error message here"
}
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions