Skip to main content
Glama
browser-mcp
by cwilko
README.md
# browser-mcp

A small MCP server that drives a real Google Chrome through [Patchright](https://github.com/Kaliiiiiiiiii-Vinyzu/patchright) (a Playwright build with the automation signs removed), for research agents reading marketplace sites. Chrome runs headed on a virtual display (Xvfb), with a normal profile, `en-GB` locale and London time zone.

It serves streamable HTTP at `/mcp` and enforces its own limits, so an agent cannot browse faster or further than allowed.

## Tools

| Tool | What it does |
|---|---|
| `navigate(url)` | Open a page on an allowed site. Returns URL, title, HTTP status, page-load counts and an accessibility snapshot with element refs (`[ref=e42]`). |
| `snapshot()` | The current page's snapshot again, without loading anything. |
| `click(ref)` | Click an element by ref. Returns the new snapshot. |
| `type(ref, text, submit)` | Type into an input (for example a search box), optionally pressing Enter. |
| `scroll(direction)` | Scroll to load more results. |
| `back()` | Re-open the previous page of this session. |
| `close()` | Close the session's tab. |

There is no script evaluation, file access or screenshot tool.

## Limits

| Limit | Default | Variable |
|---|---|---|
| Page loads at a time, whole server | 1 | |
| Gap between loads on a site (randomised) | 4–8 s | `MIN_DELAY_MS`, `MAX_DELAY_MS` |
| Page loads per site per session | 60 | `MAX_LOADS_PER_SITE` |
| Page loads per session | 150 | `MAX_LOADS_PER_SESSION` |
| Time an automatic bot check may take to clear | 20 s | `CHALLENGE_WAIT_MS` |
| How long a site stays closed after a 429 or an uncleared bot check | 6 h | `SITE_COOLDOWN_MS` |

A page load is a `navigate`, a `back`, or a click or submit that loads a new document. It counts against the site the page lands on. Cooldowns are kept in memory, so restarting the server clears them.

Hosts:

- `ALLOWED_SITES` (required): comma-separated sites whose pages may be opened, for example `upwork.com,fiverr.com`. Subdomains match. Every top-level navigation is checked, including redirects and clicked links.
- Sub-resources (scripts, images, bot-check frames) may come from any public host, because blocking them breaks pages and bot checks. No request at all may reach a private or loopback IP address or a host ending in `BLOCKED_HOST_SUFFIXES` (default `localhost,.local,.internal,.svc,.cluster.local,.lan`).

## Other settings

| Variable | Default | |
|---|---|---|
| `AUTH_TOKEN` | required | Callers send `Authorization: Bearer <token>` |
| `PORT` | `3000` | |
| `SESSION_IDLE_MS` | 30 min | Sessions with no request for this long are closed |
| `BROWSER_IDLE_MS` | 10 min | Chrome is closed when no session has been open for this long, and started again on the next one |
| `MAX_SNAPSHOT_CHARS` | 60000 | Longer snapshots are cut |
| `USER_DATA_DIR` | `/tmp/browser-profile` | Chrome profile (cookies persist across sessions until the pod restarts) |

`GET /healthz` answers without a token.

## Build

`npm ci && npm run build`. The image (`Dockerfile`, amd64 only because Google Chrome has no Linux arm64 build) is pushed to Docker Hub as `wilkobets/browser-mcp` by `.github/workflows/dockerhub.yml`, tagged `sha-<commit>` on every push to `main`.

The container needs writable `/tmp`, `/home/node` and a large `/dev/shm` (256 MiB or more); with a read-only root filesystem, mount emptyDirs there.