Skip to main content
Glama
gemini-agent-mcp
by fangzny1

中文 README

A remote MCP (Model Context Protocol) agent harness that lets Gemini Web or CLI clients inspect workspaces, read and edit files, track diffs, and execute shell commands on local machines behind NAT via a lightweight gateway and Go client binary.

Architecture

Gemini Web / CLI
   │  HTTPS (POST/GET /mcp/<deviceId>, Bearer or X-Gateway-Token)
   ▼
Gateway Server (Cloudflare Workers or self-hosted workerd)
   ├── RegistryHub (SQLite DO)  ── device list, clientToken, PBKDF2 admin password
   ├── RelayHub[deviceId] (SQLite DO + WebSocket Hibernation)
   │      ├── workspaces, diffs, command logs, pending approvals, device gatewayToken
   │      └── /ws/ui (live WebSocket updates to the web console)
   └── ASSETS (packages/web static bundle)
          ▲
          │  Outbound WSS (/ws/client, X-Client-Token + X-Device-Id)
          ▼
Local Go Client (gemini-mcp)
   └── ~/.gemini-mcp/config.json  ── serverUrl, clientToken, deviceId, mcpUrl, gatewayToken

Each connected machine receives its own deviceId, an isolated /mcp/<deviceId> endpoint, and a server-issued gatewayToken. Rotating or setting a custom device password in the web console updates the connected client's local configuration file automatically.

Related MCP server: agy-nexus-mcp

Server deployment

Option A: Cloudflare Workers

One-click deploy

Deploy to Cloudflare

During deployment, Cloudflare prompts for the secrets defined in .dev.vars.example:

  • ADMIN_PASSWORD: initial administrator password for the web console (can be changed later inside the WebUI).

  • CLIENT_TOKEN: pre-shared registration token used by local client binaries to connect via WebSocket.

  • SESSION_SECRET: HMAC-SHA256 key used to sign WebUI session cookies.

Manual deploy via Wrangler

npm install
npm run build

npx wrangler secret put ADMIN_PASSWORD
npx wrangler secret put CLIENT_TOKEN
npx wrangler secret put SESSION_SECRET

npx wrangler deploy

The root wrangler.jsonc runs the @gemini-mcp/shared and @gemini-mcp/web builds automatically before packaging the Worker and static assets.

Option B: Self-hosted outside Cloudflare (VPS / Docker)

The server runs on any Linux/macOS host or container using the open-source workerd runtime via Wrangler with local SQLite persistence, without requiring a Cloudflare account.

Run directly on a VPS

npm install
npm run build -w @gemini-mcp/shared && npm run build -w @gemini-mcp/web

cp .dev.vars.example .dev.vars
# Edit .dev.vars with your ADMIN_PASSWORD, CLIENT_TOKEN, and SESSION_SECRET

npm run start:server

This listens on 0.0.0.0:8787 and stores SQLite Durable Object state under ./data.

Run with Docker

cp .dev.vars.example .dev.vars
# Edit .dev.vars with your secrets

docker build -t gemini-agent-mcp .
docker run -d \
  --name gemini-agent-mcp \
  --restart unless-stopped \
  -p 8787:8787 \
  -v "$(pwd)/data:/app/data" \
  -v "$(pwd)/.dev.vars:/app/.dev.vars:ro" \
  gemini-agent-mcp

Reverse proxy notes

Gemini Web requires HTTPS for remote MCP endpoints. Place Caddy, Nginx, or Traefik in front of port 8787 with WebSocket upgrade enabled and X-Forwarded-Proto / X-Forwarded-Host headers forwarded so the gateway assigns public https:// MCP URLs to connecting clients.

Example Caddyfile:

mcp.example.com {
  reverse_proxy 127.0.0.1:8787
}

Client usage

Download prebuilt binaries

Prebuilt static binaries for windows/amd64, linux/amd64, linux/arm64, and linux/armhf are published on GitHub Releases.

Example on Linux (amd64):

curl -fsSL -o gemini-mcp https://github.com/XTxiaoting14332/gemini-agent-mcp/releases/latest/download/gemini-mcp-linux-amd64
chmod +x gemini-mcp
sudo mv gemini-mcp /usr/local/bin/gemini-mcp

First-run setup and configuration

Run the binary with flags once, or run gemini-mcp in an interactive terminal to follow the prompt:

gemini-mcp \
  --url https://your-gateway.example.com \
  --token <CLIENT_TOKEN> \
  --name workstation

On connection, the server assigns deviceId, mcpUrl, and gatewayToken, writes them to ~/.gemini-mcp/config.json (mode 0600), and prints the assigned endpoint and password to stdout. Subsequent runs only require:

gemini-mcp

To use a custom config file path or update connection fields:

