Skip to content
mike-nottPublic

About

Self-hosted MCP server on Cloudflare Workers: web search (keyword + semantic), Reddit, X, YouTube, Discord and page reading — one worker, one token, no LLM in the pipe

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Web-MCP

Give any AI agent the parts of the web it can't reach.

Cloudflare Workers TypeScript MCP License: MIT

Reddit and X block LLM traffic. Ordinary pages sit behind Cloudflare challenges. Search returns the marketing layer while the real answers sit in comment threads. A video's or a podcast's content is locked in its audio. Filings, statistics and trial records sit behind data-provider APIs rather than on pages. And a local model with no search tool can't look up anything at all.

One endpoint fixes all of it. Deploy once to your own Cloudflare account, register one URL and one token, and every agent session gets the same reach.

flowchart LR
    A["<b>Your agents</b><br/>Claude Code · OpenClaw<br/>local LLMs · any MCP client"]
    W["<b>Web-MCP</b><br/>your Cloudflare Worker"]
    A -->|one URL + one token| W
    W --> R["<b>Reddit</b><br/>posts · scored comments<br/>community discovery"]
    W --> X["<b>X</b><br/>posts · replies"]
    W --> Y["<b>YouTube</b><br/>videos · comments<br/><b>transcripts</b>"]
    W --> PO["<b>Podcasts</b><br/>dialogue search<br/><b>transcripts</b>"]
    W --> S["<b>Open web</b><br/>keyword · semantic · news"]
    W --> P["<b>Walled pages</b><br/>bot-blocked · JS shells · PDFs"]
    W --> D["<b>Data providers</b><br/>SEC · statistics · trials<br/>patents · papers"]
Loading

What it actually gets you

Ask "what's the best local video model right now?" — a question no search engine answers honestly:

Step Tool What comes back
1 find_communities r/StableDiffusion (986k), r/LocalLLaMA (792k)
2 social_search The threads practitioners wrote this week
3 get_thread "Minimum for 480p is a 3060 with 12GB… ~9 minutes" — from the ComfyUI lead, plus 193 comments of dissent
4 fetch_page The vendor's benchmark page that returns 403 to everyone else
5 fetch_page on a video The spoken transcript of the tutorial

That's information that doesn't exist in any search index, and none of it needed a browser.


Start free — three keys, no card, most of the capability

These three cost nothing, ever:

Provider Unlocks Free allowance
Reddit Post search, scored comment trees, subreddit discovery Unlimited (1,000 req/10min)
YouTube Video search, comments, view/like signals ~100 searches/day
Tavily Keyword web search — everyday lookups 1,000 credits/month

Stop there and you already have: community discovery · Reddit + YouTube search with engagement signals · full scored comment threads · keyword web search · and page fetching for every site that isn't actively blocking you.

That's five of the six tools working, for £0 — only alexandria needs a (FireCrawl) key.

Then add what you actually need

Provider Unlocks Cost
FireCrawl Reads bot-protected pages and PDFs — and, with the same key, the alexandria data catalogue Pages: 1–5 credits, only when blocked. Alexandria: free to find and inspect, each call at its listed price
Supadata Video transcripts (YouTube, TikTok, Instagram, X) 1 credit each
Exa Semantic search — finds pages whose keywords you can't guess, plus find-similar ~$0.007/call
TwitterAPI.io X search and reply threads ~$0.15/1k tweets
Brave Keyword search with an independent index + publication dates ~$5/1k, no free tier
Currents News search — web_search mode news, with country, language and publisher filters Free 250/day; Builder $69/mo for 2,500/day
Particle Podcast search — what was actually said, speaker-labelled — plus full transcripts $10 free credit; Individual $29/mo for 10,000 calls
Discord Message search across the servers a dedicated account has joined (needs a free companion process on a machine you own — see below) Free — the companion runs on your own hardware

MCP_AUTH_TOKEN is the only required secret. Every source is independent, and the server only advertises tools whose providers are configured — your agent is never offered something it can't use, and never discovers that by failing.


The tools

Reach the discussion — where practitioners actually talk

Tool
social_search Search Reddit, X, YouTube and podcasts — and Discord servers a dedicated account has joined (opt-in: pass platform: "discord"). Returns engagement signals — scores, views, comment counts, authors, dates — so you can weigh consensus yourself
get_thread The full scored comment tree. High-voted dissent is often the most valuable thing on the page (Reddit, X, YouTube; podcasts use fetch_page instead)
find_communities Which subreddits own a topic. Scoping a search is the single biggest quality lever

Reach the page — anything that blocks you

Tool
fetch_page Bot-protected pages, JavaScript shells, PDFs, and video and podcast transcripts. Free direct fetch first; paid escalation only on a genuine wall

Reach the open web — for everything else

Tool
web_search keyword mode for factual lookups; semantic mode for "essays arguing against microservices" — pages that never use those words; news mode for current coverage by country and publisher

Reach the data — records that live behind provider APIs, not on web pages

Tool
alexandria FireCrawl's catalogue of several hundred data providers — SEC filings, company financials, economic statistics, clinical trials, patents, research papers, government data. find a tool, inspect its inputs and price, then call it

Six tools. No LLM inside the worker, no ranking, no summarising — raw signals go straight to the calling model, which does the thinking. Sprawling tool surfaces bloat context windows and confuse routing.


How it works

fetch_page escalates — free first, paid only when necessary

flowchart TD
    U["fetch_page(url)"] --> PC{"Podcast<br/>episode URL?"}
    PC -->|yes| PT["Particle transcript<br/><i>1 call</i>"]
    PC -->|no| V{"Video URL?"}
    V -->|yes| T["Transcript<br/><i>1 credit</i>"]
    V -->|no| G{"country set?"}
    G -->|yes| F
    G -->|no| D["Direct fetch + HTMLRewriter<br/><b>FREE</b>"]
    D --> C{"Blocked, JS shell,<br/>or PDF?"}
    C -->|no| OK["Clean text ✓"]
    C -->|yes| F["FireCrawl stealth proxy<br/><i>1–5 credits</i>"]
    F --> OK2["Clean text ✓"]
    F --> ERR["Explicit error —<br/><b>never</b> the challenge page's HTML"]
Loading

That last box matters more than it looks. The common failure mode elsewhere is an agent confidently summarising a Cloudflare interstitial it mistook for content. Web-MCP tells you it failed.

Keyword search can merge two independent engines

flowchart LR
    Q["keyword query"] --> TA["Tavily<br/><i>page text</i>"]
    Q --> BR["Brave<br/><i>publication dates</i>"]
    TA --> M["dedupe + merge"]
    BR --> M
    M --> RES["One result carrying<br/><b>date AND full text</b><br/><i>neither engine returns alone</i>"]
Loading

Their indexes are largely disjoint, so recall roughly doubles. Every result lists which engines found it — cross-index agreement is handed to your model as a signal, not baked into a ranking here.

alexandria — find, inspect, then call

flowchart LR
    N["What data do you need?"] --> FI["find<br/><b>FREE</b>"]
    FI -->|"ranked tools + prices"| IN["inspect<br/><b>FREE</b>"]
    IN -->|"inputs + response fields"| CA["call<br/><i>listed credits</i>"]
    CA --> OUT["Data + source attribution"]
    CA -.->|"wrong option"| E["Free error listing<br/>the valid options"]
    E -.-> CA
Loading

FireCrawl's catalogue covers several hundred providers. Discovery never costs anything, and a mistaken call is refused for free with the options it would accept, so the calling model can correct itself. FireCrawl's own "rate this before you answer the user" instruction is stripped from every result.

Everything is cached in KV and every paid provider has a daily spend ceiling that fails with a readable message rather than a surprise bill. Alexandria's ceiling is counted in credits rather than calls, and every Alexandria call is logged for 90 days.

Extending it, or want the reasoning behind the design? ARCHITECTURE.md covers the principles, how to add a provider, and the per-provider gotchas that aren't in any vendor's docs.


Setup

The fast path — clone the repo, then one command:

./setup.sh

It generates your token, creates your KV namespace, deploys, and — if you want Discord — offers to install the companion on that machine right away, passing the token along so you never paste it twice. Re-run any time; existing tokens and namespaces are kept unless you say otherwise.

What setup.sh does step by step (or do them by hand)

1. Generate your token — the only credential your clients need:

echo "webmcp_$(openssl rand 32 | base64 | tr '+/' '-_' | tr -d '=\n')"

2. Grab the provider keys you want (all optional):

Reddit — free, ~2 minutes

At reddit.com/prefs/apps: create another app… → type script → redirect URI http://localhost (unused). Copy the client ID (under the app name) and secret.

