gemini mcp add --include-tools/--exclude-tools does not split comma-separated lists, silently inverting tool filtering

Aperta Adatta ai principianti
#30,330 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@anujmishra03 ci sta già lavorando.

Dal 17/11/2026.

  • #30332 di @anujmishra03 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
85/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
node.js, typescript
Ambito
cli, tooling

Direzione di ricerca

Inizia dalle definizioni delle opzioni include-tools e exclude-tools in packages/cli/src/commands/mcp/add.ts, poi leggi coerceCommaSeparated in packages/cli/src/config/config.ts e verifica come viene usato per --include-directories. Esamina i test pertinenti di mcp add oppure aggiungi test per i valori separati da virgole e i flag ripetuti. Il lavoro è completato quando ogni valore separato da virgole viene salvato come nome di strumento individuale senza spazi superflui e i flag ripetuti continuano a funzionare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

status/need-triage
What happened?

gemini mcp add --include-tools tool1,tool2 (and --exclude-tools) stores the whole comma-separated string as a single array element instead of splitting it into individual tool names. Both the flag help ("A comma-separated list of tools to include/exclude") and the official docs promise comma-separated usage, but the value is never split.

Because the tool filter downstream matches names exactly, this silently inverts the user's intent:

  • --include-tools a,b → stored as ["a,b"] → matches no tool → all tools from the server are silently dropped (server appears broken).
  • --exclude-tools x,y → stored as ["x,y"] → matches no tool → nothing is excluded; tools the user intended to block stay fully callable. This is the security-relevant direction: a user restricting a server's surface gets no restriction and no warning.

In both cases the command prints "added" and exits 0.

Reproduction

Verified with a source build of commit 4fa64e71b9b4e1bb65a86cc2863574f561b82340 (version string 0.70.0-nightly.20261110.g1603e9bab), run with an isolated USERPROFILE/HOME. Same commands reproduce with a normal install (they write to ~/.gemini/settings.json):

$ gemini mcp add probe3 node --include-tools a,b --scope user
MCP server "probe3" added to user settings. (stdio)

Resulting ~/.gemini/settings.json (excerpt):

"probe3": {
  "command": "node",
  "args": [],
  "includeTools": [
    "a,b"
  ]
}

Same for exclude:

$ gemini mcp add probe5 node --exclude-tools x,y --scope user
MCP server "probe5" added to user settings. (stdio)
"probe5": {
  "command": "node",
  "args": [],
  "excludeTools": [
    "x,y"
  ]
}

Workaround confirmed: repeating the flag works, because yargs accumulates array values:

$ gemini mcp add probe4 node --include-tools a --include-tools b --scope user
"includeTools": [
  "a",
  "b"
]
Why the unsplit string is harmful (consumer semantics)

packages/core/src/tools/mcp-client.ts (L2500–L2512):

const { includeTools, excludeTools } = mcpServerConfig;

// excludeTools takes precedence over includeTools
if (excludeTools && excludeTools.includes(funcDecl.name)) {
  return false;
}

return (
  !includeTools ||
  includeTools.some(
    (tool) => tool === funcDecl.name || tool.startsWith(`${funcDecl.name}(`),
  )
);

"a,b" never equals a tool name and never starts with name(, so an include-list of ["a,b"] filters out every tool, and an exclude-list of ["x,y"] excludes none.

Root cause and documented intent

The options in packages/cli/src/commands/mcp/add.ts (L217–L226) are declared as plain string arrays with no comma coercion:

.option('include-tools', {
  describe: 'A comma-separated list of tools to include',
  type: 'array',
  string: true,
})
.option('exclude-tools', {
  describe: 'A comma-separated list of tools to exclude',
  type: 'array',
  string: true,
})

Yet comma-separated usage is the documented interface:

The repo already has the exact helper needed — coerceCommaSeparated at packages/cli/src/config/config.ts L124 — and applies it to other comma-separated array options, e.g. --include-directories (config.ts L469–L476). It is simply missing from mcp add's two tool-filter options.

Related but distinct

This is different from #28962, which concerns the parenthesized tool(args) include syntax in extension manifests / ToolRegistry matching. The present issue is the CLI flag parsing in gemini mcp add: comma-separated values are never split before being persisted to settings, regardless of any tool(args) syntax.

What did you expect to happen?

--include-tools a,b and --exclude-tools x,y should behave as documented: split on commas into ["a","b"] / ["x","y"] (ideally reusing coerceCommaSeparated, trimming whitespace), so the exact-match filter in mcp-client.ts works as intended. Repeated-flag usage should keep working. Optionally, warn when a persisted filter entry matches no discovered tool, so a silent empty include-list is surfaced instead of looking like a broken server.

Client information
  • Gemini CLI version: 0.70.0-nightly.20261110.g1603e9bab, built from source at commit 4fa64e71b9b4e1bb65a86cc2863574f561b82340 (npm ci && npm run build); the option definitions above are unchanged at that commit.
  • Node: v24.17.0
  • OS: Windows 11 (10.0.26200), x64
  • Transport: stdio, --scope user
  • No LLM/API calls involved; settings-write path plus the static filter logic in mcp-client.ts.
Login information

Not applicable — no authentication or model calls are involved. Reproduced with a source build and an isolated home directory; no API key configured.

Lingua principale
TypeScript
Stelle
109k
Fork
15k
Merge medio
1g 1h
PR unite (30g)
121

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di google-gemini/gemini-cli

Tutte le issue di google-gemini/gemini-cli

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.