Skip to main content
Glama

gemini-local-mcp

中文说明 | English README

非官方开源项目声明(Disclaimer):本项目为社区独立开源工具,基于 Google 官方公开的 Gemini Connected Apps Model Context Protocol (MCP) 与 OAuth 2.1 标准构建,与 Google 官方无隶属或背书关系。

让 Google Gemini 桌面端(Gemini.exe)/ 网页版 / 手机 App 拥有媲美 Antigravity / Cursor 的本地 Windows 开发体验——代码、文件与命令全部留在你自己的 Windows 电脑本地执行,同时配备支持置顶画中画(PiP)与多对话归类的本地实时中文执行工作台。


核心特性

  • 100% 官方标准接入:基于 FastMCP(Streamable HTTP)+ 本机单用户 Keycloak(OAuth 2.1 + PKCE)+ Cloudflare Tunnel HTTPS 转发,兼容 Google Account Linking 表单/Basic 双鉴权与浏览器平滑回跳,零抓包、零逆向、零封号风险。

  • 19 项 Antigravity 级本地工具:

    • 高效只读探索(9 项,readOnlyHint: true):directory_tree(目录树,自动跳过 .git/node_modules/.venv)、search_text(全文/正则代码搜索)、search_names、file_outline(AST/正则符号行号大纲)、read_text(支持按行切片与行号,上限 256 KiB)、read_files_batch(单次并行读 12 个片段)、list_directory、file_info、read_file_chunk。

    • 精准局部与跨文件原子编辑(8 项,显著减少确认弹窗):edit_text(单文件多块局部替换,保留 CRLF/LF 并返回 unified diff)、apply_edits(单次原子编辑/新建最多 15 个文件,先全量校验、任一失败自动回滚,将多次确认合并为 1 次)、write_text、write_file_chunk、create_directory、copy_path、move_path(支持跨盘迁移)、recycle_path(移入 Windows 回收站)。

    • 本地终端执行(2 项):run_local_task(只读预设检查)+ run_command(UTF-8 无乱码 PowerShell / cmd 终端,超时自动清理整个子进程树)。

  • 产品级本地实时工作台 & 置顶悬浮窗(127.0.0.1:17662):

    • 彻底解决 Gemini Desktop 多步工具调用期间“黑盒看不见进度”的痛点;

    • 物理绑定 127.0.0.1 本地回环,绝不通过公网隧道暴露;

    • 支持 Chrome/Edge Document Picture-in-Picture 一键置顶悬浮小窗,主窗口与悬浮窗功能 100% 对等;

    • 支持按对话自动/手动归类(剥离系统自检、按项目目录与时间自动分流、➕ 新对话 切分、🔒 锁定当前对话、行内重命名、置顶、合并对话、单轮迁移、一键导出 Markdown 执行摘要)以及本地历史持久化。

  • 精细化安全边界:

    • 支持最小单目录沙箱(默认 ./pilot)、指定多目录白名单,或动态全盘模式(all_drives + 系统/密钥目录黑名单);

    • 强制屏蔽 MCP 自身程序与 .private 密钥目录、拦截 NTFS 符号链接/目录联接(Reparse Points)、UNC 路径及受保护父目录误删。

  • 开箱即用附属资产:内置可直接导入 Gemini Skills(技能) 面板的 gemini-skill/ 文件夹模板,以及兼容 Windows PowerShell 5.1 / PowerShell 7 的一键启停与单服务秒级热重载脚本 manage.ps1。


Related MCP server: OneCode Core

架构概览

Gemini Desktop / Web / Mobile
        │  HTTPS + OAuth 2.1 (PKCE)
        ▼
Cloudflare Tunnel (cloudflared)
        │  127.0.0.1 loopback only
        ├──► 127.0.0.1:17661  Keycloak (单用户本地身份认证)
        └──► 127.0.0.1:17658  FastMCP Server (server.py + drive_files.py)
                                   │
                                   └──► 127.0.0.1:17662  Live Activity HUD (仅本机可见,支持置顶悬浮窗)

快速开始