Set REDDIT_USER_AGENT in wrangler.toml to identify your app — e.g. cf-worker:web-mcp:v1 (by /u/yourusername). Reddit requires a unique, descriptive UA.

YouTube — free

console.cloud.google.com → create/pick a project → APIs & Services → Library → "YouTube Data API v3" → Enable → Credentials → Create Credentials → API key.

Empty API-restrictions dropdown? The API isn't enabled on that project yet — the dropdown only lists enabled APIs.

Quota: search costs ~100× more than metadata or comments, so only search is scarce and only search is budgeted here.

Keyword search — Tavily and/or Brave

Configure this if your MCP client has no web search of its own (a local LLM, for instance).

  • Tavily — 1,000 credits/month free, native domain filters, full page text, no publication dates
  • Brave — independent index, publication dates, no free tier since Feb 2026

KEYWORD_SEARCH_PROVIDER = auto | tavily | brave | both. Defaults to both (parallel + merged). For free-tier-only running, set it to auto.

Semantic search — Exa

dashboard.exa.ai. Matches meaning, not keywords — and does find-similar-by-URL, which nothing else here can do.

Complementary to keyword search, not a replacement: semantic is measurably weaker at plain factual lookups.

X — TwitterAPI.io

twitterapi.io — instant key, no X developer approval, ~$0.15/1k tweets. A small free allowance lets you test, throttled to 1 request/5s until you add credits.

Bot-protected pages — FireCrawl

firecrawl.dev. fetch_page works without it on open pages — it only escalates at a genuine wall. 1 credit, up to 5 with the enhanced proxy.

