/ 目錄 / 演練場 / gemini-mcp-tool
● 社群 jamubc ⚡ 即開即用

gemini-mcp-tool

作者 jamubc · jamubc/gemini-mcp-tool

讓 Claude 呼叫 Google Gemini CLI 進行大上下文檔案分析——將 Gemini 的百萬 token 視窗作為子程式使用。

jamubc/gemini-mcp-tool 將 Claude(或任何 MCP 客戶端)橋接至 Gemini CLI。提供三個工具:ask-gemini(使用 @ 語法進行檔案分析)、sandbox-test(在 Gemini 沙箱中執行程式碼)、Ping。可將大型檔案與大型程式碼庫的分析工作卸載至 Gemini 的 1M token 上下文。

為什麼要用

核心特性

即時演示

實際使用效果

gemini-mcp-tool.replay ▶ 就緒
0/0

安裝

選擇你的客戶端

~/Library/Application Support/Claude/claude_desktop_config.json  · Windows: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "gemini-mcp-tool": {
      "command": "npx",
      "args": [
        "-y",
        "gemini-mcp-tool"
      ],
      "_inferred": true
    }
  }
}

開啟 Claude Desktop → Settings → Developer → Edit Config。儲存後重啟應用。

~/.cursor/mcp.json · .cursor/mcp.json
{
  "mcpServers": {
    "gemini-mcp-tool": {
      "command": "npx",
      "args": [
        "-y",
        "gemini-mcp-tool"
      ],
      "_inferred": true
    }
  }
}

Cursor 使用與 Claude Desktop 相同的 mcpServers 格式。專案級設定優先於全域。

VS Code → Cline → MCP Servers → Edit
{
  "mcpServers": {
    "gemini-mcp-tool": {
      "command": "npx",
      "args": [
        "-y",
        "gemini-mcp-tool"
      ],
      "_inferred": true
    }
  }
}

點擊 Cline 側欄中的 MCP Servers 圖示,然後選 "Edit Configuration"。

~/.codeium/windsurf/mcp_config.json
{
  "mcpServers": {
    "gemini-mcp-tool": {
      "command": "npx",
      "args": [
        "-y",
        "gemini-mcp-tool"
      ],
      "_inferred": true
    }
  }
}

格式與 Claude Desktop 相同。重啟 Windsurf 生效。

~/.continue/config.json
{
  "mcpServers": [
    {
      "name": "gemini-mcp-tool",
      "command": "npx",
      "args": [
        "-y",
        "gemini-mcp-tool"
      ]
    }
  ]
}

Continue 使用伺服器物件陣列,而非映射。

~/.config/zed/settings.json
{
  "context_servers": {
    "gemini-mcp-tool": {
      "command": {
        "path": "npx",
        "args": [
          "-y",
          "gemini-mcp-tool"
        ]
      }
    }
  }
}

加入 context_servers。Zed 儲存後熱重載。

claude mcp add gemini-mcp-tool -- npx -y gemini-mcp-tool

一行命令搞定。用 claude mcp list 驗證,claude mcp remove 移除。

使用場景

實戰用法: gemini-mcp-tool

如何分析超出 Claude 上下文限制的大型檔案

👤 需要處理大型日誌、程式碼庫或文件的開發者 ⏱ ~15 min intermediate

何時使用: Claude 無法載入該檔案,但 Gemini 可以。

前置條件
  • Gemini CLI + Google API 金鑰 — npm i -g @google/gemini-cli;接著執行 gemini config set 並填入來自 aistudio.google.com 的金鑰
  • 安裝 MCP — claude mcp add gemini-cli -- npx -y gemini-mcp-tool
步驟
  1. 卸載分析任務
    ask-gemini: @/var/log/app-2026-04.log — find all 5xx errors clustered around deploys in the last 72h, produce a table.✓ 已複製
    → Gemini 完成分析並回傳精簡摘要
  2. 由 Claude 深入追蹤
    Based on Gemini's summary, focus on the cluster around 2026-04-12 14:30 UTC and propose a root cause.✓ 已複製
    → Claude 針對摘要進行推理

結果: 任何一個模型都無法單獨一次完成的分析結果。

注意事項
  • 將含有敏感資訊的日誌傳送給 Gemini — 呼叫 ask-gemini 前先移除個人識別資訊,或改用自架模型
  • 使用 Gemini Pro 處理大型輸入時的 token 費用 — 預設使用 Gemini Flash 以節省成本;僅在精確度有要求時才改用 Pro
