WebWarden MCP
# WebWarden MCP
> Read any web page from Claude — even the ones that block bots — without letting prompt injections through.
> [!WARNING]
> **Status: alpha.** The core works and is tested, but expect rough edges and breaking changes. See the [roadmap](#roadmap).
WebWarden is a self-hosted [Model Context Protocol](https://modelcontextprotocol.io) server that lets AI agents (Claude on web, desktop and mobile, Claude Code, or any MCP client) read web pages that normally refuse them:
- pages rendered with JavaScript,
- sites behind bot walls (Cloudflare and friends),
- sites that explicitly block AI agents.
Every page passes through a **configurable chain of prompt-injection guards** before your agent sees a single word of it.
## Why
Agents are great at summarizing the news, comparing supermarket offers or reading product specs — until the site answers with a captcha, an empty JavaScript shell or a "no bots allowed" page. And when they *do* get in, the page may carry hidden instructions aimed at your agent.
Existing tools solve half of the problem each:
| | JS / anti-bot | Remote MCP usable from Claude mobile | Prompt-injection defense |
|---|---|---|---|
| [Scrapling](https://github.com/D4Vinci/Scrapling) | ✅ excellent | ⚠️ static bearer token only | ⚠️ strips hidden HTML |
| Firecrawl (self-hosted) | ⚠️ anti-bot engine is cloud-only | ✅ | ❌ |
| Crawl4AI | ✅ | ⚠️ SSE | ❌ |
| Prompt-injection proxies | — | — | ✅ but young or archived |
WebWarden does not reinvent scraping: it builds on **Scrapling** for fetching and adds what is missing — OAuth for Claude connectors, a pluggable guard pipeline, agent-friendly tools, SSRF protection for home deployments, and spend tracking for paid guard services.
## Tools
| Tool | What it does |
|---|---|
| `read_page(url, mode, content, max_chars, start_index)` | Fetches a page (plain HTTP first, stealth browser when needed), removes invisible content, extracts Markdown (plus JSON-LD products and prices), runs the guard chain and returns the text framed as untrusted data, with a short report. Long pages paginate. When the site answers with a CAPTCHA/bot check or a login page instead of the content, the response says so (`ACCESS BLOCKED`, `access_wall` in the structured output). |
| `usage_report(period, group_by, scope)` | Requests, tokens and estimated USD spent on external guard services (e.g. Jev, OpenAI), by guard, model or day, plus today's budget usage. |
There is deliberately no search tool: the agent finds pages with its own web search (Claude has one built in) and reads the ones it needs with `read_page`, so the content — where injections live — is always screened. The server's instructions tell the agent to do exactly that.
What you get back, in practice:
- **Articles** come back as clean Markdown (title, text, links); **front pages and listings** keep every headline with its absolute link, so the agent can open the stories it wants.
- **Shops** keep product grids and prices; JSON-LD products and offers are appended as structured data.
- **Long pages** paginate (`start_index`); plain-text resources (CSV, JSON, Markdown) are returned as text.
## How it works
```
Claude (web / desktop / mobile)
│ HTTPS + OAuth
▼
Reverse proxy (TLS) ← e.g. NGINX on a small VPS
│ private tunnel (WireGuard)
▼
WebWarden (Docker, at home) ← egress firewall: never reaches your LAN
├─ fetch: impersonated HTTP → stealth browser → + Cloudflare solver
├─ process (isolated worker, time/memory/size limits):
│ ├─ sanitize: hidden elements, comments, invisible styles, <template>
│ └─ extract: article text or full page, linked headlines, JSON-LD products
├─ guard chain: transformers → detector cascade (free → classifier → judge)
└─ frame: <untrusted-web-content id=random> … </untrusted-web-content id=random>
→ the web sees a residential IP, not a datacenter one
```
**Why a residential IP matters:** no stealth technique compensates for a datacenter IP address — many retailers and news sites block cloud ranges outright. WebWarden is designed to run at home (a mini PC is enough) and be exposed through a small VPS.
## Prompt-injection guard chain
Two plugin kinds: **HTML sanitizers** run on the DOM before extraction; **guards** run on text chunks after it. Guards are either *transformers* (rewrite text) or *detectors* (score each chunk 0–1).
Detectors form a **cost-ordered cascade**. Every chunk is `undecided`, `clean` or `flagged`; each stage only sees chunks that are still undecided:
```yaml
chain:
guards:
- use: unicode_normalizer # transformer: strips zero-width, bidi and tag characters
- use: heuristics # free, local: may flag on very strong evidence, NEVER clears
flag_at: 0.95
- use: jev # calibrated classifier (TypeSafe AI): sees every undecided chunk
clean_below: 0.2
flag_at: 0.85
- use: openai_compatible # LLM judge: sees only what the classifier was unsure about
model: gpt-5.4-nano
temperature: null # reasoning models only accept the default
reasoning_effort: low
clean_below: 0.5
flag_at: 0.5
# full stages with API keys, prices and budgets: config.example.yaml
```
- `score < clean_below` → clean, `score >= flag_at` → flagged, otherwise on to the next stage. A stage without `clean_below` can never mark text as safe.
- A failing stage (timeout, provider error, budget exhausted, open circuit breaker) leaves its chunks undecided — scores of different stages are never compared. A provider that reports being **out of credit** (HTTP 402, or an error code such as OpenAI's 429 `insufficient_quota`) is not retried: the stage is skipped for `quota_cooldown_s` (15 min) and `usage_report` says so.
- Overlapping **seams** across chunk (and page) boundaries catch injections split in two.
- Flagged chunks are redacted (or the page blocked, or annotated). With `refine` (default) only the offending paragraphs are removed, and only when the remaining text passes the cascade again as a whole; otherwise the chunk goes. Chunks nobody could verify are announced in the output header.
| Plugin | Kind | Runs |
|---|---|---|
| `hidden_content` | HTML sanitizer | local, free |
| `unicode_normalizer`, `heuristics` (English + Spanish) | transformer / detector | local, free |
| `jev` ([TypeSafe AI](https://typesafe.ai)) | calibrated classifier | API (~$0.04 per million tokens) |
| `openai_compatible` (OpenAI, Groq/gpt-oss-safeguard, OpenRouter, Ollama, vLLM) | LLM judge | API or local |
Remote adapters share a base that handles retries, circuit breaking, caching, daily request/cost budgets and per-attempt usage recording. Third-party plugins are discovered through the `webwarden.sanitizers` / `webwarden.guards` entry points.
## Evaluation and cost
Thresholds are chosen with a built-in evaluation harness (`webwarden eval`, [design 0002](docs/design/0002-evaluation-harness.md)) over public prompt-injection datasets (BIPIA, LLMail-Inject, NotInject, BrowseSafe-Bench), benign web text (FineWeb, Spanish and English), Spanish attack sets and snapshots of real pages. Baseline with the reference chain (heuristics → Jev → gpt-5.4-nano judge), test split — full report in [docs/eval](docs/eval/2026-11-29-baseline.md):
| | Result |
|---|---|
| Recall on unambiguous attacks | 94% (147/156) |
| Real pages / FineWeb windows falsely redacted | 0/17 · 0/321 |
| Facts kept on attacked pages (paragraph-level redaction) | 24/28 (whole-chunk redaction: 12/28) |
| Cost of the paid guards | about **$0.04 per 100 pages** (plus refinement calls on flagged chunks) |
Paid guards can have per-guard daily caps (`daily_request_budget`, `daily_cost_budget_usd`; off unless set). A stage that hits its cap, times out or errors is skipped: its chunks go on to the next stage, and chunks no stage could decide are counted in an `UNVERIFIED: n of m chunks` header line (`chain.undecided`: `allow` shows them; `flag` — recommended with paid guards — treats them as flagged, so under `action: redact` they are removed with a "could not be verified as safe" notice). Known weak spots — stealthy payloads written to read like normal content (BrowseSafe-Bench), quoted attacks in articles *about* prompt injection — are listed in the report.
## Security model
- **SSRF:** only public addresses are fetched — every DNS answer is checked, redirects are followed manually and re-validated, the validated IP is pinned in curl, and the browser routes every request through the same check. Because a browser cannot stop WebSockets or redirected sub-resources, **the Docker image applies an egress firewall** (private ranges, your tunnel subnet), and the browser tier refuses to run over HTTP without it.
- **Hidden content:** elements a human would not see are removed before any guard runs — `hidden`/`aria-hidden`, inline and stylesheet hiding (display, visibility, opacity, zero size, off-screen, clipping, transparent or same-color text, zero scale), comments, `<template>`. When in doubt (invalid CSS values, ambiguous tokenization) content is treated as hidden.
- **Bounded processing:** each page is parsed, sanitized and extracted in a short-lived worker process with a time and memory limit, after the DOM is capped (nodes, depth; hiding rules are kept when content is cut). A page crafted to be slow cannot stall the server; parsers of page CSS and text are linear-time.
- **Untrusted output:** page text, title and final URL are inside a frame with a random id; look-alike tags and forged `[webwarden: …]` notices are neutralized. Bot checks and login walls are reported as fixed labels (`ACCESS BLOCKED`), never echoing page text outside the frame.
- **Auth:** GitHub OAuth (allowlist by immutable numeric id, enforced at token verification) plus optional static tokens for Claude Code. HTTP without auth only works on loopback.
- **Privacy:** the usage ledger stores counters, never URLs or page text.
Found a vulnerability? Please report it privately — see [SECURITY.md](SECURITY.md).
## Quick start
WebWarden is installed from source for now (no PyPI package or published image yet). You need Python ≥ 3.12, [uv](https://docs.astral.sh/uv/getting-started/installation/) and, for the browser tier, Chromium installed through Patchright (`patchright install chromium`; on Linux add `--with-deps`). The remote setup needs a Linux host with Docker Engine and Compose v2 (the egress firewall uses iptables). On platforms without `fork` (Windows) page processing falls back to threads, without the time kill and memory limit.
Guards that call an API need a key: [TypeSafe](https://typesafe.ai) for Jev, OpenAI (or any OpenAI-compatible endpoint) for the judge. Put them in environment variables — by default `TYPESAFE_API_KEY` and `OPENAI_API_KEY` — or in a `.env` file in the working directory, which is loaded automatically.
Local (Claude Code over stdio):
```bash
uv sync
uv run patchright install chromium
cp config.example.yaml config.local.yaml # edit to taste
claude mcp add webwarden -- uv --directory "$PWD" run webwarden --config config.local.yaml serve
```
Claude Desktop (`claude_desktop_config.json`):
```json
{
"mcpServers": {
"webwarden": {
"command": "uv",
"args": ["--directory", "/path/to/webwarden-mcp", "run", "webwarden", "--config", "config.local.yaml", "serve"]
}
}
}
```
Try it from the terminal: `uv run webwarden --config config.local.yaml read https://example.com/`.
Remote (claude.ai web and mobile): see [deploy/README.md](deploy/README.md).
### Configuration
Everything lives in one YAML file; [config.example.yaml](config.example.yaml) documents the main options (every key and default: `src/webwarden/config.py`):
- `server` / `auth` — transport, public URL, GitHub OAuth allowlist, static tokens;
- `fetch` — browser concurrency, render wait, extra blocked networks (your tunnel subnet);
- `output` — default `max_chars` and content mode (`auto`, `main`, `full`);
- `chain` — sanitizers, guards with `clean_below`/`flag_at`, action (`redact`, `annotate`, `block`), refinement;
- `processing` — worker processes and their time, memory and DOM limits;
- `usage` — the spend ledger.
API keys are read from environment variables (`api_key_env`), never from the file. Without any paid guard the chain still runs the free local stages, and the output says the content was not verified by a classifier.
## Development
```bash
uv run pytest # unit tests (no network)
uv run pytest -m browser # real headless browser tests
uv run ruff check . && uv run ruff format .
```
Evaluation (optional dependency group, downloads public datasets into `eval/data/`, gitignored):
```bash
uv sync --group eval && uv run webwarden eval fetch
uv run webwarden eval snapshot --file eval/snapshot-urls-es.txt # real-page snapshots (add --lang en for *-en.txt)
uv run webwarden --config config.local.yaml eval run --band-low 0.1 [--refine-check] [--offline]
```
Design decisions, each reviewed by an independent agent before implementation:
- [0001 — MVP architecture](docs/design/0001-mvp-architecture.md) (fetching tiers, SSRF, guard cascade, auth, output framing)
- [0002 — Evaluation harness](docs/design/0002-evaluation-harness.md)
- [0003 — Paragraph-level redaction](docs/design/0003-paragraph-redaction.md)
- [0004 — `web_search` tool](docs/design/0004-web-search.md) (deferred, with field-test findings)
[CLAUDE.md](CLAUDE.md) holds the contributor guide: layout, guard contract and the security invariants that must not break.
## Contributing
Issues and pull requests are welcome. [CLAUDE.md](CLAUDE.md) is the contributor guide (for humans too): read the security invariants and the guard contract first. Before a pull request run `uv run pytest` and `uv run ruff check . && uv run ruff format .`; unit tests never touch the network; a new guard needs an entry point, tests and a line in this README; commits follow the conventional style (`feat:`, `fix:`, `docs:` …). Behaviour changes start with a short decision record in `docs/design/`.
## Responsible use
WebWarden is meant for **personal, low-volume reading** of publicly available pages — the kind of browsing you would do yourself. You are responsible for complying with the terms of service of the sites you access and with the laws of your jurisdiction. Do not use it for mass crawling, for content you are not entitled to, or to overload anyone's infrastructure.
## Roadmap
- [x] `read_page` with HTTP → browser → Cloudflare escalation, Markdown + JSON-LD extraction
- [x] SSRF protection (DNS checks, manual redirects, IP pinning, browser routing, egress firewall)
- [x] Guard chain with cascade semantics, seams, built-in guards
- [x] Adapters: Jev, OpenAI-compatible
- [x] GitHub OAuth + static tokens
- [x] Usage and spend ledger, `usage_report` tool, budgets
- [x] Docker image, compose, NGINX + WireGuard recipe
- [x] Evaluation harness (BIPIA, LLMail-Inject, NotInject, FineWeb, BrowseSafe, Spanish sets, real-page snapshots) — `webwarden eval`, results in `docs/eval/`
- [x] Paragraph-level redaction with a residual check
- [x] Bounded, isolated page processing (worker process per page, DOM limits, linear-time parsers)
- [x] Front pages: linked headlines and absolute links
- [ ] ~~`web_search` tool~~ — deferred: Claude's own search plus `read_page` covers it (docs/design/0004)
- [ ] Browser-side visibility pruning (computed styles) for complex CSS hiding
- [ ] More adapters: Prompt Guard 2, Anthropic, Model Armor, Azure Prompt Shields, Lakera
- [ ] Page cache, per-user rate limiting, PDF support
- [ ] CI (GitHub Actions) and published Docker image
## Acknowledgements
Built on the shoulders of [Scrapling](https://github.com/D4Vinci/Scrapling), [FastMCP](https://github.com/jlowin/fastmcp) and [trafilatura](https://github.com/adbar/trafilatura).
## License
[Apache License 2.0](LICENSE).
TDQS
Scored across 2 tools
The two tools serve wholly unrelated purposes — one reports service consumption and budget, the other fetches web page content. There is no plausible way to confuse them, and the read_page description explicitly scopes its usage relative to an external search tool.
Both names are lowercase snake_case, which is consistent stylistically, but the patterns differ slightly: read_page is verb_noun while usage_report is noun_noun (a reporting noun phrase). Readable and predictable enough, with only a minor deviation.
Two tools is on the thin side for a server that appears to wrap a scraping/guard service, but the scope (read a page, report usage) is at least coherent. Each tool earns its place; the surface just feels minimal rather than over-stuffed.
read_page covers fetching, pagination, JS rendering, and access-wall signalling well, and usage_report covers billing visibility, but there are notable gaps: no search/discovery tool, no batch or multi-URL read, no way to inspect or configure guards/budgets. Agents can work around this using an external search tool, but the surface is not fully rounded out.