gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

Gemini CLI Fails to Parse ToolError from Custom MCP Server

Open sniemczyk-google opened this issue 1 year ago • 4 comments

What happened?

Bug Report: Gemini CLI Fails to Parse ToolError from Custom MCP Server

Title: Gemini CLI fails to parse ToolError responses from a custom MCP server, even when the error message is a simple string.

Description:

When a custom MCP server built with fastmcp raises a fastmcp.exceptions.ToolError, the Gemini CLI is unable to parse the response and reports a generic "[Error: Could not parse tool response]" message. This issue persists even when the error message is a simple string without any special characters, preventing the CLI from displaying meaningful error information to the user.

Steps to Reproduce:

  1. Create a Custom MCP Server:

    • Set up a basic MCP server using fastmcp.
    • Implement a tool (start_task) that raises a fastmcp.exceptions.ToolError under specific conditions. For example, the tool can check if a prerequisite action has been completed and, if not, raise the exception.
  2. Initial Test with Backticks:

    • The initial implementation of the error message included backticks to highlight a tool name: 'The instructions must be read before starting a task. Please call the `read_instructions` tool first.'.
    • When this tool was called via gemini, the execution failed with the error: [Error: Could not parse tool response].
  3. Second Test without Backticks:

    • Suspecting that the backticks were causing a parsing issue, the error message in the server code was simplified to a plain string: 'The instructions must be read before starting a task. Please call the read_instructions tool first.'.
    • The MCP server was reinstalled to apply the changes.
    • The gemini --debug command was run again to call the same tool.

Expected Behavior:

The Gemini CLI should correctly parse the ToolError response from the MCP server and display the string-based error message to the user. For example, it should output: "The instructions must be read before starting a task. Please call the read_instructions tool first."

Actual Behavior:

The Gemini CLI continues to fail with the exact same error: [Error: Could not parse tool response]. The --debug output confirms that the MCP server is being called and is processing the request, but the CLI is unable to handle the ToolError it receives.

Debug Output Snippet:

[DEBUG] [MCP STDERR (craftMCP)]: [08/15/25 13:35:52] INFO Processing request of type CallToolRequest [39m
I attempted to start the task, but it failed with the following error: "Could not parse tool response".

Analysis:

This behavior suggests a potential bug in how the Gemini CLI handles ToolError exceptions from MCP servers. The parser appears to be failing even on simple, unformatted error strings, which makes it difficult to provide meaningful feedback to the user when a tool fails. The issue does not seem to be with the server's implementation—as the error is being raised correctly—but rather with the client's ability to interpret that error. This problem hinders the development of robust MCP tools, as there is no reliable way to communicate tool-specific errors to the end-user through the Gemini CLI.

What did you expect to happen?

Gemini CLI would read the tool exception and not produce a parse error and then take action based on the parsed error message, as it has done in the past, instead of retrying to call the tool over and over.

Client information

Gemini CLI using a FastMCP 1.6.0 server

$ gemini /about
                                                   │
│ About Gemini CLI                                  │
│                                                   │
│ CLI Version      0.1.21                           │
│ Git Commit       4973e7e1                         │
│ Model            gemini-2.5-pro                   │
│ Sandbox          no sandbox                       │
│ OS               linux                            │
│ Auth Method      gemini-api-key 

Login information

Gemini API Key

Anything else we need to know?

No response

sniemczyk-google avatar Aug 15 '25 13:08 sniemczyk-google

Found possible duplicate issues:

  • #6286

If you believe this is not a duplicate, please remove the status/possible-duplicate label.

gemini-cli[bot] avatar Aug 15 '25 13:08 gemini-cli[bot]

@sniemczyk-google can you see if this is still happening at head? https://github.com/google-gemini/gemini-cli/pull/6194 sought to fix this

leehagoodjames avatar Aug 15 '25 14:08 leehagoodjames

I rebuilt from HEAD 1a2906a8 and it now successfully parses the tool call exception and Gemini CLI decides the right course of action... Thanks @leehagoodjames !

sniemczyk-google avatar Aug 15 '25 17:08 sniemczyk-google

Great, closing as fixed

leehagoodjames avatar Aug 21 '25 20:08 leehagoodjames