Skip to main content
Glama
README.md
# Gemini Web Bridge MCP

An MCP server that lets coding agents use **Gemini Pro through the Gemini web app** — no Gemini API key, no per-token billing, and no separate "API" account.

It drives a real Chrome/Chromium session through a small extension. The agent calls one MCP tool, the extension types the prompt into Gemini, waits for the answer, and returns it. It also supports **file upload** and **downloading generated images/files**.

> This is an unofficial browser bridge. It is not affiliated with Google. Use it only with an account you are allowed to use this way, and review the security and terms-of-service notes below.

Based on [Walkoud/gemini-browser-mcp](https://github.com/Walkoud/gemini-browser-mcp) (MIT), with substantial changes: file transfer, multi-workspace proxy support, loopback-only binding, automatic content-script injection, longer response stabilization, and Linux server tooling.

---

## Contents

- [Features](#features)
- [How it works](#how-it-works)
- [Requirements](#requirements)
- [Quick start: Windows / macOS desktop](#quick-start-windows--macos-desktop)
- [OpenCode configuration](#opencode-configuration)
- [Linux server guide](#linux-server-guide)
  - [Option A: Chrome on your laptop + SSH tunnel](#option-a-chrome-on-your-laptop--ssh-tunnel-recommended-for-headless-servers)
  - [Option B: Chrome on the server with Xvfb + VNC](#option-b-chrome-on-the-server-with-xvfb--vnc)
  - [Run the background browser as a systemd user service](#run-the-background-browser-as-a-systemd-user-service)
- [Tool reference](#tool-reference)
- [File transfer](#file-transfer)
- [Architecture details](#architecture-details)
- [Security and privacy](#security-and-privacy)
- [Limitations](#limitations)
- [Troubleshooting](#troubleshooting)
- [Development](#development)
- [Attribution and license](#attribution-and-license)

---

## Features

- **No Gemini API key** — uses the same web session you use manually.
- **Per-session chats** — every MCP server process (one per agent session) gets its own Gemini tab and chat, so concurrent sessions never share a conversation. Messages to one tab are serialized, and the tab is activated while its prompt runs.
- **High thinking by default** — prompts select High thinking unless you explicitly ask for another level. The extension verifies the selected model/thinking in Gemini's own selector.
- **File upload** — pass local file paths to the tool; text, code, PDF, images, documents, etc. are attached and the bridge waits for Gemini's upload chip before sending.
- **Download generated files** — images and downloadable links from Gemini's response are saved to a local directory and returned as file paths.
- **Multi-workspace safe** — one bridge owns port `8085`; other OpenCode workspaces automatically become proxies instead of fighting for the port.
- **Loopback-only by default** — the WebSocket bridge binds `127.0.0.1` and rejects non-loopback clients unless explicitly allowed.
- **Automatic recovery** — a failed submission is retried once after a page reload; a timed-out prompt reloads the tab and restores High thinking. `refresh_gemini_chat` does the same on demand.
- **Linux server support** — run Chrome under Xvfb, or keep Chrome on your laptop and tunnel port `8085` to the server.
- **OpenCode, Claude Code, and any MCP client** — the server is a standard stdio MCP server.

---

## How it works

```
┌────────────────────┐        stdio MCP         ┌──────────────────────────┐
│ OpenCode / agent   │ ◄──────────────────────► │  server.js (MCP server)  │
└────────────────────┘                          │  owner on 127.0.0.1:8085 │
                                                └────────────┬─────────────┘
                                                             │ WebSocket
                                                             │ (loopback)
                                                ┌────────────▼─────────────┐
                                                │ Chrome extension          │
                                                │ background + content.js   │
                                                └────────────┬─────────────┘
                                                             │ DOM automation
                                                ┌────────────▼─────────────┐
                                                │ Gemini web app            │
                                                │ gemini.google.com/app     │
                                                └──────────────────────────┘
```

1. OpenCode starts `server.js` over stdio.
2. `server.js` opens a WebSocket server on `127.0.0.1:8085`.
3. The Chrome extension connects to that WebSocket and identifies itself.
4. When the agent calls `ask_gemini_web`, the server sends the prompt (and optional file payloads) to the extension.
5. The content script clears Gemini's Quill composer, attaches files, pastes the prompt through Quill's clipboard path, clicks the real Send host, and waits for the conversation turn that belongs to this prompt.
6. The response text and any generated attachments are sent back over the WebSocket. The MCP server returns the text and writes attachments to disk.

### Multi-workspace proxy mode

OpenCode can load the same MCP server for several workspaces. Only one process can bind port `8085`. The first process becomes the **owner**; later processes detect `EADDRINUSE`, switch to **proxy mode**, connect to the owner, and relay their tool calls through it. If the owner disappears, proxies attempt to take over after repeated failures.

### Response timing

- **High thinking (default):** up to 9 minutes for the answer; the first response turn must appear within 75 seconds.
- **Other thinking levels:** up to 4.7 minutes for the answer.
- The bridge waits for a 1.2-second stable answer, but only after it has seen this prompt's conversation turn generate or change from the previous answer. This prevents returning a stale answer from the previous turn.
- A submission that is not accepted is retried once after a page reload. A prompt that hits the bridge timeout reloads the tab and restores High thinking.
- Server-side request timeout: 12 minutes (content stops first at 9 minutes).
- Generated attachments are fetched in parallel, and timing logs (`[Gemini Bridge] ... +Nms`) are written to the page console. Prompt and response text are not logged.

The stability window and timeouts are in `chrome-extension/content.js`.

---

## Requirements

- **Node.js 20 or newer**
- **Chrome, Chromium, Brave, or another Chromium-based browser**
- The Gemini Bridge extension loaded in that browser
- A Google account with access to Gemini (Pro recommended)
- For Linux servers: Xvfb and x11vnc for the one-time login (or use the SSH tunnel option)

---

## Quick start: Windows / macOS desktop

### 1. Clone and install

```bash
git clone https://github.com/Zaltapar/gemini-web-bridge-mcp.git
cd gemini-web-bridge-mcp
npm install
```

### 2. Load the extension

1. Open `chrome://extensions`
2. Enable **Developer mode**
3. Click **Load unpacked**
4. Select the `chrome-extension/` folder from this repository

### 3. Log in to Gemini

1. Open `https://gemini.google.com/app`
2. Log in with the account that has Gemini Pro
3. Set the model to **Hydrogen** (or Neon/Carbon if your account offers them) and thinking to **High**. The bridge defaults to High for prompts.
4. Keep the tab open

### 4. Configure OpenCode

Add this to `~/.config/opencode/opencode.jsonc` (Linux/macOS) or `C:\Users\<you>\.config\opencode\opencode.jsonc` (Windows):

```jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "servers": {
      "gemini": {
        "type": "local",
        "command": [
          "node",
          "C:\\path\\to\\gemini-web-bridge-mcp\\server.js"
        ]
      }
    }
  }
}
```

Alternatively, with the OpenCode CLI:

```bash
opencode mcp add gemini --global -- node /absolute/path/to/gemini-web-bridge-mcp/server.js
opencode mcp list
```

### 5. Test

Ask OpenCode:

> Use `ask_gemini_web` to reply with exactly: BRIDGE_OK

You should get `BRIDGE_OK`.

### 6. Keep Chrome running

The extension needs a Gemini tab. You can minimize Chrome; you do not need to interact with it while the MCP is working. If you close the tab or Chrome, open Gemini again.

---

## OpenCode configuration

Minimal global config:

```jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "servers": {
      "gemini": {
        "type": "local",
        "command": ["node", "/opt/gemini-web-bridge-mcp/server.js"],
        "environment": {
          "GEMINI_BRIDGE_HOST": "127.0.0.1",
          "GEMINI_BRIDGE_PORT": "8085"
        }
      }
    }
  }
}
```

Environment variables:

| Variable | Default | Description |
|---|---|---|
| `GEMINI_BRIDGE_HOST` | `127.0.0.1` | Bind address for the WebSocket bridge. Keep loopback unless you have a specific reason. |
| `GEMINI_BRIDGE_PORT` | `8085` | Owner/proxy port. The extension's `BRIDGE_URL` must match the owner's port. A laptop proxy may use a different local port that an SSH tunnel forwards to the owner. |
| `GEMINI_BRIDGE_ALLOW_REMOTE` | unset | Set to `1` to allow non-loopback WebSocket clients. Dangerous; prefer an SSH tunnel. |
| `GEMINI_BRIDGE_DAEMON` | unset | Set to `1` to run only the WebSocket owner (no stdio MCP transport). Used by `gemini-bridge-owner.service`. |
| `GEMINI_BRIDGE_PROXY_ONLY` | unset | Set to `1` to never bind a port; the process only retries an existing owner. Use this on a laptop that reaches the owner through an SSH tunnel. |
| `GEMINI_BRIDGE_LOG` | `server.log` | Log file path. Each line includes the process PID. |
| `GEMINI_AUTO_RECOVER` | unset | Set to `0` to disable automatic tab reload after a prompt times out. |

Project-local config works the same way in any `opencode.json(c)` or `.opencode/opencode.json(c)` discovered by OpenCode.

---

## Linux server guide

See **[docs/LINUX.md](docs/LINUX.md)** for a longer copy-paste guide, including systemd, VNC, dedicated users, and firewall notes.

### Linux desktop with a GUI

If your Linux machine has a normal desktop session, Chrome runs natively. You do **not** need Xvfb or VNC:

1. Install Google Chrome or Chromium.
2. Load `chrome-extension/` at `chrome://extensions`.
3. Open `https://gemini.google.com/app`, log in, and select Pro.
4. Install and configure the MCP as usual:

```bash
cd /opt/gemini-web-bridge-mcp
npm install
opencode mcp add gemini --global -- node /opt/gemini-web-bridge-mcp/server.js
```

That is the whole setup. Xvfb is only needed when there is no display at all.

### Headless Linux server

There are two reliable ways to run this on a headless Linux server:

1. **Recommended for headless servers:** Chrome runs on your laptop/desktop; the server runs OpenCode and the MCP bridge; an SSH tunnel connects the extension to the server.
2. **Chrome on the server:** Chrome runs under Xvfb on the server. Log in once with VNC, then keep it running headlessly.

### Option A: Chrome on your laptop + SSH tunnel (recommended for headless servers)

This is the easiest and most reliable setup if your server has no desktop environment. Chrome stays on your machine, where you can see and log in normally. Only the WebSocket is tunneled.

#### On the server

```bash
sudo apt update
sudo apt install -y nodejs npm
# Node 20+ is recommended. If your distro ships an older Node, use nvm or NodeSource.

git clone https://github.com/Zaltapar/gemini-web-bridge-mcp.git /opt/gemini-web-bridge-mcp
cd /opt/gemini-web-bridge-mcp
npm install

opencode mcp add gemini --global -- node /opt/gemini-web-bridge-mcp/server.js
opencode mcp list
```

#### On your laptop

1. Load `chrome-extension/` as an unpacked extension in Chrome.
2. Open `https://gemini.google.com/app`, log in, select Pro.
3. Create an SSH tunnel from your laptop to the server:

```bash
ssh -N -L 8085:127.0.0.1:8085 user@your-server.example.com
```

Keep that SSH session open. The extension connects to `ws://127.0.0.1:8085` on your laptop, which is forwarded to the MCP bridge on the server.

4. Start OpenCode on the server and test:

> Use `ask_gemini_web` to reply with exactly: TUNNEL_OK

If the tunnel is up and Chrome has a Gemini tab open, this works exactly like the desktop setup.

> Windows laptop: use the same `ssh -L 8085:127.0.0.1:8085 user@server` command in PowerShell, or configure an equivalent tunnel in PuTTY.

### Option B: Chrome on the server with Xvfb + VNC

Use this when you want the server to be fully self-contained.

#### 1. Install system packages

Debian/Ubuntu:

```bash
sudo apt update
sudo apt install -y nodejs npm xvfb x11vnc
```

For a newer Node.js, install Node 20+ via nvm or NodeSource. Then:

```bash
git clone https://github.com/Zaltapar/gemini-web-bridge-mcp.git /opt/gemini-web-bridge-mcp
cd /opt/gemini-web-bridge-mcp
npm install
chmod +x linux/*.sh
```

#### 2. One-time login through VNC

Run:

```bash
./linux/login.sh
```

The script starts:

- Xvfb on virtual display `:99`
- x11vnc on `127.0.0.1:5900` (localhost only)
- Chrome with the extension and `gemini.google.com/app`

From your laptop, tunnel the VNC port:

```bash
ssh -L 5900:127.0.0.1:5900 user@your-server.example.com
```

Then open a VNC viewer at `127.0.0.1:5900` (macOS: Finder → Go → Connect to Server → `vnc://127.0.0.1:5900`). Log in with the Google account that has Gemini Pro. Close the Chrome window and press Enter in the terminal.

The Chrome profile is stored at:

```
~/.local/share/gemini-web-bridge/chrome-profile
```

It contains the login session. Treat it as a secret.

#### 3. Start the background browser

```bash
./linux/start-browser.sh
```

This starts Chrome under Xvfb with the extension and a Gemini tab, minimized/offscreen. You do not need a monitor.

#### 4. Configure OpenCode

```bash
opencode mcp add gemini --global -- node /opt/gemini-web-bridge-mcp/server.js
opencode mcp list
```

Or use `linux/opencode.json.example` as a starting point.

#### 5. Test

> Use `ask_gemini_web` to reply with exactly: SERVER_OK

#### Stop the browser

```bash
./linux/stop-browser.sh
```

### Run the background browser as a systemd user service

Copy the unit file and adjust the path if needed:

```bash
mkdir -p ~/.config/systemd/user
cp linux/gemini-browser.service ~/.config/systemd/user/
# Edit ExecStart if you cloned somewhere other than ~/gemini-web-bridge-mcp
systemctl --user daemon-reload
systemctl --user enable --now gemini-browser.service
systemctl --user status gemini-browser.service
```

Logs:

```bash
journalctl --user -u gemini-browser.service -f
```

The service runs Chrome under Xvfb. The separate `gemini-bridge-owner.service` runs the persistent bridge owner; OpenCode MCP processes and laptop proxies connect to it.

### Laptop OpenCode with Chrome on a server (recommended)

Use this when Chrome and the Gemini login run on a server, and OpenCode runs on your laptop. The bridge owner is a persistent systemd service on the server; the laptop reaches it through an SSH tunnel and runs in proxy-only mode.

On the server:

```bash
sudo REPO_DIR=/opt/gemini-web-bridge-mcp ./linux/install-bridge-owner.sh
# The unit uses /usr/local/bin/node. Adjust ExecStart if `command -v node` differs.
systemctl is-active gemini-bridge-owner
ss -ltnp | grep 8085          # must be 127.0.0.1:8085 only
```

Make sure Chrome and the extension are running and logged in. The owner survives OpenCode restarts; remote OpenCode MCP processes automatically become proxies to it.

On the laptop (Windows):

```powershell
powershell -ExecutionPolicy Bypass -File scripts\install-laptop-tunnel.ps1 -RemoteHost your-server -LocalPort 18085
```

This installs a Startup shortcut and starts:

```text
ssh -N -L 127.0.0.1:18085:127.0.0.1:8085 your-server
```

On Linux/macOS, add the equivalent SSH command to your startup. Then add the MCP server to OpenCode:

```jsonc
{
  "mcp": {
    "servers": {
      "gemini-web-bridge": {
        "type": "local",
        "command": ["node", "/absolute/path/to/gemini-web-bridge-mcp/server.js"],
        "environment": {
          "GEMINI_BRIDGE_PORT": "18085",
          "GEMINI_BRIDGE_PROXY_ONLY": "1"
        },
        "protocol": "legacy"
      }
    }
  }
}
```

`GEMINI_BRIDGE_PROXY_ONLY=1` prevents the laptop process from binding a local port and becoming an owner when the tunnel is down; it returns a clear proxy error instead.

Test the laptop path:

```bash
GEMINI_BRIDGE_PORT=18085 node tests/smoke.mjs
# status should report bridgeMode: "proxy", extensionConnected: true
```

The request path is: laptop MCP proxy → SSH tunnel → server loopback owner → extension → Chrome. No inbound port is opened; both ends of the tunnel are loopback and SSH encrypts the traffic.

### Chrome on a laptop with OpenCode on a server

If you run Chrome on machine A and OpenCode on machine B, tunnel B's port to A:

On machine A (Chrome side), run:

```bash
ssh -N -L 8085:127.0.0.1:8085 user@machine-b
```

Then the extension on machine A connects to `127.0.0.1:8085` and reaches the MCP bridge on machine B. No inbound firewall port is required; the SSH connection does the forwarding.

---

## Tool reference

### `new_gemini_chat`

```json
{}
```

Starts a fresh Gemini chat for the calling session. The session keeps its own tab and chat; if the tab is in an older conversation it navigates/reloads to a blank `/app` composer. The tab is unmapped when the MCP client disconnects and is reused by a later session.

### `get_bridge_status`

```json
{}
```

Reports extension connectivity and version, owner/proxy mode, this session id, its chat tab (and URL) once claimed, the number of open Gemini tabs, the active model/thinking level, and whether the tab is busy.

### `refresh_gemini_chat`

```json
{ "model": "Hydrogen", "thinking_level": "high" }
```

Recovers a stuck or timed-out Gemini tab: cancels any in-flight prompt, reloads the page by default, starts a new chat, and restores High thinking. Set `reload_page: false` for a faster new-chat-only refresh. It returns only after recovery finishes. A prompt that hits the bridge timeout triggers the same recovery automatically; set `GEMINI_AUTO_RECOVER=0` to disable that.

### `set_gemini_model`

```json
{
  "model": "Hydrogen",
  "thinking_level": "high"
}
```

- `model` — optional. The label in Gemini's selector: `Hydrogen` / `Everyday help`, `Neon` / `Deeper analysis`, `Carbon` / `Code & complex work`, or `Auto`. A level suffix such as `Hydrogen High` is understood. Legacy `Pro` / `Flash` still map onto the current labels.
- `thinking_level` — optional: `low`, `medium`, or `high`. **Defaults to `high`** when omitted. The bridge drives Gemini's own `Thinking level` submenu and verifies the result.
- `thinking` — legacy boolean shorthand (`true` → high, `false` → low).

Returns the model and thinking level Gemini reports after the change. Locked options (Neon, Carbon) are skipped.

### `ask_gemini_web`

```json
{
  "prompt": "string",
  "files": ["/absolute/path/to/file1", "/absolute/path/to/file2"],
  "download_dir": "/absolute/path/to/downloads",
  "model": "Hydrogen",
  "thinking_level": "high"
}
```

- `prompt` — required. The text sent to Gemini.
- `files` — optional. Local files to attach to the prompt.
- `download_dir` — optional. Where returned attachments are saved. Defaults to the OS temp directory under `gemini-mcp-downloads`.
- `model` / `thinking_level` — optional. Change the model/thinking mode before sending. **Thinking defaults to High** when omitted.
- The prompt is sent in the session's tab; the tab is activated first because Gemini ignores Send in a background tab.
- If the first submission is not accepted, the bridge reloads the tab once and retries the same prompt (including its files).

Returns a text block. If Gemini returned attachments, the response includes a `[Saved attachments]` section with absolute local paths.

Examples:

```text
Use ask_gemini_web to review src/main.py for bugs.
```

```text
Use ask_gemini_web with files ["logs/error.log", "src/server.ts"] to find the root cause of this crash.
```

```text
Use ask_gemini_web with files ["requirements.md", "schema.sql"] to create an implementation plan.
```

### Model selection

The Gemini web UI remains the source of truth, but the bridge can now drive its selector:

- Call `set_gemini_model` to change the model and/or thinking level.
- Or pass `model` / `thinking_level` to `ask_gemini_web` to switch before sending a prompt.
- The extension also exposes a `setMode` runtime message, so a popup or automation script can do the same thing.
- Thinking level is handled as a separate `Thinking level` submenu with `Low` / `Medium` / `High`. **High is always used unless you explicitly request another level.**

If the requested label is not present in the selector, the call returns an error listing the options Gemini actually offers (DOM labels change over time). The extension reports the active model and thinking level in its popup and adjusts its timeout for high thinking.

### File transfer details

- Uploads are read by the MCP server, base64-encoded, sent over the local WebSocket, and attached via the page's file input.
- Each uploaded file is limited to **20 MiB**.
- The total upload per request is limited to **60 MiB** before base64 encoding.
- For large videos, prefer a URL-based prompt or split the request.
- Generated images and downloadable links are extracted from the response container, fetched with the browser session, and written to `download_dir`.
- Gemini's inline document editor is returned as text; it is not automatically converted into a separate file.

---

## Architecture details

### Owner / proxy mode

Only one MCP server process can own port `8085`. Later processes:

1. Detect `EADDRINUSE`.
2. Connect to the owner as an MCP proxy client.
3. Send `ask` requests through the owner.
4. Receive text and attachments back.

If the owner exits, proxies attempt to take over. This avoids the "port busy" failure mode when OpenCode has several workspaces open.

### Extension roles

The background worker identifies itself as `role: extension`. MCP proxies identify as `role: mcp`. The owner only routes prompts to the extension client; it does not confuse a proxy with the browser.

### Content script

`chrome-extension/content.js` is injected into `https://gemini.google.com/*`. It:

- Finds the composer and reads Gemini's Quill instance (`rich-textarea.__quill`).
- Clears the composer through Quill, so a restored draft cannot leave the DOM and Quill's model out of sync.
- Clicks the attachment button if Gemini has not created the hidden file input yet.
- Attaches files with a `DataTransfer` and waits for both the upload spinner to stop and the file chip to appear.
- Pastes the prompt as a `ClipboardEvent` through Quill, which updates the model Angular actually reads.
- Clicks the `gem-icon-button.send-button` host (the inner `<button>` has no click handler) and verifies that a new user turn appeared.
- Pairs the answer with the conversation container whose user query matches this prompt, then waits for a 1.2-second stable answer after seeing generation or a text change.
- Extracts text, images, and downloadable links.
- Sends the result back through the background worker.

If the tab was open before the extension was reloaded, the background worker injects `content.js` with `chrome.scripting.executeScript` and retries once. **After changing `content.js`, reload the extension in `chrome://extensions`**; simply reloading the Gemini tab can keep the cached old content script.

### Tab and session behavior

- Each MCP session is mapped to one Gemini tab and one chat.
- The tab is activated while a prompt is sent. Gemini ignores Send in a hidden tab.
- A submission that fails is retried once after a page reload.
- `sessionEnd` unmaps the tab; the extension keeps a small warm pool (maximum three bridge-created tabs) and closes idle extras on its five-minute cleanup alarm.
- `refresh_gemini_chat` aborts any in-flight prompt and reloads the page by default.

### Security defaults

- The WebSocket server binds `127.0.0.1` by default.
- Non-loopback clients are rejected unless `GEMINI_BRIDGE_ALLOW_REMOTE=1`.
- The extension only requests host permissions for Gemini and Google content domains.
- The extension requests only `tabs`, `scripting`, `storage`, and `alarms`. It has no `cookies` or `debugger` permission.
- The extension has no cookie access at all, so the bridge cannot export session credentials. The bridge never logs prompt contents to its log file.

---

## Security and privacy

This tool automates a logged-in browser session. That has real security implications:

- **Your Gemini session is powerful.** Anyone who can connect to the bridge can send prompts as you. Keep the bridge on loopback and do not expose port `8085` to the internet.
- **Do not run it on a shared server without isolation.** Use a dedicated Unix user, a dedicated Chrome profile, and OS-level access controls.
- **Prompt and file contents pass through the Gemini web app.** Treat them as data sent to Google, exactly as if you typed them in the browser.
- **Use a dedicated Chrome profile** for the Gemini account rather than your daily profile. Its login session is still sensitive; protect it like an SSH private key.
- **Chrome sandbox.** The scripts add `--no-sandbox` only when running as root. Running Chrome as root is discouraged; use a normal user account.
- **Terms of service.** Automating the Gemini web UI may conflict with Google's terms or usage policies. You are responsible for how you use it. This project is not affiliated with or endorsed by Google.
- **No warranty.** DOM selectors and Google's UI change. Expect occasional breakage.

### Cookie handling

This fork does **not** expose Google session cookies. The extension no longer requests the `cookies` permission, has no `getCookies` handler, and the bridge does not forward cookie requests. `scripts/export-cookies.mjs` has been removed. The only data that crosses the bridge is prompts, responses, and attached files.

---

## Limitations

- **Chrome must be running** somewhere and must have a Gemini tab open. The "no browser process at all" route is not reliable; Google blocks the unofficial HTTP API.
- **The server needs access to Chrome.** Either Chrome runs on the server under Xvfb, or you tunnel `8085` from your laptop.
- **The DOM can change.** Selectors for the composer, send host, upload input, and conversation containers may need updates after Gemini UI changes.
- **The active tab is used for sending.** Gemini ignores Send in a hidden tab, so the bridge activates the session's tab. Concurrent prompts from several sessions briefly switch tabs; each session keeps its own chat.
- **File upload is UI-level.** Very large files or unusual MIME types may be rejected by Gemini.
- **One Google account per browser profile.** Different accounts require a different Chrome profile and bridge instance.
- **High thinking is slower.** Simple prompts may take 10–30 seconds because the bridge waits for a genuine generation/answer change rather than trusting stale text.

---

## Troubleshooting

### `Chrome extension not connected`

- Make sure Chrome is running.
- Make sure the extension is loaded and enabled.
- Reload the extension from `chrome://extensions`.
- Open `https://gemini.google.com/app`.
- Check that the bridge is running: `opencode mcp list` should show `connected`.
- On Linux, check the browser log: `~/.local/state/gemini-web-bridge/chrome.log`.

### `Could not establish connection. Receiving end does not exist`

The Gemini tab is older than the extension reload. Refresh the Gemini tab. The background worker also injects the content script automatically. After changing `content.js`, reload the extension first, then refresh the tab; otherwise Chrome can keep serving the cached content script.

### `Gemini UI only partially loaded` / model selector missing

Gemini sometimes renders the composer without the model pill, history, or working Send button after a slow load. The bridge detects this before prompting and reloads the tab. If it persists, call `refresh_gemini_chat`; a full page reload is the default.

### The answer is from the previous turn

The bridge pairs the answer with the conversation container whose user query matches this prompt and waits for a generation signal or a text change. If this still happens, reload the extension and the Gemini tab so the latest content script is active. The timing logs (`prompt inserted`, `prompt submitted`, `response stable`) show whether the send actually happened.

### File prompt is answered from chat context

- Reload the extension after content changes; an old content script may send before the upload chip appears.
- Keep the Gemini tab visible while a file prompt runs; the bridge activates it, but another window can steal focus.
- Check the timing logs for `Attached 1 file(s)` and `Uploads look ready`. If the upload times out, call `refresh_gemini_chat` and retry.
- The bridge now waits for both the upload spinner to stop and the file chip to appear before sending.

### `No Gemini tab open`

Open `https://gemini.google.com/app` in the Chrome instance that has the extension. In normal use the bridge creates its own tab if none exists.

### `Port 8085 busy` / multiple workspaces

This is expected; the later MCP processes become proxies. If the owner died and nothing owns the port, restart the MCP server by reloading the OpenCode config or restarting the OpenCode service. Check `server.log` in the repository directory; each process line includes its PID.

### `Gemini file input not found`

Gemini changed its upload UI. Update `findFileInput`, `uploadCandidates`, and `attachFiles` in `chrome-extension/content.js`. The error message lists visible candidate buttons to help.

### Upload works but the answer is cut off

Increase the `1200` ms stable-answer timer in `waitForStableResponse` in `chrome-extension/content.js` (and reload the extension). Very long code reviews may need 2.5–3 seconds. Do not remove the generation/change proof; that is what prevents stale answers.

### Linux: Chrome exits immediately

Run `./linux/start-browser.sh` and inspect:

```bash
tail -n 50 ~/.local/state/gemini-web-bridge/chrome.log
```

Common causes:

- Chrome not installed or `CHROME_BIN` wrong.
- Running as root without `--no-sandbox` (the script adds it automatically when root).
- Missing shared libraries; install Chrome's dependencies.
- Xvfb not installed.

### Linux: no VNC connection

- Make sure you ran `ssh -L 5900:127.0.0.1:5900 user@server`.
- x11vnc binds localhost only. Do not expose it publicly.
- Check `~/.local/state/gemini-web-bridge/x11vnc.log`.

### OpenCode does not see the MCP server

- Validate config JSON.
- Run `opencode mcp list`.
- Check OpenCode logs: `~/.local/share/opencode/log/opencode.log`.
- Use an absolute path to `server.js` in the config.

---

## Development

```bash
npm install
node server.js        # stdio MCP server, normally started by OpenCode
```

Extension development:

1. Edit files in `chrome-extension/`.
2. Reload the extension at `chrome://extensions`.
3. Refresh the Gemini tab **after** the extension reload. Content scripts are cached per extension load.
4. Check the service worker console for `[Bridge BG]` and the Gemini page console for `[Gemini Bridge]` timing messages.

### Tests

The tests spawn their own MCP server over stdio and exercise the real browser bridge. Chrome must be running, the extension loaded, and a Gemini tab available. If another process owns the bridge port, the test server becomes a proxy, which also exercises proxy routing.

```bash
npm run test:smoke      # status, model, one prompt
npm run test:seq        # text -> context -> file in one chat
npm run test:e2e        # status, mode, text, context, file, refresh, new chat
npm run test:e2e:full   # adds abort/recovery and two-session isolation
```

Use `GEMINI_BRIDGE_PORT` to point the tests at an isolated bridge port (for example `8086`). Do not expose that port.

`tests/one.mjs` can run a single prompt with an optional file:

```bash
node tests/one.mjs --new-chat --file /tmp/report.txt --prompt "Summarize the attachment"
```

Logs:

- MCP server log: `server.log` next to `server.js` (override with `GEMINI_BRIDGE_LOG`). Each line includes the process PID.
- Browser launcher logs: `~/.local/state/gemini-web-bridge/`.

To test the MCP handshake without OpenCode, send JSON-RPC lines to `node server.js`:

```json
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}
{"jsonrpc":"2.0","method":"notifications/initialized"}
{"jsonrpc":"2.0","id":2,"method":"tools/list"}
```

---

## Attribution and license

- Original extension and bridge concept: [Walkoud/gemini-browser-mcp](https://github.com/Walkoud/gemini-browser-mcp), MIT.
- This fork adds file transfer, owner/proxy multi-workspace support, loopback security, auto-injection, Linux tooling, and documentation.
- License: MIT. See [LICENSE](LICENSE).

TDQS

B3.4/5.0

Scored across 1 tool

Disambiguation5/5

With only one tool there is no possibility of confusion or misselection between tools. The single tool's purpose—sending a prompt to Gemini via the browser bridge—is unambiguous.

Naming Consistency4/5

ask_gemini_web follows a clear snake_case verb_noun convention, which is a good pattern. Consistency cannot really be demonstrated with a single tool, so it falls short of a perfect score by lack of evidence rather than by any flaw.

Tool Count3/5

The server's purpose is narrow (a browser bridge to Gemini), so one core operation is defensible, but a single tool is thin even for this scope. There is no companion tool for checking extension connectivity, managing sessions, or retrieving prior responses.

Completeness3/5

The prompt/upload/download loop is covered, which is the essential capability. However, there are notable gaps: no connection/health check, no way to list or resume conversations, and no handling of long-running or asynchronous requests, leaving agents with dead ends when things go wrong.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues