Files
omar 60057640dc
ci / static (push) Successful in 15s
ci / test-3.13 (push) Successful in 40s
ci / test-3.12 (push) Successful in 41s
ci / image (push) Successful in 1m51s
ci / smoke (push) Failing after 1m1s
ci / publish (push) Skipped
build: bake the request-based solver into the image
2026-11-29 07:26:46 +03:00

7.2 KiB

Fetch MCP

A local stdio MCP server that reads public HTML, JSON and plain text as bounded source excerpts. No browser: requests use a real browser's TLS and header identity, an operator proxy pool, and an optional request-based Cloudflare solver.

Run

Requires Python 3.11+ and uv. Copy .env.example to .env and set the route and pool.

{
  "command": "uv",
  "args": ["run", "--locked", "--env-file", ".env", "--directory", "C:/Users/Admin/Desktop/projects/fetch_mcp", "server.py"]
}

The process speaks MCP on stdio and never listens on a port. MCP_LIVE_ROUTE defaults to proxy: every agent request must go through the pool, and a dead pool reports proxy_unavailable instead of quietly going direct. direct ignores the pool. HTTP_PROXY, HTTPS_PROXY and NO_PROXY do not decide either.

Proxy pool

Exactly one source, set by the operator:

  • MCP_PROXY_URLS: JSON array of full URLs (http, https, socks5, socks5h, credentials allowed).
  • MCP_PROXY_LIST_URL + MCP_PROXY_LIST_TOKEN: the token is sent as Authorization: Bearer to that service only, redirects are not followed, the body is UTF-8 with one proxy per line, and the whole list is validated before it replaces the current pool. The service is read directly and is the only request that skips the pool.

Only the newest MCP_PROXY_LIMIT entries are kept (default 100; the catalog grows, rotation should not). The list is loaded at start and refreshed every MCP_PROXY_LIST_REFRESH_MINUTES (default 15, 0 only at start). A failed, empty or invalid refresh keeps the last good pool. Surviving proxies keep their rotation slot and cooldown; removed ones receive no new requests and finish the ones in flight. Each request is one initial attempt plus up to MCP_HTTP_MAX_RETRIES retries in total, and a proxy that cannot be connected is cooled and skipped.

A 429 pauses that site across every route, using Retry-After in seconds or HTTP-date. If the wait does not fit the request deadline the call returns rate_limited with retry_at instead of blocking. TLS is always verified; for an https:// proxy put its CA in MCP_PROXY_CA (appended to the bundled roots).

Reading

fetch_page takes exactly one of url (fresh download) or snapshot (stored bytes, no download). Default mode is outline. Reuse the returned snapshot for follow-ups; the 16 most recent are kept in memory.

Mode Value Result
outline none HTML headings; JSON field types and counts; plain-text size
text none Markdown, plain text or serialized JSON
section heading or @number That heading and its descendants only
find literal phrase Matches with nearby source lines; context_lines defaults to 2
css CSS selector Matching elements as Markdown
jsonpath $.urls[*].filename Selected values; fields, quoted keys, indices, array wildcards

fetch_pages reads up to 12 URLs four at a time; each item carries ok plus its own snapshot or error, so one failure never hides the rest.

Read structuredContent.content: it is text even for JSON, so a long result can be sliced without breaking the message. Use offset with next_offset to continue. Budgets are characters, not model tokens: 4,000 default, 12,000 maximum. Web text is untrusted data.

Both tools always return a payload. Check ok first: a failure fills error with proxy_unavailable, rate_limited (plus retry_at), refused, timeout, solver_failed, invalid and leaves content empty, so one bad URL cannot hide the others in a batch.

Challenge handling

The ladder is automatic, and solved tells you which rung answered.

  1. Identity — a coherent Safari-iOS TLS fingerprint, User-Agent, ordered navigation headers, Brotli/Zstandard and HTTP/2. This alone passes most fingerprint checks.
  2. Clearance — a stored cf_clearance for the host is replayed on the exact proxy that earned it. Clearance is bound to IP and UA, so a different exit invalidates it; it lives MCP_CLEARANCE_TTL seconds.
  3. Solver — a detected challenge page is handed to an external request-based solver (cfsolve), which runs through the same proxy, up to three exits. The clearance is then replayed and cached.
  4. Widget — a page carrying a Turnstile sitekey gets a solved cf_turnstile_response in turnstile (disable with MCP_SOLVE_TURNSTILE=0).

Without a solver the server still fetches and reports the challenge. On the host the default command is cfsolve built in WSL at ~/cfsolve; in the image it is /opt/cfsolve/challenge. Override the prefix with MCP_SOLVER (JSON array) or disable with MCP_SOLVER=off. MCP_SOLVER_PROFILE holds the solver's fingerprint file, whose User-Agent identity is reused for replay.

Reports

Failures are not detected automatically — the model reports them, because only it knows the content was needed and that it already tried every rung. report stores one row per host and category in MCP_REPORT_FILE (.reports.jsonl by default); repeating a failure merges into the same open row and raises hits, so re-reporting costs nothing.

Report when a task's need on that host is exhausted: challenge still returned after solver retries, JavaScript-only shell, login or paywall, datacenter ban, needed text absent, selector from the outline matching nothing. Do not report a first timeout, a 404 from a guessed URL, or a typo in your own selector. needed says which fact was wanted; attempts lists what was already tried; note says what the page showed instead.

Close the queue one at a time: reports lists open rows by hits, then reports_update(id, "closed" | "ignored", note) records the fix or the decision. open reopens a row that still reproduces.

Verification

  • uv run --locked smoke_proxy.py — loopback stand: all four proxy schemes, credentials, round-robin, pin reuse, dead-proxy failover, wrong credentials, whole-pool outage, no direct fallback, 429 with and without room in the deadline, and pool replacement during an in-flight request. No external network.
  • uv run --locked smoke_live.py — real MCP client against the live server on the direct route: HTML, documentation, JSON, snapshot views, batch isolation, error reporting.

Both are checks, not benchmarks. Upstream pages change.

Image

Built by CI only. Two tags exist: sha-<12> is immutable and identifies a commit; latest moves only when HEAD has not changed during the run, so it can lag but never lies.

docker pull git.eeee.moe/omar/fetch-mcp:latest   # public, no login
docker run -d --name fetch-mcp -v fetch-mcp-data:/data \
  -e MCP_LIVE_ROUTE=proxy \
  -e MCP_PROXY_LIST_URL=https://your-list -e MCP_PROXY_LIST_TOKEN=... \
  git.eeee.moe/omar/fetch-mcp:latest

The image runs as UID 10001 and writes clearance and reports under /data. The request-based solver is built in at /opt/cfsolve/challenge with its Safari-iOS profile, so the clearance rung works without WSL and without a browser; MCP_SOLVER=off disables it, and MCP_SOLVER_PROFILE points at another profile. The solver is pinned by commit in the image (CFSOLVE_COMMIT), and CI checks its --help offline.

ci/Dockerfile is the runner-side image (uv, git, node, docker CLI); it is built by the operator, not by CI.