Skip to main content
Glama
README.md
# gemini-win-bridge

[English](README.md) | [中文](README.zh-CN.md)

A Windows-native MCP server that lets the web version of Gemini read and
write local files and run commands inside your workspaces. Remote access
works over three connection options (Tailscale, a Cloudflare quick tunnel,
or your own public base URL), and every dangerous command must be approved
by the owner before it runs.

## Features

- **12 MCP tools** — `read_file`, `write_file`, `edit_file`, `list_dir`,
  `grep_search`, `find_by_name`, `run_command`, `manage_task`, `execute`,
  `poll_execution`, `cancel_execution`, `server_info`.
- **Workspace whitelist plus sensitive-path blacklist** — file tools only
  touch paths inside the configured roots and never touch credential
  directories (`.ssh`, `.aws`, ...).
- **Dangerous-command interception in three shell grammars** — the command
  line is parsed (not string-searched) for Git Bash, PowerShell and cmd
  syntax, including wrappers, variable expansion and nested shells.
- **Owner approval page at `/web`** — a blocked command creates a pending
  approval; the owner approves it in the browser and the model retries with
  `Confirm=true`.
- **Per-session write claims and an audit log** — two sessions never write
  the same path, and the last 200 tool calls are recorded.
- **Code Mode (`execute`)** — sandboxed Python snippets with tool callbacks
  for batch, multi-file operations.
- **OAuth 2.1 for remote connections** — dynamic client registration and a
  password-based consent page, no external identity provider needed.
- **Interactive TUI wizard and a single-file exe** — one `gwb` command
  configures everything; the release build needs no Python installed.

## Requirements

- Windows 11 (Windows 10 also works).
- Python 3.12+ — only needed for a source install; the release exe is
  self-contained.
- Git for Windows — provides the default `git-bash` shell the command tools
  run in.
- Optional, for remote access: [Tailscale](https://tailscale.com) or
  [cloudflared](https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/installation/).

## Installation

**A) Release exe (recommended)**

1. Download `gwb-windows-x86_64.exe` from the GitHub Releases page.
2. Rename it to `gwb.exe` and put the folder on your `PATH`.
3. The exe is unsigned, so the first launch shows a SmartScreen warning —
   choose "More info" → "Run anyway".

**B) From source**

```
pip install git+https://github.com/shiyuanzheng/gemini-win-bridge
```

or with uv:

```
uv tool install git+https://github.com/shiyuanzheng/gemini-win-bridge
```

This requires Python 3.12+ and Git for Windows on the `PATH`.

## Quick start

1. Start the wizard with `gwb` (no arguments), or go headless:

   ```
   gwb init --workspace D:\code --connect local
   ```

   The first run prints the generated **owner password** — shown once, save
   it now.

2. Check the environment:

   ```
   gwb doctor
   ```

   All checks should be green. A missing tunnel binary is fine for
   `local`; it only matters for remote modes.

3. Start the server:

   ```
   gwb serve
   ```

   It prints the MCP URL (local mode: `http://127.0.0.1:7676/mcp`) and the
   approval page (`http://127.0.0.1:7676/web`).

4. Register the connector in Gemini: open
   `gemini.google.com/customize/connectors`, create a new connector, and
   paste the MCP URL. Leave **Client ID** and **Client Secret empty**. When
   the consent page opens, paste the owner password.

5. In a Gemini conversation, mention the connector with `@` and start
   working on your files.

## Connection modes

| Mode | Listens on | Public URL | Notes |
|------|------------|------------|-------|
| `local` | `127.0.0.1` | none, no OAuth | for local MCP clients on the same machine |
| `tailscale` | `127.0.0.1` | `tailscale funnel --bg --yes <port>` → `https://<DNSName>/mcp` | enable Funnel and HTTPS certificates in the Tailscale admin console; stable address |
| `cloudflare` | `127.0.0.1` | `cloudflared tunnel --url http://127.0.0.1:<port>` → `https://*.trycloudflare.com/mcp` | the trycloudflare URL changes on every restart; update the connector afterwards |
| `public` | `0.0.0.0` | `publicBaseUrl` (required, `https://`) | you provide the reverse proxy and certificate |

