MCP Hub
Back to servers

gemini-cli-mcp

A secure MCP server that wraps the Google Gemini CLI, allowing clients to query Gemini models using local OAuth sessions without requiring an API key. It provides tools for model interaction and diagnostics with built-in protection against command injection.

glama
Stars
4
Updated
Mar 24, 2026
Validated
Mar 27, 2026

gemini-cli-mcp

npm version npm downloads license node GitHub stars

中文文档

A secure MCP server that wraps Google's Gemini CLI. It lets Claude Code (or any MCP client) call Gemini models using your local OAuth session — no API key required.

Highlights

  • Securespawn(shell:false) on Unix; controlled shell:true + arg escaping on Windows. No command injection.
  • Cross-platform — macOS, Linux, Windows. Auto-resolves .cmd wrappers and forces UTF-8.
  • Activity-based timeout — idle timer resets on each output chunk. Long thinking won't be killed; stuck 429 retries will.
  • Low token overhead — replaces Gemini's ~8 800-token default system prompt with a minimal one (~50 tokens).
  • Clean output — internally uses stream-json and parses structured responses. No stdout noise pollution.
  • 2 tools onlygemini_query + gemini_info. Minimal context-window footprint for the host AI.

Prerequisites

  1. Node.js >= 18Download
  2. Google Gemini CLI — installed globally and logged in:
npm install -g @google/gemini-cli
gemini   # run once — complete the Google OAuth login in your browser
  1. Verify it works before using this MCP server:
gemini -p "say hello" -o text
# Should print a response. If you see auth errors, re-run `gemini` to log in.

Install

NPM (recommended)

npm install -g @xjoker/gemini-cli-mcp

# Register with Claude Code
claude mcp add gemini-cli -s user -- gemini-cli-mcp

From source

git clone https://github.com/xjoker/gemini-cli-mcp.git
cd gemini-cli-mcp
npm install && npm run build

claude mcp add gemini-cli -s user -- node $(pwd)/dist/index.js

Claude Desktop

Edit ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "gemini-cli": {
      "command": "gemini-cli-mcp"
    }
  }
}

Upgrade

npm update -g @xjoker/gemini-cli-mcp

Tools

gemini_query

Send a prompt to Gemini.

ParameterTypeRequiredDescription
promptstringYesPrompt text. Use @file.ts to include local files.
modelstringNoModel name or alias (default: gemini-2.5-flash)
sandboxbooleanNoRun in sandboxed environment
yolobooleanNoAuto-approve all tool actions
approval_modeenumNodefault / auto_edit / yolo / plan
include_statsbooleanNoAppend token usage stats
include_directoriesstring[]NoExtra workspace directories
cwdstringNoWorking directory for @file references

gemini_info

Diagnostics and metadata — most actions cost zero API calls.

ActionDescriptionAPI call?
pingTest CLI connectivityNo
versionGet CLI versionNo
list_modelsShow available models and aliasesNo
list_sessionsList past Gemini sessionsNo
list_extensionsList installed Gemini extensionsNo

Models

ModelTierDescription
gemini-2.5-prostableHigh reasoning & creativity
gemini-2.5-flashstableFast, balanced (default)
gemini-2.5-flash-litestableFastest, lightest
gemini-3-pro-previewpreviewGemini 3 Pro
gemini-3-flash-previewpreviewGemini 3 Flash
gemini-3.1-pro-previewpreviewGemini 3.1 Pro (rolling out)
gemini-3.1-flash-lite-previewpreviewGemini 3.1 Flash Lite

Aliases: auto, pro, flash, flash-lite

Free tier quota: 60 RPM / 1 000 requests per day.

Environment Variables

VariableDefaultDescription
GEMINI_MODELgemini-2.5-flashDefault model
GEMINI_STARTUP_TIMEOUT15000Phase 1 idle timeout (ms) — CLI startup and initial response
GEMINI_TIMEOUT120000Phase 2 idle timeout (ms) — thinking, resets on each output chunk
GEMINI_MAX_RESPONSE100000Max response chars before truncation
GEMINI_BINgeminiPath to Gemini CLI binary
GEMINI_SYSTEM_MD(bundled minimal)Path to custom system prompt, or "default" for Gemini built-in

Security

PlatformStrategy
Unixchild_process.spawn() with shell: false — user input never reaches a shell
Windowsshell: true (required for .cmd) with % -> %% and ! -> ^^! escaping
  • Zero usage of exec() / execSync() / template-string commands.
  • Verify: grep -rn "exec(" src/ returns nothing.

License

MIT

Reviews

No reviews yet

Sign in to write a review

gemini-cli-mcp — MCP Server | MCP Hub