1. 环境准备

  1. Windows 10 / 11(自带 Windows PowerShell 5.1 或 PowerShell 7 均可)

  2. Python 3.12+

  3. 在仓库下的 bin/ 目录放置便携版运行组件(或使用系统 PATH 中已安装的版本):

    • JRE 21+(bin/jdk-*/bin/java.exe)

    • Keycloak(bin/keycloak-*/bin/kc.bat)

    • cloudflared(bin/cloudflared.exe)

  4. 一个托管在 Cloudflare 上的自定义子域名(如 https://mcp.yourdomain.com)并创建一条 Cloudflare Tunnel,配置两条公开主机名转发规则:

    • 路径 ^/identity/(realms/gemini/(protocol/openid-connect/auth/?$|login-actions/)|resources/) → http://127.0.0.1:17661

    • 默认路径 → http://127.0.0.1:17658

2. 安装 Python 依赖并初始化配置

python -m venv .venv
.\.venv\Scripts\pip install -r requirements.txt

# 生成 config.json 与默认安全的 file-scope.json(仅开放 ./pilot 目录)
.\scripts\init-config.ps1 -PublicUrl "https://mcp.yourdomain.com"

如需开启全盘动态模式(自动屏蔽系统与密钥目录),可加 -AllDrives 参数,或参考 file-scope.all-drives.example.json 自行定制 file-scope.json。

3. 配置本地凭据(保存在 .private/,已被 Git 忽略)

在 .private/ 目录下放置以下本机私密文件:

  • tunnel.token:Cloudflare Tunnel 运行令牌

  • identity-client.json:Keycloak gemini Realm 的客户端配置(含 client_id、client_secret、owner_subject、redirect_uri: "https://mcp.yourdomain.com/auth/callback")

  • owner-login.txt:Keycloak 单用户登录账号密码(Username: ... / Password: ...)

  • gemini-oauth-client.txt(可选推荐):为 Gemini 预注册的 OAuth Client ID: <uuid> 与 Client Secret: ...

4. 启动服务与打开实时置顶看板

.\manage.ps1 start           # 后台静默启动 Keycloak、MCP 服务与 Cloudflare 隧道
.\manage.ps1 status          # 查看进程状态、隧道连接数与 HUD 状态
.\manage.ps1 monitor         # 弹出本地实时执行工作台(点右上角「📌 置顶悬浮窗」即可钉在屏幕角落)
.\manage.ps1 restart mcp     # 修改代码或范围配置后秒级热重载 MCP(不断开隧道)
.\manage.ps1 stop            # 安全停止全部服务

如需开机登录 Windows 自动静默拉起:

$action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument "-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File `"$PWD\manage.ps1`" start"
$trigger = New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit ([TimeSpan]::Zero) -StartWhenAvailable
Register-ScheduledTask -TaskName 'GeminiLocalMcpAutoStart' -Action $action -Trigger $trigger -Settings $settings -Force

5. 在 Gemini 中关联并导入专属 Skill

  1. 打开 https://gemini.google.com → 设置 → 关联应用(Connected Apps)→ 添加自定义应用,填入 https://mcp.yourdomain.com/mcp(并在「其他设置」填入预注册的 Client ID / Secret),完成一次登录授权。

  2. 如更新过服务端工具列表,前往 Gemini Developer Mode → Tool schemas → 点击 Sync schema。

  3. 打开 Gemini 技能(Skills) 页面,直接将本仓库下的 gemini-skill 文件夹拖入上传框,即可获得 Antigravity 风格的分段汇报与批量编辑工作流。


本地自检与端到端验证

无需公网配置即可在克隆仓库后直接运行完整离线自检(覆盖全部 19 项工具、全盘敏感目录拦截、多对话工作台 API 与安全边界):

.\.venv\Scripts\python.exe .\verify_local.py

公网部署就绪后可运行完整 OAuth + PKCE + 令牌刷新 + 读写命令联调测试:

.\.venv\Scripts\python.exe .\verify_oauth.py --public --client-auth client_secret_post --browser-handoff

安全提示

  • 最小权限优先:初次部署建议保持默认的 file-scope.example.json(仅开放 ./pilot),确认流程熟悉后再按需扩大范围。

  • 审慎核对终端与写入确认弹窗:run_command 以当前 Windows 登录用户的权限执行 PowerShell / cmd 命令,不受文件工具路径黑名单约束;在 Gemini 弹出写入、删除或执行命令确认框时,请核对目标路径与命令内容后再点击允许。

  • 严禁提交 .private/:所有密钥、OAuth 状态与运行日志均存放在 .private/ 目录,已在 .gitignore 中默认排除。

开源协议

本项目基于 Apache License 2.0 开源。

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables the Gemini website, connected through Google's native custom MCP app, to list, read, create, edit and organize UTF-8 text files inside a user-chosen local folder on Windows. Access is bounded by a selected root, a workspace ID, a pause switch and read-only or read-and-edit permission, reached over a private HTTPS tunnel without needing a model API key.
      3
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Connects Gemini on the web to a user's own Windows PC, letting it read files, run commands, write to disk, and invoke local skills and other MCP plugins. It reaches the machine through a stable self-hosted Tailscale Funnel URL, with tools enabled and approved by the user.
      1
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables cloud AI clients such as Gemini and ChatGPT connectors to operate on a local Windows machine through nine MCP tools for reading, writing, editing files, running shell commands, and managing background jobs. Includes sandboxed root confinement, a command gate that blocks dangerous operations, token/OAuth authentication, a browser control panel, and a cloudflared tunnel for public access.
      1
      AGPL 3.0
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables Gemini web chat to access and control a local PC's files, search, Git, shell commands, and background processes across macOS, Windows, and Linux through an OAuth-secured MCP connector.
      5
      MIT