搭配使用: filesystem

如何一次審閱整個小型程式碼庫

👤 對小型服務進行稽核的工程師 ⏱ ~20 min intermediate

何時使用: 你希望一次考量所有檔案,進行整體性審閱。

步驟
  1. 傳入整個專案庫
    ask-gemini: @./src/ — review for structural issues, repeated patterns that should be abstracted, and dead code.✓ 已複製
    → 涵蓋整個程式碼庫的觀察結果
  2. 篩選建議優先順序
    Of those, which 3 are highest impact? Name the files.✓ 已複製
    → 已排序優先順序的清單

結果: 一個 prompt 就完成審閱者的第一輪審查。

注意事項
  • Gemini 在處理超大型程式碼庫時會遺失細節 — 若你的 src/ 超過 500k token,請縮小範圍至子目錄
搭配使用: github

如何在 Gemini 沙箱中執行不受信任的程式碼

👤 需要測試不受信任程式碼片段的開發者 ⏱ ~5 min beginner

何時使用: 你想試跑某段程式碼,但不希望它碰觸到本機環境。

步驟
  1. 提交至沙箱
    sandbox-test: run this Python script [paste] — report stdout/stderr and exit code.✓ 已複製
    → 回傳執行結果,且不對本機產生任何副作用

結果: 安全的程式碼執行結果。

注意事項
  • 沙箱在多數情況下預設沒有網路連線 — 請查閱 Gemini CLI 沙箱文件了解網路連線選項

組合

與其他 MCP 搭配,撬動十倍槓桿

gemini-mcp-tool + filesystem

在本機選取檔案,再將 @ 引用傳給 Gemini

List all *.log files modified today via filesystem, then ask-gemini @ each to find anomalies.✓ 已複製
gemini-mcp-tool + github

將完整 diff 傳給 Gemini 的大上下文視窗以審閱 PR

Fetch PR #4421 diff via github MCP, then ask-gemini to critique the whole diff as one coherent change.✓ 已複製

工具

此 MCP 暴露的能力

工具輸入參數何時呼叫成本
ask-gemini prompt: str (may include @path refs), model?: 'flash'|'pro' 大上下文分析 Gemini API call — Flash ~$0.075/1M input, Pro higher
sandbox-test code: str, language? 執行不受信任的程式碼 Gemini sandbox billing
Ping 確認連線是否正常 free

成本與限制

運行它的成本

API 配額
Gemini AI Studio 提供免費方案;付費方案按 token 計費
每次呼叫 Token 數
用量龐大——這正是此工具的核心價值。請預估每次呼叫約消耗 100k–500k token。
費用
Gemini 2.5 Flash 約每 1M 輸入 token $0.075;Pro 約貴 20 倍
提示
預設使用 Flash。僅在 Flash 明顯出錯時才升級至 Pro。

安全

權限、密鑰、影響範圍

最小權限: Gemini API key
憑證儲存: Gemini CLI 將金鑰儲存於 ~/.config/gemini/
資料出站: 檔案內容會傳送至 Google Gemini;受 Google Gemini API 資料政策規範
切勿授予: Don't pass secrets in @-referenced files — they go straight to Google

故障排查

常見錯誤與修復

gemini-cli not found

全域安裝:npm i -g @google/gemini-cli;確認 npm 全域 bin 目錄已加入 PATH。

驗證: which gemini
401 from Gemini

執行 gemini config 並設定來自 aistudio.google.com 的 API 金鑰。

驗證: gemini 'hello'
Token limit exceeded

Gemini 本身也有上限;請減少 @ 引用的範圍,或先用搜尋縮小檔案範圍。

Sandbox timeout

長時間執行的程式碼需要更高的逾時設定;或改在本機容器中執行。

替代方案

gemini-mcp-tool 對比其他方案

替代方案何時用它替代權衡
deep-research MCP你需要的是自主研究功能,而非直接存取 Gemini使用方式不同;內建網路搜尋功能
openrouter MCP你希望用單一金鑰存取多個模型不支援 @ 檔案語法;大上下文情境下較不便利

更多

資源

📖 閱讀 GitHub 上的官方 README

🐙 查看未解決的 issue

🔍 瀏覽全部 400+ MCP 伺服器和 Skills