The same key unlocks the alexandria tool (FireCrawl's Alexandria data catalogue). Finding and inspecting tools is free; a call costs the credits the tool lists, and some tools are priced per record. Calls count against ALEXANDRIA_DAILY_CREDIT_LIMIT (default 1,000 credits a day), separate from the page-scrape cap. The cost is only known after a call, so one per-record call can overshoot the cap — every call is therefore logged to KV for 90 days: npx wrangler kv key get alexandria:log:YYYY-MM-DD --binding KV --remote.

Video transcripts — Supadata

supadata.ai, 100/month free. Required because the official YouTube API cannot return transcripts: captions.download needs the video owner's OAuth, and auto-generated captions aren't exposed at all.

News search — Currents

currentsapi.services → sign up → copy the API key. Adds mode: "news" to web_search. One search covers at most 31 days, and results are cached for only 15 minutes because Currents' terms do not allow keeping copies. The free plan cuts descriptions to 300 characters; paid plans return much longer extracts. CURRENTS_DAILY_LIMIT defaults to 2,000 (Builder allows 2,500, and refuses rather than bills past that).

Podcasts — Particle

particle.pro → API key. Adds platform: "podcasts" to social_search (keyword search over transcribed, speaker-labelled dialogue), and fetch_page on a returned episode URL gives the full transcript. Podcasts are in "all" but not the default. Every call counts, and the Individual plan bills overage, so PARTICLE_DAILY_LIMIT defaults to 300/day (about 9,000 a month).

3. Run locally (optional):

npm install
cp .env.example .dev.vars   # fill in whichever keys you have
npm run dev                 # http://localhost:8787/mcp

4. Deploy:

export CLOUDFLARE_ACCOUNT_ID=<your-account-id>   # npx wrangler whoami

npx wrangler kv namespace create KV
# paste the returned id into wrangler.toml

echo "<value>" | npx wrangler secret put MCP_AUTH_TOKEN   # required
# ...then one line per provider key you're using

npm run deploy

The free Workers plan covers personal use comfortably.

5. Connect your client:

The server is stateless Streamable HTTP — any MCP client works with just a URL and a header.

Claude Code:

claude mcp add --transport http --scope user web-mcp \
  https://web-mcp.<your-subdomain>.workers.dev/mcp \
  --header "Authorization: Bearer <MCP_AUTH_TOKEN>"

Restart afterwards — Claude Code loads MCP servers at startup.

Jan, or any client with an "add MCP server" dialog:

Field Value
Transport HTTP (Streamable HTTP)
URL https://web-mcp.<your-subdomain>.workers.dev/mcp
Header name Authorization
Header value Bearer <MCP_AUTH_TOKEN>

Leave Command / Args / Env empty — those are for stdio servers.

The server speaks both halves of Streamable HTTP: plain JSON responses, or SSE when your client asks for text/event-stream (including the GET stream clients open for server-initiated messages). Long-running calls emit keepalive heartbeats, so transcripts and bot-protection escalations won't trip your client's idle timeout.

Clients that only speak stdio can bridge with mcp-remote: command npx, args -y mcp-remote <url> --header Authorization:${AUTH_HEADER}, and AUTH_HEADER=Bearer <token> in env. The colon has no space after it deliberately — several clients mangle spaces inside args when invoking npx.


Good to know

  • Search technique matters. Reddit, X, YouTube, podcasts and news all match keywords, not meaning — a natural-language question silently degrades into "merely popular posts". Short keyword queries win, and scoping to a subreddit is the biggest lever. The tool descriptions teach your model this, so you don't have to.
  • News search requires every word to appear and accepts OR, NOT and quoted phrases. Agency stories syndicated across outlets under one headline are collapsed to one result, with a note of how many repeats were removed.
  • Podcasts are opt-in. platform: "podcasts" searches them directly and "all" includes them; the default fan-out (Reddit + X) never does, because every Particle call counts against a monthly plan.
  • Alexandria per-record pricing. Some data tools charge per record returned (one contact-lookup tool is 300 credits a record). The price is shown by find and inspect, but the cost of a call is only known afterwards, so one large per-record call can overshoot the daily credit cap. Read a day's log with npx wrangler kv key get alexandria:log:YYYY-MM-DD --binding KV --remote.
  • Geo-targeted fetch. Pass country (ISO 3166-1 alpha-2, e.g. US, DE, JP) to fetch_page to read a page as seen from that country — for geo-restricted or geo-varying content. Country-level only, and it forces the paid FireCrawl tier (the free fetch uses the worker's own IP and can't be geo-located).
  • Transcripts cost 1 credit using existing captions. generate: true transcribes audio instead, billed per minute — a 60-minute talk ≈ 120 credits. Opt-in only.
  • TwitterAPI.io is third-party — ~30× cheaper than the official X API, but grey-market. src/providers/ is abstracted, so swapping is contained.
  • Privacy. Single-user by design: one shared token, no accounts. Don't publish your worker URL and token together.

Discord companion

Discord is shipped as platform: "discord" on social_search — but it needs one extra piece, because Discord's Cloudflare edge blocks every request whose TLS handshake originates from a Cloudflare Worker (403 regardless of exit IP or headers). The fix: a tiny companion process on any always-on machine you own (Mac, Linux box, NAS). It holds an outbound WebSocket to your worker; Discord searches are relayed through it and executed with that machine's real residential/network IP and TLS stack.

MCP clients ──▶ CF Worker ──▶ Durable Object ──WebSocket──▶ companion (your box) ──▶ Discord

Multiple companions can connect simultaneously — requests rotate across them and fail over if one goes down. Any companion can serve any request, so install it on every machine you have.

Setup — the companion needs the worker to already have DISCORD_USER_TOKEN set (see below for how to get it). Then, on each machine you want as a companion (Linux or macOS):

curl -fsSL https://raw.githubusercontent.com/mike-nott/web-mcp/main/companion/install/install.sh | bash
#   — asks for your MCP_AUTH_TOKEN (the same token your MCP clients use;
#     there is no third secret to create), then installs as systemd
#     (Linux) or launchd (macOS)

Running ./setup.sh in a fresh clone does all of this — worker deploy, Discord token, and the companion on that machine — in one pass, passing the token along so it is never typed twice. The curl | bash form above is for adding more machines later.

Verify from any MCP client: social_search { query: "test", platform: "discord", time: "month" }

Getting DISCORD_USER_TOKEN: log into a dedicated Discord account (never your primary) in a browser, open DevTools → Network → click any discord.com/api request → Request Headers → copy the Authorization value. It rotates if that account changes its password or hits "log out all devices" — the tool's 401 message names the fix. A search is only that account's own servers, kept low-volume by a 100/day cap; there are no reactions in search results, so results carry no score.

What the companion is and isn't: it refuses anything that is not a GET under discord.com/api/v10, needs only Node ≥18 (zero npm dependencies), and never writes the Discord token to disk — the worker sends it per-request over the authenticated WebSocket. If no companion is connected, Discord search returns a readable error telling you to start one; every other platform is unaffected.

Issues and ideas welcome.

License

MIT

About

Self-hosted MCP server on Cloudflare Workers: web search (keyword + semantic), Reddit, X, YouTube, Discord and page reading — one worker, one token, no LLM in the pipe

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages