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

400 “FunctionDeclaration … maximum allowed nesting depth” on every prompt when Notion MCP is enabled

Open nahyeongjin1 opened this issue 1 year ago • 30 comments

What happened?

Summary

gemini fails for every conversation prompt with a 400 error when the Notion MCP server is enabled. As soon as I disable that MCP entry in settings.json, the CLI works normally again.


Observed error

╭────────╮ │ > hi │ ╰────────╯

✕ [API Error: {"error":{"message":"{\n "error": {\n "code": 400,\n "message": "A FunctionDeclaration in the request exceeds the maximum allowed nesting depth.",\n "status": "INVALID_ARGUMENT"\n }\n}\n","code":400,"status":"Bad Request"}}]

╭───────────╮ │ > hello │ ╰───────────╯

✕ [API Error: {"error":{"message":"{\n "error": {\n "code": 400,\n "message": "A FunctionDeclaration in the request exceeds the maximum allowed nesting depth.",\n "status": "INVALID_ARGUMENT"\n }\n}\n","code":400,"status":"Bad Request"}}]


Minimal settings excerpt (before)

{
  "mcpServers": {
    "notionMCP": {
      "command": "npx",
      "args": ["-y", "mcp-remote", "https://mcp.notion.com/mcp"]
    }
  }
}

Workaround (after)

Commenting out or removing just the Notion MCP entry makes the CLI work again:

{
  "mcpServers": {
    // "notionMCP": {
    //   "command": "npx",
    //   "args": ["-y", "mcp-remote", "https://mcp.notion.com/mcp"]
    // }
  }
}

What did you expect to happen?

Prompts should succeed even with Notion MCP enabled.

Client information

  • CLI Version: 0.1.18-nightly.250810.c632ec8b
  • Git Commit: c632ec8b
  • Operating System: linux v20.19.3
  • Sandbox Environment: no sandbox
  • Model Version: gemini-2.5-pro
  • Memory Usage: 138.0 MB

Login information

API key

Anything else we need to know?

  • The failure reproduces consistently with any simple prompt.

  • Disabling only the Notion MCP (leaving other MCP servers intact) removes the error, suggesting the failure is triggered by this server’s FunctionDeclarations (likely exceeding the API’s nesting-depth constraints).

nahyeongjin1 avatar Aug 10 '25 06:08 nahyeongjin1

Facing the same issue

pgrandin avatar Aug 11 '25 15:08 pgrandin

I got the same error that vanished after removing all MCP servers from settings.json.

{
	"selectedAuthType": "gemini-api-key",
	"theme": "Atom One",
	"preferredEditor": "vim",
	"checkpointing": {
		"enabled": true
	},
	"mcpServers": {
		"sequential-thinking": {
			"command": "npx",
			"args": [
				"-y",
				"@modelcontextprotocol/server-sequential-thinking"
			]
		},
		"sequentialthinking-tools": {
			"command": "npx",
			"args": [
				"-y",
				"mcp-sequentialthinking-tools"
			]
		}
	}
}

The error happens with version 0.1.16 as well as 0.1.20.

olk avatar Aug 13 '25 15:08 olk

I think this is a wider issue with the Gemini API, as we're getting the same error with no changes to our responseSchema param in the generateContent - suddenly we're getting this max depth error.

jaw9c avatar Aug 14 '25 08:08 jaw9c

I replaced the sequential-thinking MCP (which was working some weeks ago) by shannon-thinking MCP - same error happens.

olk avatar Aug 14 '25 08:08 olk

Hi @jaw9c

Do you see:

A FunctionDeclaration in the request exceeds the maximum allowed nesting depth."

Or

A schema in GenerationConfig in the request exceeds the maximum allowed nesting depth.

Can you help to provide the responseSchema?

Thank you.

wanlin31 avatar Aug 14 '25 15:08 wanlin31

@pgrandin The error is {"error":{"code":400,"message":"A schema in GenerationConfig in the request exceeds the maximum allowed nesting depth.","status":"INVALID_ARGUMENT"}}

jaw9c avatar Aug 14 '25 16:08 jaw9c

I'm not able to provide the code publicly, but can provide over email if you provide one?

jaw9c avatar Aug 14 '25 16:08 jaw9c

This is due to a restriction recently put in place in the Gemini model (not Gemini CLI). I think the limit is currently 29 levels.

I've reached out to the implementer to find out what the long term plan is.

scidomino avatar Aug 14 '25 20:08 scidomino

Thanks. Is that total keys rather than complete depth? The object I’m sending is ~5 objects deep and ~20 wide

jaw9c avatar Aug 15 '25 00:08 jaw9c

Hi @jaw9c

I am a bit confused in your case, I don't really need your schema, just want to understand following questions.

  • Are you using generateContent from Gemini CLI?
  • I think the schema depth is counting the depth of the nested schema, not really the width, do your schema use "$ref", "$def" or "$schema" fields by any chance? In your schema, does look like {"type": "OBJECT"} or {"type": "object"}

Thank you :)

wanlin31 avatar Aug 15 '25 15:08 wanlin31

I have updated the error message to include the name of the FunctionDeclaration that have issue.

