gemini-cli-bridge
Exposes the local Gemini CLI as an MCP stdio server, providing tools for prompting, web search, file operations, and MCP management, enabling AI clients like Codex CLI and Claude Code to interact with Gemini.
README
Gemini CLI MCP Bridge
[English] | 简体中文
A tiny bridge that exposes your local Gemini CLI as an MCP (Model Context Protocol) stdio server. It wraps common Gemini CLI flows and adds handy file/network utilities for tools-capable clients like Codex CLI and Claude Code.
Note: In client UIs and configs, the server is displayed as "Gemini" while the command remains gemini-cli-bridge (or uvx --from . gemini-cli-bridge).
Features
- Standard MCP (stdio) server
- Thin wrappers for common Gemini CLI flows: version, prompt, WebFetch/Search, MCP management
- Utilities: read/write files, list folders, simple web fetch, text search, optional Shell (disabled by default)
- Runs with uv/uvx without manually installing dependencies
Prerequisites
- Python 3.10+ (3.11+ recommended)
- Gemini CLI installed and authenticated (used to call the actual model)
- On macOS, ensure Homebrew bin is in PATH:
/opt/homebrew/bin
Quick checks:
python3 --version
which gemini && gemini --version
Install & Run
Quick install (PyPI)
- pip
pip install gemini-cli-bridge- Start:
gemini-cli-bridge(Ctrl+C to exit)
- pipx (isolated)
pipx install gemini-cli-bridgegemini-cli-bridge
Clone first:
git clone https://github.com/chaodongzhang/gemini_cli_bridge.git
cd gemini_cli_bridge
Clone repository (for dev workflows):
git clone https://github.com/chaodongzhang/gemini_cli_bridge.git
cd gemini_cli_bridge
From source (dev), install as a global tool via uv:
uv tool install --from . gemini-cli-bridge
# Verify (should work from any directory)
gemini-cli-bridge
Add uv tools dir to PATH if needed.
-
macOS (zsh):
# Typically: $HOME/Library/Application Support/uv/tools/bin echo 'export PATH="$HOME/Library/Application Support/uv/tools/bin:$PATH"' >> ~/.zshrc && source ~/.zshrc -
Linux: usually
~/.local/bin.
One-off try (uvx, no install):
uvx --from . gemini-cli-bridge
Direct run (repo checkout):
python3 ./gemini_cli_bridge.py
Release downloads
- Prebuilt wheels and source tarballs are available on GitHub Releases: https://github.com/chaodongzhang/gemini_cli_bridge/releases
Notes
- Runs in foreground; press Ctrl+C to stop.
- On macOS ensure
/opt/homebrew/binis on PATH. - uv tools bin (if needed):
$HOME/Library/Application Support/uv/tools/bin.
Use with common clients (stdio)
Examples below use stdio; adjust command/paths for your system.
1) Codex CLI (global TOML)
~/.codex/config.toml:
[mcp_servers.Gemini]
command = "gemini-cli-bridge"
args = []
[mcp_servers.Gemini.env]
NO_COLOR = "1"
Notes:
- As of 2025-09-10, Codex only supports a global
~/.codex/config.toml. - Restart Codex after changes. Use
gemini_versionas a quick health check.
2) Claude Code (VS Code extension)
User Settings (JSON):
{
"claude.mcpServers": {
"Gemini": {
"command": "gemini-cli-bridge",
"args": [],
"env": { "NO_COLOR": "1" }
}
}
}
3) Generic MCP CLI (for local testing)
npm i -g @modelcontextprotocol/cli
mcp-cli --server gemini-cli-bridge
4) Claude Desktop (optional)
{
"mcpServers": {
"Gemini": {
"command": "gemini-cli-bridge",
"args": [],
"env": { "NO_COLOR": "1" }
}
}
}
Typical usage (from clients)
- Version:
gemini_version - Non-interactive prompt:
gemini_prompt(prompt=..., model="gemini-2.5-pro") - Advanced prompt with attachments/approval:
gemini_prompt_plus(...) - Web fetch:
gemini_web_fetch(prompt, urls=[...]) - Manage Gemini CLI MCP:
gemini_mcp_list / gemini_mcp_add / gemini_mcp_remove - Google search:
GoogleSearch(query="...", limit=5)(defaults to CLI built-in) - Alias to avoid tool name conflicts:
GeminiGoogleSearch(...)(same args asGoogleSearch)
Return shape note (wrappers):
- Gemini CLI wrappers now return structured JSON:
{ "ok", "exit_code", "stdout", "stderr" }. Tools affected:gemini_version,gemini_prompt,gemini_prompt_plus,gemini_prompt_with_memory,gemini_search,gemini_web_fetch,gemini_extensions_list,gemini_mcp_list/add/remove.
Notes about GoogleSearch:
- By default it uses Gemini CLI’s built-in GoogleSearch (no Google API keys needed, assuming you’re logged in to the CLI).
- If both
GOOGLE_CSE_IDandGOOGLE_API_KEYare set (env or args), it switches to Google Programmable Search (CSE). - You can force the mode via
mode:"gemini_cli" | "gcs" | "auto"(default auto).
MCP tool call examples
gemini_prompt_plus payload example:
{
"name": "gemini_prompt_plus",
"arguments": {
"prompt": "hello",
"extra_args": ["--debug", "--proxy=http://127.0.0.1:7890"]
}
}
Minimal GoogleSearch payload (defaults to CLI built-in):
{
"name": "GoogleSearch",
"arguments": {
"query": "Acme Corp",
"limit": 5
}
}
Use the alias to avoid naming conflicts in some IDEs:
{
"name": "GeminiGoogleSearch",
"arguments": {
"query": "today ai industry news",
"limit": 5
}
}
Force built-in mode (no keys):
{
"name": "GoogleSearch",
"arguments": {
"query": "today ai industry news",
"limit": 5,
"mode": "gemini_cli"
}
}
Troubleshooting startup/handshake timeouts
- Prefer installed command over
uvx --from .to avoid cold-start dependency resolution. - Increase client startup/handshake timeouts if supported.
- PATH issues on macOS: ensure
/opt/homebrew/binor set PATH in client env.
Make sure it uses CLI built-in search (avoid unintended CSE mode)
Possible causes:
- Another tool named
GoogleSearchfrom a different server/extension. - Your environment sets both
GOOGLE_API_KEYandGOOGLE_CSE_ID, which switches this bridge into CSE mode.
What to do:
- Explicitly clear two vars in your MCP config
Codex (~/.codex/config.toml):
[mcp_servers.Gemini]
command = "gemini-cli-bridge"
args = []
[mcp_servers.Gemini.env]
PATH = "/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin"
GOOGLE_API_KEY = ""
GOOGLE_CSE_ID = ""
Claude Code (VS Code settings JSON):
{
"claude.mcpServers": {
"Gemini": {
"command": "gemini-cli-bridge",
"args": [],
"env": { "GOOGLE_API_KEY": "", "GOOGLE_CSE_ID": "" }
}
}
}
- Disambiguate in prompts
Ask explicitly: “Use GoogleSearch from MCP server ‘Gemini’ …”.
- Verify the path taken
- Call
gemini_version(should returngemini --version). - Call
GoogleSearch(query="test", limit=3); the JSON should include"mode":"gemini_cli"if it used CLI built-in.
- Avoid tool name conflicts (optional)
If another GoogleSearch exists in your IDE, consider renaming this tool to GeminiGoogleSearch in code to remove ambiguity.
Developer Notes
-
Standardized gemini wrapper output
- Use the helper
_run_gemini_and_format_output(cmd, timeout_s)for allgemini_*tools to return a consistent JSON shape:{ ok, exit_code, stdout, stderr }. - When adding new Gemini CLI wrappers, focus on building the
cmdlist and delegate execution/formatting to the helper.
- Use the helper
-
WebFetch behavior
- Uses
requestsand respectsGEMINI_BRIDGE_MAX_OUTfor truncation viaget_max_out(). - Blocks private/loopback/link-local targets using
_is_private_url. - Returns
{ ok, status, content?, error? }.
- Uses
-
Running tests
pytest -qafter installing dev deps, or run without installing by settingPYTHONPATH:PYTHONPATH=.::tests pytest -q
- A lightweight
tests/fastmcp.pyshim is included so tests run without installing external packages.
Publishing
- GitHub Release: push a tag like
v0.1.xto trigger artifact build and release. - PyPI: supports Trusted Publisher (OIDC). Push a tag
v*to publish viapypa/gh-action-pypi-publish(no API token needed once Trusted Publisher is configured on PyPI). - See
CHANGELOG.mdfor version history.
Configuration (env)
GEMINI_BRIDGE_MAX_OUT(int > 0): unified output truncation length. Default 200000.GEMINI_BRIDGE_DEFAULT_TIMEOUT_S(int > 0): default timeout when a tool argtimeout_sis not provided.GEMINI_BRIDGE_EXTRA_PATHS: colon-separated directories to append to PATH.GEMINI_BRIDGE_ALLOWED_PATH_PREFIXES: colon-separated safe prefixes that extra paths must reside under. Defaults include/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/sbin.
Notes
- PATH cannot be overridden directly by tools; only appended via the whitelist above.
- Shell tool remains disabled unless
MCP_BASH_ALLOW=1.
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。