400 “FunctionDeclaration … maximum allowed nesting depth” on every prompt when Notion MCP is enabled
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).
Facing the same issue
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.
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.
I replaced the sequential-thinking MCP (which was working some weeks ago) by shannon-thinking MCP - same error happens.
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.
@pgrandin The error is {"error":{"code":400,"message":"A schema in GenerationConfig in the request exceeds the maximum allowed nesting depth.","status":"INVALID_ARGUMENT"}}
I'm not able to provide the code publicly, but can provide over email if you provide one?
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.
Thanks. Is that total keys rather than complete depth? The object I’m sending is ~5 objects deep and ~20 wide
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 :)
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
# ask some random things
what is the weather today
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.
The related internal bug: b/433406975
The same error happens with firecrawl MCP too
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.
Just noting this issue crops up when using the Contentful MCP as well.
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.
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 ?
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.
WORKAROUND: Same problem here, after changing the authentication to vertex, problems went away and my firecrawl mcp works as expected.
FYI, we have escalated this issue internally. I'm hoping to get clarity on this issue soon.