Before:

ApiError: {"error":{"code":400,"message":"A FunctionDeclaration in the request exceeds the maximum allowed nesting depth.","status":"INVALID_ARGUMENT","details":[{"@type":"type.googleapis.com/google.rpc.DebugInfo","detail":"[ORIGINAL ERROR] generic::invalid_argument: A FunctionDeclaration in the request exceeds the maximum allowed nesting depth. [google.rpc.error_details_ext] { message: \"A FunctionDeclaration in the request exceeds the maximum allowed nesting depth.\" }"}]}}

Now:

ApiError: {"error":{"code":400,"message":"FunctionDeclaration 'sequentialthinking_tools' in the request exceeds the maximum allowed nesting depth.","status":"INVALID_ARGUMENT","details":[{"@type":"type.googleapis.com/google.rpc.DebugInfo","detail":"[ORIGINAL ERROR] generic::invalid_argument: FunctionDeclaration 'sequentialthinking_tools' in the request exceeds the maximum allowed nesting depth. [google.rpc.error_details_ext] { message: \"FunctionDeclaration \\'sequentialthinking_tools\\' in the request exceeds the maximum allowed nesting depth.\" }"}]}}

Currently it only show's the FunctionDeclaration name, probably need some development on the JS sdk side/gemini cli to map it to the MCP server name that have issue.

Create a JS sdk internal bug to track the investigation and effort on this issue.

For the time being, you can try to use /mcp list to find the list of the tools, try to find the MCP server that includes the tool name mentioned in the error message:

The step looks like this:

/mcp list
Image
# ask some random things
what is the weather today
Image

Find the tool name sequentialthinking_tools, remove the MCP server has this tool: sequentialthinking-tools in the settings.json

{
  "selectedAuthType": "gemini-api-key",
  "theme": "Dracula",
  "mcpServers": {
    "context7": {
      "command": "npx",
      "args": ["-y", "@upstash/context7-mcp"]
    },
    "git": {
      "command": "uvx",
      "args": [
        "mcp-server-git",
        "--repository",
        "/usr/local/google/home/wanlindu/gemini-cli"
      ]
    },

    "playwright": {
      "command": "npx",
      "args": ["@playwright/mcp@latest"]
    },
    "sequential-thinking": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-sequential-thinking"]
    },
    "memory": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-memory"]
    },
    "time": {
      "command": "uvx",
      "args": ["mcp-server-time"]
    },
    "firebase": {
      "command": "npx",
      "args": [
        "-y",
        "firebase-tools@latest",
        "experimental:mcp"
      ]
    },
    "sequentialthinking-tools": {
                        "command": "npx",
                        "args": [
                                "-y",
                                "mcp-sequentialthinking-tools"
                        ]
                }
  },
  "preferredEditor": "nano"
}

After removing the Mcp server.

Image

wanlin31 avatar Aug 18 '25 18:08 wanlin31

The related internal bug: b/433406975

scidomino avatar Aug 25 '25 15:08 scidomino

The same error happens with firecrawl MCP too

auggie246 avatar Aug 28 '25 03:08 auggie246

Same error. Using gemini-cli 0.3.3. Interestingly enough, for me it started happening only when I switched from personal auth to "selectedAuthType": "gemini-api-key"

EDIT 2025-09-11: Upgraded to gemini-cli 0.4.0 and it's still happening. It happens with MCP server cocal/google-calendar-mcp. Using the same MCP server with claude, and it works well there.

santi-h avatar Sep 06 '25 22:09 santi-h

Just noting this issue crops up when using the Contentful MCP as well.

stevis avatar Sep 08 '25 19:09 stevis

Same error. Using gemini-cli 0.3.3. Interestingly enough, for me it started happening only when I switched from personal auth to "selectedAuthType": "gemini-api-key"

EDIT 2025-09-11: Upgraded to gemini-cli 0.4.0 and it's still happening. It happens with MCP server cocal/google-calendar-mcp. Using the same MCP server with claude, and it works well there.

Same here. I had to create my own function do detect the intention using prompt instructions to know which google-calendar-mcp tool to use. Works well.

EmersonVilar avatar Sep 12 '25 13:09 EmersonVilar

We were using gemini API with openai client. Suddenly it started to throw 400 "A schema in GenerationConfig in the request exceeds the maximum allowed nesting depth.'". Is there a certain thing that has been changed ?

alpemreelmas avatar Sep 16 '25 07:09 alpemreelmas

We were using gemini API with openai client. Suddenly it started to throw 400 "A schema in GenerationConfig in the request exceeds the maximum allowed nesting depth.'". Is there a certain thing that has been changed ?

Same here. Suddenly we are having the same issue without any changes to our codebase in last few hours.

jatinmistry13 avatar Sep 16 '25 19:09 jatinmistry13

WORKAROUND: Same problem here, after changing the authentication to vertex, problems went away and my firecrawl mcp works as expected.

dquiros1985 avatar Sep 17 '25 06:09 dquiros1985

FYI, we have escalated this issue internally. I'm hoping to get clarity on this issue soon.

scidomino avatar Sep 17 '25 18:09 scidomino