Google binds connectors by hostname: one hostname can only carry one
connector. If `serve` prints a new public hostname, remove the old
connector registration in Gemini first.

## Configuration

Show, locate or change `config.json`:

```
gwb config show
gwb config path
gwb config set shell=powershell
```

| Key | Default | Meaning |
|-----|---------|---------|
| `workspace` | your home directory | allowed roots; repeatable (`gwb init --workspace A --workspace B`) |
| `connect` | `local` | `local` / `tailscale` / `cloudflare` / `public` |
| `listenPort` | `7676` | first port tried; occupied ports walk up (max 10 tries) |
| `listenHost` | `127.0.0.1` | bind address (`public` mode forces `0.0.0.0`) |
| `publicBaseUrl` | empty | required for `connect=public`, must be `https://` |
| `shell` | `git-bash` | shell for `run_command`: `git-bash` / `powershell` / `cmd` |
| `language` | auto | UI language: `en` / `zh` |
| `holdMs` | `45000` | how long `manage_task` waits for a running task (500–55000) |

Everything lives in `%USERPROFILE%\.gemini-win-bridge` (override with the
`GWB_CONFIG_DIR` environment variable): `config.json`, `auth.json` (the
owner password hash), `clients.json` (registered OAuth clients) and
`server.pid` (the running instance).

## Command reference

| Command | One-liner |
|---------|-----------|
| `gwb` | no arguments: the interactive setup wizard (needs a TTY) |
| `gwb init [--workspace DIR] [--connect MODE] ...` | write `config.json` and print the registration steps |
| `gwb setup` | run the setup wizard explicitly |
| `gwb doctor` | run the environment health checks |
| `gwb password [--set VALUE]` | generate or set the owner password |
| `gwb url` | print the MCP URL for the configured mode |
| `gwb status` | report the running server (pid, port, URL) |
| `gwb stop` | stop the running server and its process tree |
| `gwb config show\|path\|set key=value` | inspect or change `config.json` |
| `gwb serve [--port N] [--no-tunnel]` | start the MCP server, local or tunneled |
| `gwb stdio` | run the MCP server on stdio (for local clients) |

## Tools

| Tool | One-liner |
|------|-----------|
| `read_file` | read a text or binary file slice (max 800 lines / 45 KB per call; images inlined) |
| `write_file` | create, overwrite (atomic) or append to a file |
| `edit_file` | exact-match replace that preserves the file's line endings and BOM |
| `list_dir` | list one directory (max 500 entries) |
| `grep_search` | text or regex search (max 100 hits) |
| `find_by_name` | glob file-name search (max 100 hits) |
| `run_command` | run a shell command with a wait window, background tasks and input |
| `manage_task` | status, output, input or kill for background tasks |
| `execute` | Code Mode: run a sandboxed Python snippet with tool callbacks |
| `poll_execution` | fetch a Code Mode execution's log and result |
| `cancel_execution` | cancel a running Code Mode execution |
| `server_info` | report the server version, public URL and workspace roots |

## Security model

