mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-16 23:02:51 -07:00
35589570be
## What the change is - Implemented `smartLimitTools` in `ToolRegistry` to ensure that `getFunctionDeclarations` returns at most 128 tools (the Gemini API limit). - The "smart" limiting strategy: 1. Always prioritizes built-in tools. 2. Prioritizes non-MCP discovered tools. 3. Fairly distributes the remaining slots among all available MCP servers (round-robin style). - Added a hard limit of 128 tools in `GeminiChat` as a final safety measure before calling the API. - Added warning logs when tools are truncated to inform the user. ## Why it is recommended The Gemini API has a hard limit of 128 tools per request. If more than 128 tools are enabled (e.g., multiple MCP servers with many tools), the CLI currently sends all of them, resulting in a 400 Bad Request error from the API. This change prevents those errors while ensuring that a representative and critical set of tools remains available to the model. ## Expected impact - Fixes the 400 error reported in #24246. - Improves reliability when many MCP servers are connected. - No negative impact on existing functionality, as most users have fewer than 128 tools, and for those who have more, it provides a stable fallback instead of a crash.