gemini-cli-mcp

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.

Category
访问服务器

README

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.

Parameter Type Required Description
prompt string Yes Prompt text. Use @file.ts to include local files.
model string No Model name or alias (default: gemini-2.5-flash)
sandbox boolean No Run in sandboxed environment
yolo boolean No Auto-approve all tool actions
approval_mode enum No default / auto_edit / yolo / plan
include_stats boolean No Append token usage stats
include_directories string[] No Extra workspace directories
cwd string No Working directory for @file references

gemini_info

Diagnostics and metadata — most actions cost zero API calls.

Action Description API call?
ping Test CLI connectivity No
version Get CLI version No
list_models Show available models and aliases No
list_sessions List past Gemini sessions No
list_extensions List installed Gemini extensions No

Models

Model Tier Description
gemini-2.5-pro stable High reasoning & creativity
gemini-2.5-flash stable Fast, balanced (default)
gemini-2.5-flash-lite stable Fastest, lightest
gemini-3-pro-preview preview Gemini 3 Pro
gemini-3-flash-preview preview Gemini 3 Flash
gemini-3.1-pro-preview preview Gemini 3.1 Pro (rolling out)
gemini-3.1-flash-lite-preview preview Gemini 3.1 Flash Lite

Aliases: auto, pro, flash, flash-lite

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

Environment Variables

Variable Default Description
GEMINI_MODEL gemini-2.5-flash Default model
GEMINI_STARTUP_TIMEOUT 15000 Phase 1 idle timeout (ms) — CLI startup and initial response
GEMINI_TIMEOUT 120000 Phase 2 idle timeout (ms) — thinking, resets on each output chunk
GEMINI_MAX_RESPONSE 100000 Max response chars before truncation
GEMINI_BIN gemini Path to Gemini CLI binary
GEMINI_SYSTEM_MD (bundled minimal) Path to custom system prompt, or "default" for Gemini built-in

Security

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

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选