**Workspace whitelist.** File tools resolve every path to its real form
(symlinks, junctions, 8.3 short names, subst drives, `\\?\` prefixes and
case tricks all normalize) and reject anything outside the configured
roots. Relative paths are always rejected.

**Sensitive-path blacklist.** These locations are never readable or
writable, even when they sit inside a workspace root: `.ssh`, `.gnupg`,
`.aws`, `.kube`, `.docker`, `.gemini`, `.azure`, `.password-store`,
`.config/gh`, `.config/gcloud`, `.config/configstore`, `.config/op`,
`.local/share/keyrings`, `.netrc`, `.git-credentials`, `.pypirc`,
`.npmrc` (each under `%USERPROFILE%`), plus
`%APPDATA%\Microsoft\Credentials`,
`%LOCALAPPDATA%\Microsoft\Credentials` and the gwb config directory
itself.

**Dangerous commands.** The command line is parsed per the configured
shell and matched against rule tables for recursive deletion
(`rm -rf`, `Remove-Item -Recurse`, `del /s /q`, PowerShell aliases like
`ri`/`rm`/`rd`/`del`/`erase`), disk tools (`mkfs`, `format`,
`diskpart`, `Format-Volume`), power (`shutdown`, `Stop-Computer`), risky
git operations (`git reset --hard`, `git clean -f`, `git push --force`,
config/env injection), and dynamic execution (`find -exec`, `xargs`,
`Invoke-Expression`). Encoded or nested variants
(`powershell -EncodedCommand`, `cmd /c ...` inside bash) are decoded and
re-parsed. The tables cannot enumerate every possible spelling — see the
known limitations in `docs/acceptance.md`.

**Approval flow.** A blocked command is refused with a pending approval
id. The owner reviews it at the `/web` page (login with the owner
password) and approves or denies it. Approval is valid for 5 minutes, for
that exact command string, and is consumed once: the model retries the
identical command with `Confirm=true`.

**stdio mode.** There is no HTTP server and no approval page, so
dangerous commands are never available in `gwb stdio`; the refusal message
says so and points at `gwb serve`.

**Audit.** The last 200 tool calls (name, arguments, outcome, truncated
output) are kept in memory and shown on the `/web` page.

## Autostart (optional, off by default)

gwb never registers itself anywhere. To start the server at logon, create
a Windows scheduled task yourself:

```
schtasks /create /tn "gwb serve" /tr "\"C:\path\to\gwb.exe\" serve" /sc onlogon
```

The server is a normal foreground process launched by Task Scheduler, so
its console output is not visible. `gwb stop` stops it like any other
instance. Remove the task with:

```
schtasks /delete /tn "gwb serve" /f
```

## Troubleshooting

- **`doctor` is all green but Gemini cannot connect** — Google binds
  connectors by hostname. If this hostname already carries another
  connector, requests fail with 401: remove the old registration in
  `gemini.google.com/customize/connectors` and register again.
- **401 in a tunnel mode after a restart** — access tokens are held in
  memory only; after a server restart Gemini must re-authorize once (paste
  the owner password on the consent page again). This is a known
  limitation.
- **`port taken`** — serve walks up from `listenPort` and picks the next
  free port (max 10 tries). The actual port is authoritative in
  `gwb status`; pin it with `gwb config set listenPort=<n>`.
- **Code Mode `SnippetRejected`** — snippets only see whitelisted
  builtins; `await` is only allowed inside `tools.<name>(...)` calls;
  `import` is banned; use f-strings instead of the `str.format` family;
  the injected names (`tools`, `json`, `print`) cannot be rebound.
- **Very long paths still fail** — the exe manifest already declares
  `longPathAware`, but the *system* policy must allow it too: set
  `LongPathsEnabled` to 1 under
  `HKLM\SYSTEM\CurrentControlSet\Control\FileSystem` (or via Group
  Policy) and reboot.
- **Tunnel binary missing** — `doctor` reports the exact winget install
  command; gwb never installs anything itself.
- **Daemon command with `shell=powershell`** — PowerShell ignores the
  detach flag, so `IsDaemon=true` degrades to a normal run there; the
  default `git-bash` shell is unaffected.

## Uninstall

1. `gwb stop` (if a server is running).
2. Delete `%USERPROFILE%\.gemini-win-bridge` (the config, password hash,
   OAuth clients and audit log).
3. Delete `gwb.exe`, or `pip uninstall gemini-win-bridge` / 
   `uv tool uninstall gemini-win-bridge`.
4. If you configured autostart: `schtasks /delete /tn "gwb serve" /f`.

## Development

```
uv sync
uv run pytest -q
uv run python scripts/build_exe.py
uv run python scripts/smoke_exe.py dist/gwb.exe
```

The full test suite runs on Windows (that is the target platform); CI runs
test → build → release on `windows-latest`. License: MIT — see
[LICENSE](LICENSE).