gemini-cli - ✅(Solved) Fix [Bug][MCP] {{HOME}} template variable silently ignored in mcpServers config — causes ALL MCPs to show Disconnected with zero error output [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
google-gemini/gemini-cli#26166Fetched 2026-04-30 06:45:09
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×1labeled ×1

Gemini CLI v0.40.0 silently ignores the {{HOME}} template variable in mcpServers configuration. The string is passed verbatim to the process spawner, causing every MCP server to fail with no error output — reported to the user only as "Disconnected".

This caused weeks of misdirected debugging because the failure surface gave no indication that the root cause was an unresolved path template.


Error Message

Gemini CLI v0.40.0 silently ignores the {{HOME}} template variable in mcpServers configuration. The string is passed verbatim to the process spawner, causing every MCP server to fail with no error output — reported to the user only as "Disconnected". No error message is shown. No log output. No hint that the path failed. | Error visibility | ❌ None — shows only "Disconnected" |

Option B: Warn on unresolved templates

Root Cause

Searched the entire bundled source:

grep -c '{{' ~/.npm-global/lib/node_modules/@google/gemini-cli/bundle/gemini.js
# Output: 0

Zero occurrences. The {{HOME}} expansion logic does not exist in the Gemini CLI codebase. The raw string {{HOME}}/.bun/bin/bun is passed to child_process.spawn(), which fails because no such path exists.

The Node.js child_process does not expand shell variables or template strings — it requires a literal, resolved path.


Fix Action

Fix / Workaround

Fix (User-side Workaround)

PR fix notes

PR #26247: fix: expand template vars in MCP stdio config

Description (problem / solution / changelog)

Summary

  • expand {{VAR}} template placeholders in stdio MCP command, args, cwd, and explicit env values before creating the transport
  • keep existing $VAR / ${VAR} expansion behavior by routing through the existing env expansion helper
  • add coverage for {{HOME}} in command, args, cwd, and env values

Fixes #26166

Tests

  • npm run test --workspace @google/gemini-cli-core -- mcp-client.test.ts
  • npm run typecheck --workspace @google/gemini-cli-core
  • npx prettier --check packages/core/src/tools/mcp-client.ts packages/core/src/tools/mcp-client.test.ts
  • npx eslint packages/core/src/tools/mcp-client.ts packages/core/src/tools/mcp-client.test.ts

Changed files

  • packages/core/src/tools/mcp-client.test.ts (modified, +39/-0)
  • packages/core/src/tools/mcp-client.ts (modified, +28/-4)

Code Example

{
  "mcpServers": {
    "github": {
      "command": "{{HOME}}/.bun/bin/bun",
      "args": ["{{HOME}}/.npm-global/lib/node_modules/@modelcontextprotocol/server-github/dist/index.js"]
    }
  }
}

---

gemini

---

/mcp list
→ 🔴 github - Disconnected

---

grep -c '{{' ~/.npm-global/lib/node_modules/@google/gemini-cli/bundle/gemini.js
# Output: 0

---

# Replace all {{HOME}} with actual home directory
sed -i "s|{{HOME}}|$HOME|g" ~/.gemini/settings.json

---

const resolveTemplate = (s: string): string =>
  s.replace(/\{\{HOME\}\}/g, os.homedir())
   .replace(/\{\{USER\}\}/g, os.userInfo().username);

const resolvedCommand = resolveTemplate(serverConfig.command);
const resolvedArgs = serverConfig.args.map(resolveTemplate);

---

⚠️  MCP server "github": command contains unresolved template "{{HOME}}".
    Replace with absolute path: /home/username/.bun/bin/bun
RAW_BUFFERClick to expand / collapse

Environment

  • OS: Windows 10 Host / Ubuntu 24.04 (WSL2)
  • Gemini CLI: v0.40.0
  • Shell: bash (WSL2)
  • Settings file: ~/.gemini/settings.json

Summary

Gemini CLI v0.40.0 silently ignores the {{HOME}} template variable in mcpServers configuration. The string is passed verbatim to the process spawner, causing every MCP server to fail with no error output — reported to the user only as "Disconnected".

This caused weeks of misdirected debugging because the failure surface gave no indication that the root cause was an unresolved path template.


Reproduction

Step 1: Configure any MCP server using {{HOME}} syntax

{
  "mcpServers": {
    "github": {
      "command": "{{HOME}}/.bun/bin/bun",
      "args": ["{{HOME}}/.npm-global/lib/node_modules/@modelcontextprotocol/server-github/dist/index.js"]
    }
  }
}

Step 2: Launch Gemini CLI

gemini

Step 3: Check MCP status

/mcp list
→ 🔴 github - Disconnected

No error message is shown. No log output. No hint that the path failed.


Root Cause

Searched the entire bundled source:

grep -c '{{' ~/.npm-global/lib/node_modules/@google/gemini-cli/bundle/gemini.js
# Output: 0

Zero occurrences. The {{HOME}} expansion logic does not exist in the Gemini CLI codebase. The raw string {{HOME}}/.bun/bin/bun is passed to child_process.spawn(), which fails because no such path exists.

The Node.js child_process does not expand shell variables or template strings — it requires a literal, resolved path.


Impact

This is a silent, undiscoverable failure with maximum user impact:

BehaviorDetail
Error visibility❌ None — shows only "Disconnected"
Debug hint❌ None — no log, no stderr output
Documentation❌ Community examples use {{HOME}} syntax
Blast radius🔴 All MCP servers fail simultaneously
Time to discoverTook 1 user approximately 6 weeks to find

The failure is particularly insidious because:

  1. Gemini CLI correctly reads the settings file (it shows "12 MCP servers configured")
  2. It correctly counts the MCPs in the UI footer
  3. It silently fails to spawn them without any diagnostic output
  4. Users debug network issues, permissions, and bun versions — never suspecting the path template

Fix (User-side Workaround)

# Replace all {{HOME}} with actual home directory
sed -i "s|{{HOME}}|$HOME|g" ~/.gemini/settings.json

After this single substitution: all MCP servers connected immediately on next launch.


Requested Changes

Option A: Implement {{HOME}} expansion (recommended)

Before spawning MCP server processes, resolve {{HOME}} (and potentially other template variables like {{USER}}, {{PWD}}) in the command and args fields:

const resolveTemplate = (s: string): string =>
  s.replace(/\{\{HOME\}\}/g, os.homedir())
   .replace(/\{\{USER\}\}/g, os.userInfo().username);

const resolvedCommand = resolveTemplate(serverConfig.command);
const resolvedArgs = serverConfig.args.map(resolveTemplate);

Option B: Warn on unresolved templates

If template expansion is intentionally not supported, the CLI should detect {{...}} patterns in command/args paths and emit a clear warning:

⚠️  MCP server "github": command contains unresolved template "{{HOME}}".
    Replace with absolute path: /home/username/.bun/bin/bun

Option C: Document the limitation

At minimum, add a clear note to the MCP configuration documentation that {{HOME}} and similar template variables are not supported and will cause silent failures.


Related Issues

  • #26164 — Model self-diagnosis failure (this bug is the root cause documented there)
  • #26114 — Large paste premature execution
  • #26117 — Comprehensive reliability failure report

extent analysis

TL;DR

The most likely fix is to replace {{HOME}} with the actual home directory in the settings.json file or implement template variable expansion in the Gemini CLI.

Guidance

  • Verify that the settings.json file contains the {{HOME}} template variable in the mcpServers configuration.
  • Replace {{HOME}} with the actual home directory using the provided sed command as a temporary workaround.
  • Consider implementing template variable expansion in the Gemini CLI to resolve {{HOME}} and other potential template variables.
  • If template expansion is not supported, add a warning to detect unresolved templates in command/args paths.

Example

const resolveTemplate = (s: string): string =>
  s.replace(/\{\{HOME\}\}/g, os.homedir())
   .replace(/\{\{USER\}\}/g, os.userInfo().username);

const resolvedCommand = resolveTemplate(serverConfig.command);
const resolvedArgs = serverConfig.args.map(resolveTemplate);

Notes

The provided sed command is a user-side workaround and may not be a permanent solution. Implementing template variable expansion or adding warnings for unresolved templates would be a more robust fix.

Recommendation

Apply the workaround by replacing {{HOME}} with the actual home directory using the sed command, as this is a quick and effective solution to resolve the issue. However, it is recommended to implement template variable expansion in the Gemini CLI for a more permanent fix.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

gemini-cli - ✅(Solved) Fix [Bug][MCP] {{HOME}} template variable silently ignored in mcpServers config — causes ALL MCPs to show Disconnected with zero error output [1 pull requests, 1 participants]