gemini-mcp --config /path/to/config.json
gemini-mcp init --url https://your-gateway.example.com --token <CLIENT_TOKEN> --name server-01

Gemini MCP configuration

Gemini Web (gemini.google.com)

In Gemini Web under custom MCP server connections (Connect to MCP server), the gateway exposes OAuth 2.1 discovery (/.well-known/oauth-protected-resource, /.well-known/oauth-authorization-server) and PKCE authorization (/oauth/authorize, /oauth/token):

  1. MCP Server URL: https://your-gateway.example.com/mcp/<deviceId>

  2. Expand Other settings (optional if using dynamic client registration, or fill directly from the WebUI Overview tab):

    • Client ID (OAuth Client ID): <deviceId>

    • Client Secret (OAuth Client Secret): <DEVICE_GATEWAY_TOKEN>

  3. Click Next and approve access on the gateway authorization page using your device password (<DEVICE_GATEWAY_TOKEN>) or WebUI admin password.

Gemini CLI / Gateway clients

Clients that support custom HTTP headers can connect directly using static Bearer or gateway headers:

{
  "mcpServers": {
    "workstation": {
      "httpUrl": "https://your-gateway.example.com/mcp/<deviceId>",
      "headers": {
        "Authorization": "Bearer <DEVICE_GATEWAY_TOKEN>",
        "X-Gateway-Token": "<DEVICE_GATEWAY_TOKEN>"
      }
    }
  }
}

Command policy and security

  • Workspace sandboxing: file operations (list_dir, find_files, read_file, write_file, edit_file, delete_file, grep_search, git_status, git_diff) and run_command working directories are validated on the client against enabled workspace paths registered in the WebUI using symlink-aware realpath resolution.

  • auto mode (default): run_command requires risk_level (safe, moderate, or high) and risk_reason, combined with deterministic server-side pattern escalation in packages/shared/src/risk.ts (rm -rf, sudo, piped remote scripts, git push --force, etc.). safe commands execute immediately; moderate and high commands pause with APPROVAL_REQUIRED and an approval_id, requiring user confirmation in chat (允许 / 拒绝) or via the WebUI Commands tab.

  • bypass mode: executes workspace commands directly without approval prompts while still recording stdout, stderr, exit codes, and duration.

  • Credential storage: the WebUI administrator password is stored as a salted PBKDF2-SHA256 hash inside RegistryHub SQLite. Changing the password in WebUI Settings increments the password version and invalidates prior session cookies.

Repository layout

.github/workflows/   CI checks and multi-arch client release workflow
packages/
  shared/            shared TypeScript protocol types, MCP tool schemas, risk classifier
  worker/            gateway router, MCP Streamable HTTP handler, RelayHub & RegistryHub DOs
  web/               React + Vite + Tailwind CSS v4 web console
  client-go/         standalone Go client binary (cmd/gemini-mcp)
  client/            Node.js/TypeScript reference client and esbuild single-file bundle
scripts/             end-to-end integration test against local wrangler dev
Dockerfile           self-hosted container image using workerd + local SQLite persistence
wrangler.jsonc       root Workers configuration for one-click, CLI, and self-hosted runs

Development

Requirements: Node.js 20+ (tested on Node 22) and Go 1.24+.

npm install
npm run build
npm run typecheck

Run the end-to-end integration test (starts local wrangler dev, connects both the Go binary and Node bundle clients simultaneously, and verifies auth, multi-device isolation, diffs, auto approval, and bypass execution):

npm test

Cross-compile all release binaries locally:

npm run build:binary-all

License

Source code is licensed under the GNU General Public License v3.0 (GPL-3.0); see LICENSE.

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
      C
      maintenance
      Enables Google Gemini to autonomously read, write, search, and patch code files and run whitelisted developer commands inside a sandboxed local workspace for edit-and-verify coding workflows.
      1
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables Google Gemini on web or mobile to connect to a local Antigravity IDE/CLI workstation, letting users browse and manage coding sessions, inspect paused approvals, search and read repository files, audit git changes, send handoffs that resume the right project chat, and view ASCII usage telemetry or a live web dashboard.
      12
      AGPL 3.0
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables Gemini Web to securely connect to local code repositories and terminal toolchains through Streamable HTTP MCP, hardened OAuth 2.1, and Cloudflare Tunnel support, with low-RTT batch tools for searching, reading, editing, and executing commands.
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Enables Gemini on the web and the local Gemini app to read files, search code, and run commands on the user's computer through a locally running HTTP or stdio MCP server. Connections reach the machine over Tailscale Funnel, a Cloudflare tunnel, or a custom HTTPS reverse proxy, with OAuth approval, write-session claiming, and confirmation for destructive commands.
      13
      11
      MIT