PageHand MCP Server
by Mawyxx
README.md
# PageHand
PageHand is a local browser runtime for AI agents. It starts Chromium, exposes it over the Model Context Protocol, and gives the agent a text-first page model with stable element ids, real network control, durable profiles, and a download jail.
The server is deterministic Python and Playwright. It does not call an LLM and it does not send page data to a cloud service. The agent is the MCP client. PageHand is the browser it drives.
Status on 27 November 2026: the M4 network surface and M5 downloads are closed. 24 tools are implemented. The local strict gate exits 0 with 106 passed, 0 failed, 33 skipped, and 139 registered. The full suite has 2,145 passing tests and 15 skipped. Critical coverage is 126 of 126 files at 100% line and branch. GitHub Actions has not run in this workspace yet, so CI is still unverified.
## Why PageHand exists
A browser is a visual program and an agent works with text. Screenshots and pixel coordinates are expensive, slow, and fragile when the layout moves. PageHand turns the live page into a typed document: visible text, interactive elements, forms, and stable ids. The agent reads that model and acts by id. The same session also owns the network view, the profile, and the downloaded files, so the agent does not have to rebuild context from a separate scraper.
PageHand runs on the machine that owns the browser profile. Cookies, local storage, IndexedDB, client certificates, and downloaded files stay there. There is no hosted browser and no telemetry channel.
## What an agent can do
- Open and navigate a session, then read the page as text, outline, accessibility tree, forms, or a compact snapshot.
- Click, fill, select, check, hover, scroll, press keys, and submit forms through `page_act` or the semantic `page_invoke`.
- Wait for a selector, text, URL, response, network idle, DOM mutation, readiness state, or a download without sleeping.
- Extract tables, lists, grids, forms, and whole pages with a schema, and collect pages with dedupe and loop limits.
- Run long tasks and jobs with a ledger, checkpoints, and resume support.
- Inspect HTTP, WebSocket, and Server-Sent Events traffic through `page_net`.
- Block, fulfill, redirect, add headers, or delay requests through `page_route`.
- Send and close WebSocket frames through the routed browser socket, and read captured SSE events.
- Set a per-profile proxy, mTLS client certificate, or origin-scoped Basic auth through `page_transport`.
- List, save, delete, and inspect browser downloads through `page_capture`.
- Keep profiles, cookies, web storage, IndexedDB, caches, checkpoints, and secret handles across sessions.
- Check health, console errors, history, timeline, metrics, and network recording state through `page_meta`.
## What PageHand is not
PageHand is not a cloud browser, a scraping API, or a raw HTTP client. It drives the browser and the browser's own network stack. It does not fetch a URL for the agent, run JavaScript from a shell, open downloaded files, or upload captured data.
Several tools from the original 30-tool design are deliberately absent: trace and video, screenshots and PDF, permissions, dialogs, source dumps, scenario recording, an extraction schema registry, JavaScript eval, corporate SSO, multi-tab recovery, and a native handoff console. The `full` profile reports 24 of 30 implemented, and the status stays UNMET rather than being relabelled as complete.
## Quick start
Requirements: Python 3.12, a Chromium build installed through Playwright, and an MCP client.
```bash
python -m venv .venv
. .venv/bin/activate
pip install -e ".[dev]"
playwright install chromium
PAGEHAND_TOOLSET=capture pagehand-mcp
```
On Windows PowerShell:
```powershell
python -m venv .venv
.venv\Scripts\Activate.ps1
pip install -e ".[dev]"
playwright install chromium
$env:PAGEHAND_TOOLSET = "capture"
pagehand-mcp
```
A minimal MCP client entry:
```json
{
"mcpServers": {
"pagehand": {
"command": "pagehand-mcp",
"env": {
"PAGEHAND_TOOLSET": "capture"
}
}
}
}
```
`PAGEHAND_TOOLSET` selects the exposed profile. `core` is the default. `state` adds profiles and storage. `network` adds HTTP, routes, streams, and transport. `capture` adds downloads. `full` exposes every implemented tool, currently 24.
Run `pagehand-health` for a one-shot health probe.
## Tool surface
| Profile | Tools | Status |
|---|---|---|
| `core` | 16 | implemented |
| `state` | 19 | implemented |
| `network` | 23 | implemented |
| `capture` | 24 of 26 target | implemented, capture-only downloads |
| `full` | 24 of 30 target | UNMET, six tools deliberately excluded |
The four capability groups:
| Group | Tools |
|---|---|
| lifecycle and reads | `page_session`, `page_tabs`, `page_handoff`, `page_nav`, `page_read`, `page_meta`, `page_capabilities` |
| action and extraction | `page_act`, `page_invoke`, `page_wait_for`, `page_extract`, `page_task`, `page_foreach`, `page_collect`, `page_job`, `page_reconcile` |
| state | `page_profile`, `page_storage`, `page_secret` |
| network and files | `page_net`, `page_route`, `page_ws`, `page_transport`, `page_capture` |
`openapi/mcp-tools.yaml` is the machine-readable contract. `docs/TOOLSETS.md` explains profiles, aliases, and counts.
## Downloads
`page_capture` owns four actions:
| Action | Purpose |
|---|---|
| `downloads` | List download records for a live session, with state, size, hash, URL, and paging. |
| `download_save` | Publish a completed download into the session jail and return the path, bytes, and SHA-256. |
| `download_delete` | Delete one published file, or all published files for the profile. |
| `download_policy` | Report caps, quota, usage, retention, staging mode, and capture diagnostics. |
`page_wait_for(condition="download")` waits for a terminal record without polling.
Downloads can come from a `Content-Disposition` attachment, a direct file navigation, a `blob:` or `data:` URL created by page script, a JS-generated file, repeated or parallel links, or a popup. Every extension is accepted. The file is never opened, executed, uploaded, or scanned by PageHand.
The jail lives under `runtime/downloads/<profile_key>/<session_id>/`. Published leaves are POSIX `0600` or a verified Windows protected DACL. Default caps are 1 GiB per file, 100 files per session, a 4 GiB profile quota, seven-day retention, and a 24-hour staging TTL. A save uses a temp leaf, a single hash pass, an atomic replace, and a read-back check. A disabled policy denies the download at the engine before a record exists.
## Architecture
```text
MCP client
|
v
interfaces/mcp strict tool arguments, toolset gate, envelopes
|
v
application sessions, reads, actions, extraction, network, downloads
|
v
domain page model, ids, FSM, bounds, download names and states
|
v
ports browser, recorder, streams, downloads, files, clock, ids
|
v
adapters Playwright, filesystem, SQLite, crypto, OS ACL
```
One composition root builds the concrete adapters. Domain code has no filesystem or Playwright imports. The network recorder is shared by `page_net`, events, waits, and `page_route`. The download bridge feeds one service, and the service owns the record ledger, publication, and audit. The secure-file layer owns POSIX modes and the Windows DACL, including the read-back that proves the result.
## Security model
PageHand is local software with a local profile. The trust boundary is the MCP client, the browser page, and the filesystem jail.
- Every tool call is scoped to a live session. A resource id from another session returns the same not-found error as a missing id.
- Network tools return complete agent-visible values, including headers, bodies, and frame payloads. Logs, audit rows, traces, and evidence keep ids, states, sizes, and redacted URLs only.
- Download paths resolve under the profile jail. Absolute paths, `..`, symlinked parents, Windows junctions, reparse points, and non-regular targets are refused.
- Published files are verified after write. A failed verification removes the target and returns a named error.
- Downloads are never opened, executed, uploaded, or passed to a shell. An extension is not a security decision.
- Profiles can be deleted explicitly. Download retention and `download_delete` remove bytes on request.
- Secrets come from the environment, the OS keyring, or the encrypted secret store. They are not written to logs or evidence.
See `docs/SECURITY-M4.md`, `design/SECURITY-DOWNLOADS.md`, and `docs/THREAT-MODEL.md` for the detailed threat model.
## Verification
The local gate is the source of truth for this checkout:
```bash
ruff check src tests scripts
ruff format --check src tests scripts
mypy src scripts
python -m pytest -q -o addopts=
python -m scripts.prime_check --strict
```
Current result:
- `prime_check --strict`: exit 0, 106 passed, 0 failed, 33 skipped, 139 registered.
- Full suite: 2,145 passed, 15 skipped, 2,160 collected.
- Critical coverage: 126 of 126 files at 100% line and branch, floor 126.
- Flaky detector: 10 separate processes, 10 distinct `(pid, seed)` pairs, no timeouts.
- Real browser smoke: WebSocket, SSE, and download attachment paths pass on this machine.
The Windows DACL job and the GitHub Actions workflows have not run in this workspace. Treat those as unverified until the CI run is recorded. `full=30` is UNMET by design.
## Repository layout
| Path | Contents |
|---|---|
| `src/pagehand/` | runtime: domain, application, ports, adapters, MCP interfaces, composition |
| `tests/` | unit, contract, integration, security, fixtures, and fakes |
| `design/` | architecture, security, and frozen TDD locks for M2 to M5 |
| `docs/` | API contracts, network, capture, toolsets, runbooks, ADRs, reasoning, reviews |
| `openapi/` | machine-readable MCP tool contract |
| `scripts/prime_check.py` | checker and gate runner |
| `reports/` | evidence, strict runs, flaky reports, and milestone sign-offs |
| `prime_check.config.yaml` | scopes, caps, gates, flaky profiles, critical floor |
## Development
Install the development dependencies, then run the checks above. The checker is not a formality. Every gate maps to a law in `Mawyxx Prime V7.0.md`, and a red gate blocks a merge.
```bash
python -m scripts.prime_check --list
python -m scripts.prime_check --only <gate>
PAGEHAND_FLAKY_PROFILE=nightly python -m scripts.prime_check --only flaky-detector
```
Changes follow the repository's design-first rules. A new behavior starts with a locked test in `design/TDD-LOCK-<task>.md`. A trade-off gets an ADR in `docs/adr/`. A PRIME+ change also gets a reasoning note in `docs/reasoning/` and an adversarial review in `docs/reviews/`. Tests are not weakened to make a gate green, and evidence is refreshed from a measured run.
The current download work is documented in `design/ARCH-DOWNLOADS.md`, `design/SECURITY-DOWNLOADS.md`, `design/TDD-LOCK-DOWNLOADS.md`, and `docs/API-DOWNLOADS.md`.
## Documentation
Start with `docs/README.md`. The pages most people need:
- `docs/API-M2.md`, `docs/API-M3.md`, `docs/API-M4.md`, and `docs/API-DOWNLOADS.md` for tool contracts.
- `docs/NETWORK.md` for records, routes, streams, and transport.
- `docs/CAPTURE.md` for downloads and the limits of the capture surface.
- `docs/TOOLSETS.md` for profiles and aliases.
- `docs/RUNBOOK-M4.md` and `docs/RUNBOOK-M5.md` for health, rollback, and incident steps.
- `docs/ROADMAP-M4-DOWNLOADS.md` for the current status and the remaining operational work.
- `docs/adr/` for decisions, including ADR 0072 for downloads.
## Limitations and next work
The feature scope agreed for this project is complete. The remaining work is operational.
- Run GitHub Actions, including `windows-secure-file`, and record the run URLs. Local green does not prove CI.
- Decide whether `full=30` stays UNMET or is cancelled by a scope ADR. Do not silently relabel it.
- Optional hardening: the truncated `download_delete(all=true)` pass reports `remaining` but walks the profile twice; real Windows symlink behavior is covered by Ubuntu CI; an ephemeral context's pre-save body sits in the OS temp directory outside the jail and quota.
- No per-profile download policy, no antivirus or CDR pipeline, and no pre-write CDP byte cap in this version.
- `gitleaks-history` and `mutation-critical` are skipped with ADRs and a sunset at M8. There is no git baseline for `coverage-diff` or `blast-radius` in this checkout.
## License
MIT. See `LICENSE`.
## Contributing and security
Read `CONTRIBUTING.md` before a pull request and `SECURITY.md` before reporting a vulnerability. Do not open a public issue for a suspected secret leak or a browser escape.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues