Skip to main content
Glama
mcp-tools
by stef7
README.md
# mcp-tools

Cloudflare Workers that speak MCP, in one TypeScript repo.

```
core/mcp.ts                  shared plumbing: HTTP MCP endpoint + RPC surface + tool typing
core/web.ts                  what a worker touching the open web needs: stripHtml, a browser UA
core/egress.ts               smart / tunnel / browser in the order you pick, then a plain fetch
core/proxy.ts                fetch through an HTTP proxy over a raw socket (CONNECT + TLS)
core/apify-ca.ts             the key Apify's Unblocker re-signs HTTPS with, for core/proxy.ts
core/vendor/subtls.mjs       TLS 1.3 in JavaScript (jawj/subtls), built by scripts/vendor-subtls.mjs
test/                        vitest, run against mocks rather than anyone's live service
workers/mcp-toolkit/         aggregator: its own tools + every worker bound under `services`
workers/mcp-wp/              WordPress REST API -> MCP, read and write
workers/mcp-fetch/           fetch one URL in the format you ask for, cache it, search the cache
workers/mcp-archives/        the Wayback Machine: TimeMap, CDX, Save Page Now
workers/mcp-un-docs/         UNISPAL, the UN Digital Library, ODS symbols, RightDocs
workers/mcp-abc-search/      ABC's Algolia index, transcripts included
workers/mcp-abc-ombudsman/   ABC Ombudsman complaint findings
workers/mcp-data-gov-au/     data.gov.au over CKAN, including raw SQL
workers/mcp-ghost/           Ghost publications, with member sign-in for paid posts
workers/mcp-apify/           what Apify is costing you, by service and by Actor
workers/mcp-happyhousesitters/ house sits on happyhousesitters.com.au, ranked around a date
workers/mcp-righttoknow/     FOI requests on Right to Know: JSON only, challenged pages behind `full_` tools
workers/mcp-qon/             Senate questions on notice and estimates questions, from aph.gov.au/qon
workers/mcp-helios/          Helios Voting: read, verify and run elections. Its own door, not in the toolkit
workers/mcp-printify/        Printify: search its API, call it, upload artwork. Its own door too
workers/mcp-nc/              Nextcloud calendars over CalDAV, read and write. Its own door too
workers/mcp-mail/            a private inbox: mail forwarded to one address, kept in D1. Own door
scripts/mock-wp.mjs          fake WordPress for local testing
scripts/mock-ghost.mjs       fake Ghost, including the magic-link sign-in
scripts/cf-tunnel-relay.mjs  runs on the Mac at the far end of the tunnel
scripts/cf-tunnel-relay-menu.swift
                             CF Tunnel Relay.app: menu bar switch that runs the relay and cloudflared
scripts/build-cf-tunnel-relay-app.sh
                             builds that app into ~/Applications and opens it
scripts/mock-proxy.mjs       fake Apify Proxy, for the proxy tests, re-signing HTTPS as Apify does
scripts/mock-helios.mjs      fake Helios, for the election lifecycle tests
scripts/mock-printify.mjs    fake Printify: catalogue, uploads, products, orders, rate limits
scripts/mock-nextcloud.mjs   fake Nextcloud: CalDAV discovery, calendars, events, recurrence
scripts/seal-nextcloud.mjs   encrypts a Nextcloud login for mcp-nc; prints the seal and its key
scripts/vendor-printify-spec.mjs
                             trims Printify's OpenAPI document into workers/mcp-printify/src/spec.json
scripts/apify-tls-probe.mjs  checks HTTPS through the real Unblocker the way the Worker does it
scripts/apify-trust-anchor.py
                             rebuilds core/apify-ca.ts from certificates Unblocker presented
```

## A worker is a tools object

```ts
import cfg from "../wrangler.json";
import pkg from "../package.json";
import { mcpWorker, tool } from "../../../core/mcp";

export default mcpWorker({
  ...cfg, // name + services come straight from wrangler.json
  version: pkg.version,
  tools: {
    hello: tool({
      description: "Say hi",
      input: { type: "object", required: ["name"], properties: { name: { type: "string" } } },
      run: ({ name }) => `Hi ${name}`, // `name` is typed from `input`; nothing declared twice
    }),
  },
});
```

Rules the core enforces so nothing needs a mapping table:

- The object key is the tool name. Exposed as `<worker>_<key>`: worker `mcp-wp` -> `wp_search_posts`.
  A worker can set `prefix: ""` to drop that, as mcp-toolkit does for its own three tools.
- `run` may return a string, any JSON value, or a full MCP result (`{ content, isError }`).
- `tools` may be a function of the request context when tools depend on the connector URL.
- A worker with `services` in its wrangler.json re-exports those workers' tools and routes calls by
  prefix. The connector's query string is forwarded, so each worker reads its own params. A bound
  worker that is down loses its own tools and nothing else; the GET page lists what it could not
  reach.

## Connector URLs

| URL                                                 | You get                                             |
| --------------------------------------------------- | --------------------------------------------------- |
| `mcp-toolkit…/`                                     | everything                                          |
| `mcp-toolkit…/?tools=wp`                            | only the `wp_*` tools                               |
| `mcp-toolkit…/?tools=archives,un_docs`              | two whole toolsets                                  |
| `mcp-toolkit…/?tools=wp_get_content,acast_episodes` | exactly those two                                   |
| `mcp-toolkit…/?wp=apil.au`                          | tools generated from that site (posts, events, …)   |
| `mcp-toolkit…/?wp=apil.au,crikey.com.au`            | one set per site, named `wp_<site slug>_<tool>`     |
| `mcp-wp…/?wp=apil.au&title=APIL`                    | the wp worker alone (`?site=` still works as alias) |
| `mcp-wp…/https://apil.au?title=APIL`                | the same, with the site in the path                 |

Tools named `create_*`, `update_*` and `delete_*` change the live site. See **Editing a site**.

## Local development

```sh
npm install
npm run check                                   # wrangler types + tsc, every worker
npm test                                        # the suite, against the mock WordPress
npm run format                                  # prettier, 100 columns
node scripts/mock-wp.mjs 8799 &                 # a fake WordPress
cd workers/mcp-toolkit && npx wrangler dev -c wrangler.json -c ../mcp-wp/wrangler.json
curl 'http://localhost:8787/?wp=http://localhost:8799'   # lists the generated tools
```

Two `overrides` in `package.json` hold the test tooling together. The Vitest pool pins a Miniflare
whose runtime stops at an older compatibility date than the workers ask for, so it is pointed at
the Miniflare that the workers' own Wrangler uses; move that pin when Wrangler moves. `sharp` is
lifted to a patched release; only local image simulation uses it, never a deployed worker. npm 10
fails to resolve Vitest 4's optional peers from scratch, so regenerate `package-lock.json` with
`npx npm@11 install`; `npm ci` on npm 10 installs the result fine.

`worker-configuration.d.ts` is generated by `wrangler types` and committed so any editor
type-checks a fresh clone. Re-run `npm run check` after touching a `wrangler.json`.

## Deploying (GitHub Actions)

`.github/workflows/ci.yml` runs everything, from pull request to production:

- **Pull request:** the checks, and each changed worker is compiled. A worker whose
  `wrangler.json` changed is also uploaded to Cloudflare as a version that is not deployed, which
  catches what only Cloudflare can refuse (a setting the plan does not allow, a binding that does
  not resolve, a missing required secret) before anything merges. A code-only change uploads
  nothing, so a PR does not push unmerged versions to the top of a worker's version list. A
  worker that is not on Cloudflare yet is only compiled, because a worker's first upload has to
  be a deploy.
- **Push to `main`:** the checks, then a deploy of each changed worker. The deploys wait for the
  checks, so a red `main` never ships.
- **Run workflow** (Actions tab): the checks, then a deploy of every worker.

**"Changed" means the deployed code changed**, not the files. The `plan` job
(`core/ship.mjs`) builds every worker exactly as `wrangler deploy` would, and fingerprints each
bundle together with its `wrangler.json`. Every deploy stores that fingerprint on the new version
as its tag, so the next plan compares against what Cloudflare is actually serving. A `core/`
change reaches only the workers whose bundle it alters (a change to `core/egress.ts` ships
`mcp-fetch` alone), and a README, a test or a comment ships nothing. Workers import only `version` from their
`package.json` (`import { version } from "../package.json"`), never the whole file: a whole-file
import inlines `devDependencies` into the bundle, so bumping a dev tool would redeploy every worker. Each worker's summary is in
the run's summary page. Reading what is live survives a bad minute at Cloudflare: a 5xx, a 429 or
a dropped connection is tried again after 2, 4 then 8 seconds before the plan fails. Any other
error fails it at once, since guessing "changed" would hide a broken token.

Each changed worker then gets **its own job, in parallel**. Only `check` installs the whole
workspace: no worker has npm dependencies of its own, so `plan` builds with wrangler alone, and
each worker's job restores wrangler from the cache `plan` filled and ships the bundle `plan`
built, byte for byte.

`mcp-toolkit` and `mcp-wp` set `"preview_urls": false`. Without it, every upload from a pull
request would get a live URL running unmerged code against production resources.

It needs two repository secrets: `CLOUDFLARE_API_TOKEN` (Workers Editor on these workers, plus
Connectivity Directory Bind for `mcp-fetch`'s tunnel) and `CLOUDFLARE_ACCOUNT_ID`. The Worker name in the dashboard must equal `name` in that folder's
`wrangler.json`. Bindings live in `wrangler.json`; secrets stay in the dashboard (`keep_vars`
keeps plain variables too, so `WP_SITES` survives a deploy).

## Adding a worker

1. Copy `workers/mcp-wp` to `workers/mcp-<name>`; set `name` in `wrangler.json` and `package.json`.
2. Replace `tools` in `src/index.ts`.
3. Add `{ "binding": "<NAME>", "service": "mcp-<name>" }` to `workers/mcp-toolkit/wrangler.json`.
   The binding name is yours; the prefix comes from `service`, so `mcp-un-docs` gives `un_docs_`
   and a worker from another repo keeps its own name — `shop` gives `shop_`.

   That derivation is a guess, and a bound worker is free to disagree with it: one that sets its
   own `prefix`, or that is an aggregator re-exporting the prefixes of the workers bound to _it_,
   answers to names this repo cannot derive. Its tools are listed under their real names either
   way, and a call no prefix claims falls back to asking each bound worker which names it lists,
   so nothing is listed-but-uncallable. Add `"prefix"` — a string, or a list — to skip that
   lookup, which costs every bound worker a tool list — worth doing once you have confirmed what
   a worker really answers to, e.g. `"prefix": ["shop_", "stock_"]`. Declare it wrong and the
   fallback cannot save you: the call goes to the worker you named and stops there.

4. `npm run check`, commit, push to `main`; the deploy workflow picks the new folder up.

## Getting past blocks

`mcp-fetch` downloads through `core/egress.ts`, which tries the routes you name, in the order
you name them. It moves to the next when a route cannot connect, or when the answer is a block:
status 403, 429, 451 or 503, or a challenge header — Cloudflare's `cf-mitigated: challenge`, or
AWS WAF's `x-amzn-waf-action: challenge` (sent as a 202) or `captcha` (a 405). Only headers are
checked; the body is never read to decide. Any other answer, 404 included, is kept.

After the named routes comes the **fallback**: the worker's own `fetch`, from a Cloudflare colo.
It is free, always there and has no name, and its answer stands, whatever it is. Only if it cannot
connect at all does the last blocked answer from a named route come back instead.

1. **smart** (the default) — Apify Proxy's `UNBLOCKER` group, through `core/proxy.ts`. It routes
   each request to get the page, usually through a proxy, dealing with bot checks and CAPTCHAs
   itself, and picks the country; none is pinned, since Apify says that weakens it. A
   Worker's `fetch` cannot use an HTTP proxy, so this opens a TCP socket to `proxy.apify.com:8000`
   and sends `CONNECT`. Needs `APIFY_PROXY_PASSWORD` on `mcp-fetch` — the password on Apify
   Console -> Proxy, not an API token — and a paid Apify plan. Billed per successful request. Any
   refusal (407, Apify's 590–599) moves on. Any error status (400 and up, 404 and 502 included) or
   failure code from Apify is tried once more, and the second answer stands; `skipped` says so. A
   407 is not retried, nor is a failure with no status (TLS, a timeout). A retry may be billed as a
   second request.

   Unblocker re-signs HTTPS with its own key ("Apify Proxy CA"), which the runtime's TLS will not
   accept and cannot be told to. So TLS inside the tunnel is done in JavaScript, by a vendored
   build of [subtls](https://github.com/jawj/subtls) (`core/vendor/subtls.mjs`), trusting that key
   alone: certificates are still checked, against Apify instead of the public authorities. Apify
   does not publish the key, so it was recovered from the signatures on two certificates
   Unblocker presented, and `test/apify-ca.test.ts` checks it against them. subtls speaks TLS 1.3
   only, which Unblocker accepts. Its author calls it a proof of concept, not for production use.

   If every https URL starts failing this route on the certificate, Apify has probably changed its
   key. To check, and to rebuild `core/apify-ca.ts`:

   ```sh
   read -rs APIFY_PROXY_PASSWORD; export APIFY_PROXY_PASSWORD
   node scripts/apify-tls-probe.mjs example.com      # last line: subtls OK or FAILED
   node scripts/apify-tls-probe.mjs www.wikipedia.org
   # save each certificate it prints to a .pem file, then:
   python3 scripts/apify-trust-anchor.py a.pem b.pem  # prints the new certificate
   ```

2. **tunnel** — a home connection in Australia, only while the Mac is on. `env.TUNNEL` is a VPC
   Service binding (`vpc_services` in `mcp-fetch/wrangler.json`) to the `wmac` service:
   `localhost:8811` on the Mac behind Cloudflare Tunnel `WMac`. Run
   `node scripts/cf-tunnel-relay.mjs` there; `ALLOW_DOMAINS=a.org,b.gov.au` limits it to those
   domains and their subdomains. Alongside each page the Worker asks the relay's `/health`, which
   answers at once. If it fails first (no answer within 2 seconds, or Cloudflare saying the tunnel
   is down), the page is dropped and the tunnel skipped for a minute; if the page answers first,
   the check is dropped. Either sign of a live Mac is remembered for 30 seconds, and a page that is
   merely slow costs only that request (the relay gives up on a site after 30 seconds).
3. **browser** — the same Mac and relay, with the page loaded in Brave there, always in a window
   you can see: it waits up to 45 seconds on a check page, for one that clears itself or for you
   to pass it in that window, and has whatever sign-ins and passed checks you made with Pass a
   check in Brave… in the app's menu. The browser keeps its own profile in
   `~/.cf-tunnel-relay/profile`. Off unless the relay has `BROWSER_ALLOW_DOMAINS=a.org,b.gov.au`,
   and refused for every other domain, where the page starts and wherever it is redirected. Every
   connection the browser makes goes through a proxy inside the relay with the same private-address
   check as plain mode. Needs
   playwright-core, which `npm install` at the root of the clone brings, and Node 20 or later. Up to
   60 seconds a page.

### Setting up the Mac

The tunnel `WMac` and the VPC Service `wmac` live in Cloudflare, so a wiped Mac only needs one
app back: CF Tunnel Relay, a menu bar switch that runs the relay, which runs `cloudflared` for
`WMac`. There is no LaunchAgent or other background item: the app sits in System Settings ->
General -> Login Items -> Open at Login like any other, and quitting it stops both.

1. Install Node 18 or later (20 for browser mode), `brew install cloudflared` (the program only,
   with no `cloudflared service install`; the app runs it) and the Command Line Tools
   (`xcode-select --install`). Clone this repo.
2. From the clone, `sh scripts/build-cf-tunnel-relay-app.sh`. It builds
   `~/Applications/CF Tunnel Relay.app` and opens it; macOS 13 or later. It also removes the
   LaunchAgent `local.cf-tunnel-relay` that earlier versions installed.
3. The first time, the app asks for the tunnel token: in the dashboard, Networking -> Tunnels ->
   `WMac` -> Add a replica, copy the install command, and paste only its long `eyJ…` part. It goes
   into the login Keychain as the item `cf-tunnel-relay`, and never into a file or a command line.
   The app also puts itself in Open at Login (a notification says so).
4. The cloud in the menu bar: filled when the relay answers `/health` and `cloudflared` reports a
   live connection to Cloudflare (its metrics, on `127.0.0.1:8812`); with a `!` while either is
   starting or failing; slashed when off. Its menu has the on/off switch (which stays as left,
   across logins), Restart, Allowed domains… (`ALLOW_DOMAINS` and `BROWSER_ALLOW_DOMAINS`),
   Pass a check in Brave…, Replace tunnel token…, Open at Login, and the error log,
   `/tmp/cf-tunnel-relay.err`.
   `CHROME_PATH` and `CF_TUNNEL_RELAY_PROFILE` are set with
   `defaults write local.cf-tunnel-relay CHROME_PATH /path/to/browser`.
5. If the relay stops, the app starts it again after 5 seconds, doubling up to a minute while it
   keeps failing; the relay does the same for `cloudflared`. If the app goes without stopping
   them (a crash, a force quit), the relay notices its standard input close and stops both.
6. After a `git pull`, Restart in the menu picks up a new relay; run the build again only if
   `cf-tunnel-relay-menu.swift` changed or the clone moved. To remove it all: Quit, turn off Open
   at Login first if you like, and delete the app.
7. For browser mode, `npm install` at the root of the clone (it brings playwright-core) and Brave in
   `/Applications` (or `CHROME_PATH` as above). Some sites' checks will not clear for a browser
   that is being automated; for those, Pass a check in Brave… pauses the relay and opens the page
   in browser mode's own profile with nothing automating it. Pass the check or sign in, quit that
   Brave (⌘Q), and the relay starts again, with browser mode reusing what you got there until the
   site lets it lapse. `node scripts/cf-tunnel-relay.mjs login <url>` does the same from Terminal,
   with the tunnel switched off, since the profile can only be open in one browser at a time.

A `cloudflared` service installed the usual way (`sudo cloudflared service install <token>`) would
connect the Mac to `WMac` a second time, and keeps the token in plain text in its plist; the
app points it out, and `sudo cloudflared service uninstall` removes it.

Nothing here keeps the Mac awake. The tunnel goes down when the Mac sleeps and comes back when it
wakes: both programs carry on where they were, and `cloudflared` reconnects. While it is down,
`mcp-fetch` finds out from `/health` within 2 seconds and skips it for a minute.

The order is `via`: a list, `["tunnel", "smart"]`, or the same as a string, `"tunnel,smart"`.
The fallback always follows, so `["tunnel"]` with the Mac off gets Cloudflare's own fetch. Unset,
it is `EGRESS_VIA` on `mcp-fetch` (a plain-text variable, same format), and failing that `smart`.
An unknown name is an error, not skipped.

`fetch_url` records which route served each URL, and why earlier ones were skipped, in
`docs.meta_json`.

Any other worker can use the same routes without holding the tunnel or the password: bind
`{ "binding": "FETCH", "service": "mcp-fetch" }` and call
`await env.FETCH.egress(url, { headers, via })`. It returns the site's `Response` with
`x-egress-via` (`fallback` for Cloudflare's own fetch) and `x-egress-skipped` headers.

Binding a VPC Service needs the **Connectivity Directory Bind** role on whoever deploys, so the
`CLOUDFLARE_API_TOKEN` in Actions needs it too, or the `mcp-fetch` deploy fails.

## One public door

Only `mcp-toolkit` has a `workers.dev` URL. Every other worker sets `"workers_dev": false` and is
reachable only through the toolkit's service binding, so Cloudflare Access needs to sit on the
toolkit alone — core resolves the signed-in email there and forwards it over RPC.

`mcp-helios` is the one exception, on purpose: it is **not** bound into the toolkit and keeps
its own URL. Its admin tools act with a Helios session cookie, which is the administrator
themselves on Helios, so its tools should not appear on the connector everyone else uses. It gets
its own Access policy (the same steps as under **Auth**), listing the people running the
election, and that policy is also what identifies them to its `/login` page. To put it on the toolkit after all, add it to `services` like any other worker — but
then everyone on the toolkit's policy can see those tools, and the warning above about bindings
bypassing Access applies.

A bound worker still uses **its own** secrets: `APIFY_TOKEN` lives on `mcp-apify`, `WP_SITES` on
`mcp-wp`, the Ghost sessions on `mcp-ghost`. The toolkit holds none of them and never sees them.

**A service binding bypasses Access**, which matters for a worker bound from outside this repo.
It invokes the bound worker directly, so a worker with its own Access policy gets no second gate
here: whoever is on the **toolkit's** policy can call its tools. The forwarded email still drives
whatever authorisation the bound worker does for itself, but _reading_ is gated by the toolkit's
allowlist alone. Keep the two policies in step, or do not bind the worker.

`workers_dev: false` removes the `*.workers.dev` URL on deploy. A custom domain added in the
dashboard is not managed here and has to be removed there.

Point several connectors at the one worker to keep the grouping you want:

| Connector | URL                                                  |
| --------- | ---------------------------------------------------- |
| APIL      | `mcp-toolkit…/?wp=apil.au&tools=wp`                  |
| Research  | `mcp-toolkit…/?tools=archives,un_docs,fetch`         |
| Media     | `mcp-toolkit…/?tools=abc_search,abc_ombudsman,ghost` |

## Editing a site

Reads are open. Writing needs a login, and there are two ways to supply one.

### Either: a header on the connector

Claude connectors send only header names Anthropic has approved, and `X-Auth-Token` is one every
connector can use. Put a login in it as `user:application password` and `mcp-wp` uses it.
Nothing is stored on the worker, and the credential stays with whoever configured that
connector — so someone can be given write access without a Cloudflare account or an entry in
anything you maintain. Spaces in the password are fine — WordPress prints them in groups of four
and they are stripped before the request goes out.

One header is one login, so it is used only on a connector for exactly one site
(`?wp=apil.au`). On a connector for several sites there is no saying whose login it is, and in
generic mode it would go to whatever URL a tool call names, so there it is ignored; use
`WP_SITES` for those. `wp_login_status` says whether the header was used, and why not.

A header wins over `WP_SITES`. It also only exists while a person's connector is making the
request: anything unattended sends no headers, so `WP_SITES` is what a scheduled write would use.

### Or: `WP_SITES`, set in the dashboard on `mcp-wp` under Settings -> Variables and Secrets.

**1. `WP_SITES`, a plain variable** — who may edit what. Readable and editable, because none of it
is secret. Keyed by Cloudflare Access email, then hostname. `user` is the WordPress login, `pass`
is the _name of the secret_ holding that login's password:

```json
{
  "you@example.com": { "apil.au": { "user": "claude-mcp", "pass": "APIL_CLAUDE" } },
  "paul@example.com": { "apil.au": { "user": "paul-mcp", "pass": "APIL_PAUL" } }
}
```

**2. One secret per login**, named whatever you put in `pass` — here `APIL_CLAUDE` and
`APIL_PAUL`. The value is a WordPress **Application Password** (Users -> Profile -> Application
Passwords), not the account password.

Secret names are used exactly as written and never derived from the host or username: sanitising
those into one identifier would let different pairs collide (`apil.au` + `x_y` and `apil.au-x` +
`y` produce the same key). Naming them yourself also means the variable shows, at a glance, which
WordPress user and which secret each site is using.

There is no shared fallback. A site nobody is listed against is read-only, and so is everything if
Cloudflare Access is off, because then no identity reaches the worker. Access identity does not
cross service bindings, so the worker facing the browser resolves the email once and passes it on
with every RPC. Write tools simply do not appear when you have no login for a site, and every one
of them refuses to run until the caller passes `user_confirmed: true`.

Prefer a dedicated Editor-role WordPress user: application passwords inherit every capability the
account has and cannot be scoped.

A `get_*` tool returns the post body **exactly as WordPress stores it**, markup and all, because
reading one is usually the first half of editing it — stripping the HTML and writing it back
would replace the blocks, links and embeds with plain text. Search results still strip, since a
400-character preview of raw HTML is mostly angle brackets.

Sites running **The Events Calendar** are detected from their REST namespaces and get event, venue
and organiser tools that write through `tribe/events/v1`. The plain post tools stand aside for
those three types, because writing them through `wp/v2` silently drops the dates, venue and cost.

Sites running **WooCommerce** are detected the same way (`wc/v3`) and get `search_wc_*`,
`get_wc_*`, `create_wc_*`, `update_wc_*` and `delete_wc_*` tools for products, variations,
product categories, tags and reviews, orders, order notes, refunds, customers and coupons, plus
`get_wc_endpoint` to read any other route (reports, settings, shipping, system status), and
`update_wc_endpoint` and `delete_wc_endpoint` to write to any route the site's index says takes
it: a setting, a shipping zone, a tax rate. Most of those have no trash or history, so a write
reads the record first and returns it beside the result. Their
arguments are read from the site's own `wc/v3` index, so a field an extension adds shows up
without a code change here, and a method a route does not offer gets no tool. The `wp/v2` write
tools stand aside for products, as they do for events. Generic mode has `search_wc`, `get_wc`,
`create_wc`, `update_wc`, `delete_wc`, `get_wc_endpoint`, `update_wc_endpoint` and
`delete_wc_endpoint`, each taking a `url`.

Two differences from `wp/v2`:

- **WooCommerce will not serve anything without a login, reads included**, so none of these tools
  appear until a login is configured. Use a Shop Manager or Administrator. Either an
  Application Password or a WooCommerce REST key pair works, in `WP_SITES` or `X-Auth-Token`
  (`ck_…:cs_…`); a key pair unlocks only the WooCommerce tools, not the `wp/v2` writes.
- A new product is a **draft** unless you pass a status, because WooCommerce itself publishes by
  default. Customers, categories, tags, notes and refunds cannot be trashed, so WooCommerce
  refuses to delete them unless `force` is `true`, which deletes them permanently.

## Reading paid Ghost posts

Ghost's Content API never serves gated content: a members-only or paid post comes back with an
empty `html` whatever key you present. The body only exists in the page Ghost renders for a
signed-in member, so `mcp-ghost` signs in and reads that.

Ghost members have no passwords, so signing in is a magic link, in two tool calls:

1. `ghost_login` — asks the site to email you a sign-in link.
2. `ghost_login_complete` — you paste that link back; the worker follows it **itself** and keeps
   the two cookies Ghost sets in reply.

The link works once. Clicking it first, or a mail scanner following it, spends it on that browser
instead, and `ghost_login_complete` will say so. Sessions are stored in KV against your Cloudflare
Access email, so each person reads paid posts on their own subscription. `ghost_session_status`
says who you are signed in as; `ghost_sign_out` forgets it.

`GHOST_SITES` holds each site's Content API key, which Ghost itself calls safe to expose, so it
can be a plain variable:

```json
{ "www.lamestream.com.au": { "key": "79b548ddd5142126203cac8f8f" } }
```

An entry may still carry `cookie` and `cookie_sig` for a shared session, used when the person has
none of their own. Prefer signing in.

## Running an election on Helios

[Helios](https://vote.heliosvoting.org) has no API tokens. Public election data is JSON that
anyone can fetch; every administrative action is a Django form POST protected by the session
cookie of a browser that has logged in (Google or GitHub on heliosvoting.org) and a per-session
`csrf_token`, which `mcp-helios` scrapes from an admin page and submits the way the browser
would. There is no way for a worker to do that login for anyone, so each administrator does it
once in a browser and then opens the worker's own **`/login`** page, which is behind Cloudflare
Access: it names the cookie to copy (`sessionid`, under the browser's developer tools or a
cookie-manager extension), checks the pasted value against Helios, and keeps it in the
`SESSIONS` KV namespace against their Access email. From then on the tools act as that Helios
user for that person alone. The cookie never passes through a tool call, so it never sits in a
model's context; `helios_session_status` says who you are acting as without revealing it, and
`helios_sign_out` (or the page) forgets it. Logging out of Helios in the browser ends the session
everywhere; otherwise it lasts as long as Helios keeps it (two weeks of inactivity).

Access therefore has to be on `mcp-helios` — it is what tells the worker who is calling, as
well as who may. `?helios=https://…` on the connector URL points the worker at a self-hosted
Helios instead of heliosvoting.org (`HELIOS_URL` sets the default); sessions are kept per
server.

The tools follow the election through its life: `helios_create_election` → `helios_set_questions`
→ trustees → `helios_upload_voters` → `helios_freeze_election` → `helios_email_voters` →
`helios_compute_tally` → `helios_combine_decryptions` → `helios_release_result`, with
`helios_election_status` reading Helios's own "Next Step" box to say where things stand and
showing the tally to admins before release. Every change needs `user_confirmed`, and the
irreversible ones (freeze, tally, release, delete) say so in their descriptions.
`helios_freeze_election` runs Helios's readiness check and refuses with the list of issues.

Reading needs no login unless the election is private. `helios_verify_election_fingerprint` and
`helios_verify_ballot` recompute Helios's SHA-256 fingerprints from the published JSON
(`canonical.ts` reproduces Python's `json.dumps(sort_keys=True)` byte for byte) and compare them
with what the server displays, so a voter's tracker can be checked without trusting the server.
Full zero-knowledge verification stays with Helios's own JavaScript verifier, which the tools
link to.

Times on Helios are UTC. The tools take ISO 8601 with an offset (`2026-11-14T17:00+11:00`) and
convert; a value without an offset is taken as UTC.

## Selling on Printify

`mcp-printify` puts one Printify account behind three tools instead of one per endpoint:

- `printify_search` finds operations in Printify's API description by keyword and returns each
  one's method, path, summary, parameters and request-body schema, with an example.
- `printify_call` runs one operation by method and path. Path parameters, query and body are
  checked against the API description before anything is sent.
- `printify_upload_image` adds artwork to the media library from a public URL.

The API description is Printify's own OpenAPI document. `scripts/vendor-printify-spec.mjs` trims
it to operations, parameters and request bodies and writes `workers/mcp-printify/src/spec.json`,
which ships in the bundle; nothing fetches it at runtime. Re-run the script when Printify changes
its API, read the diff and commit it.

What may be sent:

- `GET` runs freely.
- Anything else needs `confirm: true` in the call, and the result restates the method, path and
  body that went out. Without it the call is refused and shows the request it would have made.
- Refused unless the variable `PRINTIFY_ALLOW_DESTRUCTIVE` is exactly `true`: every write to an
  order (creating one, standard or Express; sending it to production; cancelling it or a line
  item; refund and reprint requests; address changes), deleting or unpublishing a product,
  disconnecting a shop, archiving an upload, and any write to webhooks. It is unset by default;
  leave it that way unless you mean it. With it on, those calls still need `confirm: true`.

A `429` from Printify is waited out (for as long as `Retry-After` asks, up to ten seconds, three
times) and then reported with how long to wait. Lists are cut to a readable size: pass `find` to
keep the items containing some text and `fields` to keep only some keys, which is how one
blueprint is found by name in a catalogue of some three thousand.

To set it up:

1. **Create the token.** In Printify, open the account menu -> **Connections** -> **Personal
   access tokens** -> **Generate**. Name it, and choose custom scopes: reading shops, the
   catalogue, print providers, products, uploads and orders, plus writing products and uploads.
   Leave out writing orders and webhooks and managing shops, and Printify itself will refuse what
   this worker already blocks. Copy the token when it is shown; Printify shows it once, and it
   expires after a year.
2. **Store it as a secret**, once the worker exists on Cloudflare (its first deploy is the merge
   to `main`):

   ```sh
   cd workers/mcp-printify
   npx wrangler secret put PRINTIFY_TOKEN      # paste the token when asked
   ```

   The token goes to Printify as a Bearer header and nowhere else: no tool result, error or log
   line carries it.

3. **Put Cloudflare Access in front of it**, as under **Auth** below, on the `mcp-printify`
   worker: an Access policy listing who may use it, and Managed OAuth turned on. Like
   `mcp-helios` it is not bound into `mcp-toolkit`, because it acts on one person's shops.
4. **Add the connector in Claude.** Settings -> Connectors -> **Add custom connector**, and
   paste the worker's URL, `https://mcp-printify.<your-subdomain>.workers.dev/`. The sign-in that
   opens is the Access page.

Opening that URL in a browser shows whether the API description loaded, whether the token is
set, whether Printify accepts it, and whether destructive calls are on.

## Nextcloud calendars

`mcp-nc` reads and edits the calendars of one Nextcloud account over CalDAV. Calendars only, and
within them events only: no tasks, no contacts, and no inviting attendees.

| Tool                                      | Does                                                                      |
| ----------------------------------------- | ------------------------------------------------------------------------- |
| `nc_status`                               | whether the connector reaches Nextcloud, and why not                      |
| `nc_list_calendars`                       | id, name, colour, writable, shared or subscribed                          |
| `nc_create_calendar` `nc_update_calendar` | add; rename, recolour or redescribe. No deleting one                      |
| `nc_list_events`                          | a span of time, one calendar or all, with search                          |
| `nc_get_event`                            | one event in full                                                         |
| `nc_create_event` `nc_update_event`       | add, change; one occurrence or a series                                   |
| `nc_delete_event` `nc_move_event`         | move to the Bin calendar; move between calendars, and back out of the Bin |

Which Nextcloud and whose login reach the worker one of two ways.

**Sealed.** The address, login name and app password are encrypted together into one value,
`NC_SEALED`, which is all the worker stores. The key is not on the worker: it sits in the Claude
connector as an `X-Secret-Key` header, arrives with each request, opens the seal for that request and
is kept nowhere.

| Held by          | Holds                            | On its own                          |
| ---------------- | -------------------------------- | ----------------------------------- |
| Cloudflare       | `NC_SEALED`, the encrypted login | unreadable                          |
| Claude connector | `X-Secret-Key`, the key          | a key to something it does not have |

It is encryption, not hashing: a hash cannot be turned back into the password that has to be
sent to Nextcloud. The cipher is AES-256-GCM with a random 256-bit key, so there is no passphrase
to guess, and because it authenticates, a wrong key or an altered seal fails outright. The
address is inside the seal, so no request can point the password at another host. Neither the
address nor the login name is repeated in any result, error or status line.

`scripts/seal-nextcloud.mjs` makes both values. It runs on your own machine, asks for the three
things, talks to nothing, writes no file, and prints the seal and the key:

```sh
node scripts/seal-nextcloud.mjs
cd workers/mcp-nc && npx wrangler secret put NC_SEALED     # paste the seal
```

Then put the key in the connector's request headers as `x-secret-key`. Run the script again to rotate;
it makes a new key and a new seal, and both are replaced together.

What this does not do: while a request is being served the worker necessarily holds both halves,
so someone who can deploy code to the worker (a push to `main`, or the Cloudflare account) could
capture the key from the next request. Splitting the secret protects each store at rest. It does
not replace keeping those two accounts and the Access policy tight.

**With the request.** The alternative is to send all three with the request, in which case
nothing is stored on the worker and the seal is left shut:

- the address in the connector URL, or in an `X-Tenant` header;
- the login name in `X-Account-Id` and the app password in `X-App-Key`, or the two together in
  `X-Auth-Token` as `login:app password`.

The two ways are never mixed. An address from the request with a password from the seal would
send that password wherever the request pointed, so a request that brings `X-Secret-Key` and only
part of a login of its own is refused before anything is sent. A complete login in the request
is used as it stands.

| Part                                  | Means                                                                                |
| ------------------------------------- | ------------------------------------------------------------------------------------ |
| `X-Secret-Key: key`                   | opens `NC_SEALED`; sent alone                                                        |
| `mcp-nc…/https://cloud.example.com`   | the address, in the path (a folder install works: `…/https://example.com/nextcloud`) |
| `mcp-nc…/?nc=cloud.example.com`       | the address, as a parameter                                                          |
| `X-Tenant: https://cloud.example.com` | the address, as a header, where it is not on show                                    |
| `X-Account-Id: login`                 | the login name                                                                       |
| `X-App-Key: app password`             | the app password                                                                     |
| `X-Auth-Token: login:app password`    | login name and app password in one header                                            |
| `&tz=Australia/Melbourne`             | what `2026-11-20T10:00` means, and the zone times are shown in                       |
| `&private=hidden`                     | leave private events out altogether, instead of showing bare busy blocks             |
| `&private_calendars=Health,Family`    | more calendar-name words to treat as private                                         |

Every header name is one Claude's connector settings offer; a connector takes up to four. Only an
address in the connector URL is shown back. One from `X-Tenant` or from the seal is never
repeated, and neither is the login name that goes with it.

Set `tz`. Without it a time with no offset is refused rather than guessed at, and listings come
back in UTC.

What may be written:

- Reading runs freely. Every `create_`, `update_` and `delete_` needs `user_confirmed`.
- An event is changed inside the object as stored and saved with `If-Match`, so a change made
  elsewhere since it was read is a refusal, not an overwrite. Whatever the worker was not asked
  about (attendees, alarms, another client's `X-` properties) goes back as it came.
- An event with attendees also needs `notify_attendees: true`, because Nextcloud may email them.
- A repeating event is changed or binned as a whole series unless `occurrence` names one
  occurrence; the server is asked whether the series really has that occurrence first.

Nothing is erased. The worker sends no `DELETE` request for anything:

- `nc_delete_event` moves the event, whole, to a calendar called **Bin**, which it makes the
  first time one is needed. The event notes which calendar it came from (`binned_from`), and
  `nc_move_event` puts it back. Listings of all calendars leave the Bin out, so a binned event
  stops looking like an appointment; name the Bin to see what is in it. Emptying it is done in
  Nextcloud.
- Removing one occurrence of a series cannot be a move, so it is an edit: the series skips that
  date (`EXDATE`), and `nc_get_event` lists it under `removed_occurrences`.
- There is no tool that deletes a calendar. `nc_update_calendar` changes a calendar's name,
  colour or description and nothing else: its events and its id stay as they are.

### Keeping things private

Two things never reach the model, and cannot be changed through it:

- **An event marked private or confidential.** That is `CLASS:PRIVATE` or `CLASS:CONFIDENTIAL`,
  which is what the Calendar app's **When shared show** setting writes ("When shared hide this
  event" or "When shared show only busy"). `private: true` on `nc_create_event` or
  `nc_update_event` sets it too, and is one-way: once private, an event is unmarked in Nextcloud,
  not here.
- **Every event in a private calendar**: one whose name contains `Dating` (`PRIVATE_WORDS` in
  `workers/mcp-nc/src/tools.ts`) or a word from `?private_calendars=`. Case does not matter.

A private calendar is listed only as "Private calendar (colour #e9967a)": its colour, and nothing
else. It has no name and no id, so it cannot be opened, searched or written to, and asking for it
by any name answers as a missing calendar does. A private event's uid answers exactly as a
missing one does. A listing of all calendars does carry each private event as a busy block: its
start and end, and nothing else, not even which calendar, so nothing gets booked over the top of
it. With `?private=hidden` the blocks and the colour-only listing both go, and private calendars
and events do not exist as far as any tool can tell. A search never returns one either way, since
a block that appears for one word and not another would give its text away.

The filtering happens in the worker, before a result is built. Nothing private is in what Claude
receives, so it is in no conversation and no log of one. On Cloudflare's side the worker writes
no log lines of its own and has `observability` off, so no request to it (which would carry the
Nextcloud address in its URL) is recorded in Workers Logs. What this cannot do is hide anything
from Nextcloud itself, or stop the model seeing a title it was given to create an event with.

To set it up:

1. **Create an app password.** In Nextcloud: your avatar -> **Personal settings** -> **Security**
   -> **Devices & sessions** -> name it and **Create new app password**. Keep the login name it
   shows with it.
2. **Seal it.** Run `node scripts/seal-nextcloud.mjs` on your own machine and answer its three
   questions. Store the seal on the worker, once it exists on Cloudflare:

   ```sh
   cd workers/mcp-nc
   npx wrangler secret put NC_SEALED           # paste the NC_SEALED value when asked
   ```

3. **Put Cloudflare Access in front of the worker**, as under **Auth** below.
4. **Add the connector in Claude** with the URL `https://mcp-nc…/?tz=Australia/Melbourne` and
   one request header, `x-secret-key`, set to the key the script printed.

To store nothing on the worker instead, skip step 2 and give the connector three headers:
`x-tenant`, `x-account-id` and `x-app-key`.

`nc_status`, or opening the connector URL in a browser, says which Nextcloud it is for, whether
the login was accepted and which calendars it found. With a sealed login it says so without
naming the address or the login. A browser sends no header, so there it stops at "No login header
was sent".

The tests run against `scripts/mock-nextcloud.mjs`. To run them against a real CalDAV server
instead, serve one under `/remote.php/dav/` that accepts the login in `test/global-setup.ts`
(sabre/dav, the engine inside Nextcloud, does with a dozen lines of PHP) and set
`NC_TEST_BASE=http://127.0.0.1:<port>`; the handful that need the mock's request log are skipped.

## A private mail inbox

`mcp-mail` keeps the emails sent to one address and lets Claude read them. Cloudflare Email
Routing hands each message to the worker; the worker files it in D1 if the envelope sender is
allowed, and bounces it if not.

| Tool                  | Does                                                                       |
| --------------------- | -------------------------------------------------------------------------- |
| `mail_status`         | how many are kept, how many untriaged, the newest one's date               |
| `mail_list`           | untriaged messages, newest first, with search, a date and paging           |
| `mail_get`            | up to 20 messages in full: original sender, text, attachments, how it came |
| `mail_get_attachment` | one kept file: text as text, an image as an image, anything else embedded  |
| `mail_mark_triaged`   | flag messages dealt with, with a note such as where they were filed        |

**Who it was really from.** A message you forward arrives from you. The worker keeps who sent it
to the worker (`envelope_from`) and works out who originally sent it (`original_from`): from the
headers of a message attached whole (forward as attachment), else from the block a mail client
writes when forwarding inline: a `From:` header block, or an attribution line such as Proton's
`On Wednesday, 11/04/26 at 21:44 Name <a@b> wrote:`. Failing both, the message's own `From`. The
subject (less any `Fw:`) and date are taken the same way, and whatever you wrote above the
forwarded mail comes back as `forwarder_note`. Dates come back readable (`original_date`
`4 Nov 2026`, plus `original_time` and `original_date_iso` for sorting), with the client's own
text in `original_date_text`. Proton on a phone writes `11/04/26`, month first; the weekday it
gives decides month- or day-first, and a header date is shown in Melbourne time. This is worked out again each time a message is
read, so mail filed before the parser knew a format reads correctly once it does.

**What is kept.** The text (the plain part, or the HTML part stripped), every attachment up to
1.9 MB (one D1 row each; a bigger one is listed by name, type and size only), the
`Authentication-Results` header, and the raw message when it is under 1 MB. A message attached
whole is not kept as a file: its text is kept with the mail's. Text past 400,000 characters is cut, and the row says so. A Message-ID seen
before is not filed twice. The table makes itself on first use; there is no migration to run.
Nothing is ever deleted: `mail_mark_triaged` only sets a flag and a note.

**Who may send in** is `MAIL_ALLOWED_FROM`, a plain variable set in the dashboard (it is kept out
of this public repo). Unset or `*`, anyone may send: the routed address is then the only gate,
so make it one nobody would guess (say `jobs-k7q2m9@`). To narrow it, list comma-separated
addresses, or `@domain` for a whole domain, and every other sender bounces. The envelope sender is what is checked, which is your own address when you
forward by hand or with a filter. A bounce names the sender that was refused, so a forwarding
service that rewrites the envelope (SRS) shows you what to allow. An envelope sender can be
forged; the worst that buys anyone is a row in an inbox only you can read, since nothing here acts
on what a message says.

**Who may read** is `MAIL_READERS`, also a dashboard variable: comma-separated Cloudflare Access
emails. Every tool checks the signed-in email against it before touching the database, on top of
the worker's Access policy, so a policy that is loosened, switched off or bypassed by a service
binding still shows nothing. Unset, every tool refuses. Like `mcp-nc` it is not bound into the
toolkit. The worker writes no log lines and has `observability` off.

To set it up:

1. **Create the database**: `npx wrangler d1 create mcp-mail`, and put the `database_id` it
   prints into `workers/mcp-mail/wrangler.json`. Deploying only binds it, which the token's
   Workers permission covers, as it already does for `mcp-fetch`.
2. **Merge**, so the workflow deploys the worker.
3. **Set `MAIL_READERS`** on `mcp-mail` in the dashboard: the email you sign in to Access with.
   `MAIL_ALLOWED_FROM` is optional (see above).
4. **Route an address to it**: the domain -> Email -> Email Routing -> Routing rules -> Create
   address (say `jobs@`) -> action **Send to a Worker** -> `mcp-mail`.
5. **Put Cloudflare Access in front of the worker**, as under **Auth** below.
6. **Add the connector in Claude** with the worker's URL.

## Auth (Cloudflare Access)

Access runs before the Worker, so unauthenticated hits cost nothing. `mcp-toolkit` needs it, and so
do the workers that have a URL of their own rather than a binding in the toolkit (`mcp-helios`,
`mcp-printify`, `mcp-nc`, `mcp-mail`); repeat steps 2 to 4 for each:

1. Zero Trust -> Integrations -> Identity providers -> add **One-time PIN** (email code, no
   account needed).
2. Workers & Pages -> the Worker -> **Access** -> protect it; policy: Include -> Emails -> your list.
3. Zero Trust -> Access controls -> Applications -> edit that application -> Advanced settings ->
   turn on **Managed OAuth**, allow dynamic client registration.
4. In Claude.ai, add the connector URL. The browser login is the Access page.

Adding a person = adding their email to the policy.