Self-hosting
AskWearables is seven Cloudflare Workers in one repository. Self-hosting means your data stays in your own Cloudflare account, under keys only you hold. This guide assumes you are comfortable with Wrangler and a terminal.
One click: the Deploy to Cloudflare button deploys the self-host edition, a single Worker with the same core (planner, gate, compute engine, receipts) plus a Durable Object, D1, KV and Workers AI, provisioned automatically. After deploy, set MASTER_KEY and OWNER_SETUP_TOKEN, open /setup?token=…, create a passkey, and connect your agent to https://<your-worker>.workers.dev/mcp. It runs as one Worker, so it lacks the seven-Worker trust-zone separation of the hosted service. To run the full seven-Worker layout yourself, follow the steps below.
What you need
- A Cloudflare account with a domain added as a zone, and a plan that includes Durable Objects, D1, KV, R2 and Workers AI at the limits you expect. Check current limits and pricing for Durable Object storage and D1 before you rely on them.
- Node.js 20 or later and a clone of the repository. Run
npm installat the root; Wrangler is a pinned dev dependency. - A device that supports passkeys, for signing in as the owner.
The seven Workers
Each Worker lives in workers/<name> with its own Wrangler config. Bindings follow the trust zones: only gate and vault touch stored data, and nothing public calls them.
| Worker | Host | Bindings | Secrets and variables |
|---|---|---|---|
site | example.com | ASSETS (static files only) | none |
console | app.example.com | ASSETS; service GATE | AUTH_URL, CONSOLE_ORIGIN |
auth | auth.example.com | KV OAUTH_KV; D1 DB; service GATE | ISSUER, MCP_RESOURCE, API_RESOURCE, RP_ID, COOKIE_DOMAIN, CONSOLE_URL; secret OWNER_SETUP_TOKEN |
edge | api.example.com, mcp.example.com | services AUTH, GATE, PLANNER; optional rate limiter RL | ISSUER, MCP_RESOURCE, API_RESOURCE, MCP_HOST, API_HOST |
planner | none | Workers AI AI | PLANNER_MODEL, PLANNER_FALLBACK_MODEL; optional AI_GATEWAY_ID |
gate | none | D1 DB; services VAULT, AUTH; a daily cron | secret GATE_SECRET |
vault | none | Durable Object USER_VAULT (SQLite); R2 ANCHORS | secret MASTER_KEY |
Create resources
npx wrangler d1 create askwearables-control # control data: users, agents, grants, keys
npx wrangler kv namespace create OAUTH_KV # OAuth state for the auth Worker
npx wrangler r2 bucket create askwearables-anchors # daily receipt-chain anchors
Put the returned D1 id into the configs of auth and gate, and the KV id into auth; the configs in the repository hold the ids of the reference deployment, which will not work in your account. The per-user Durable Objects are created on first use and need no setup beyond the class binding and its SQLite migration in workers/vault.
Cloudflare documents a jurisdiction option for Durable Objects (for example eu). Decide where user data should live before the first real user, because moving it later is a migration.
Set secrets
Generate each secret on your own machine and set it with Wrangler. Never put them in a config file or the repository.
# 32 random bytes, base64. Wraps each user's data key. Losing it makes stored data unreadable.
openssl rand -base64 32 | npx wrangler secret put MASTER_KEY -c workers/vault/wrangler.jsonc
# 32 random bytes, base64. Encrypts developer signing secrets and webhook secrets.
openssl rand -base64 32 | npx wrangler secret put GATE_SECRET -c workers/gate/wrangler.jsonc
# A one-time token for creating the owner account.
openssl rand -hex 24 | tee /dev/tty | npx wrangler secret put OWNER_SETUP_TOKEN -c workers/auth/wrangler.jsonc
Keep an offline copy of MASTER_KEY. There is no recovery without it, by design.
Configure hosts
Replace askwearables.app with your domain in each config's variables and routes:
| Variable | Example |
|---|---|
ISSUER | https://auth.example.com |
MCP_RESOURCE | https://mcp.example.com/mcp |
API_RESOURCE | https://api.example.com/v1 |
MCP_HOST, API_HOST | mcp.example.com, api.example.com |
RP_ID, COOKIE_DOMAIN | example.com |
CONSOLE_URL, CONSOLE_ORIGIN | https://app.example.com |
AUTH_URL | https://auth.example.com |
PLANNER_MODEL, PLANNER_FALLBACK_MODEL | Workers AI model ids that support structured output; check the current catalogue |
The planner runs on Workers AI only, so question text stays on Cloudflare. If you route it through AI Gateway, turn prompt logging off.
Migrate and deploy
# Control-data schema (the migrations live in /migrations at the repository root)
npx wrangler d1 migrations apply askwearables-control --remote -c workers/gate/wrangler.jsonc
# Checks first
npm run check
# Protected zone first, then the request path, identity and public Workers
for w in vault gate planner auth edge console site; do
npx wrangler deploy -c workers/$w/wrangler.jsonc
done
auth and gate bind each other. If Wrangler reports that a bound service does not exist yet on the very first deploy, deploy the other Worker and run the loop again.
Create the owner
- Open
https://auth.example.com/setup?token=<OWNER_SETUP_TOKEN>and register a passkey. Setup works only while no owner exists. - You land in the console at
https://app.example.com. Set your time zone first: a "day" is your local day. - Optionally remove the
OWNER_SETUP_TOKENsecret afterwards.
Bring in data
- File import. In the console, choose an Apple Health
export.xml. It is parsed in your browser and uploaded as normalized batches; the raw file never leaves your machine. - Owner key. Create an
aw_own_key in the console and push records withPOST /v1/ingest, as in the quickstart. - Sync key. Create an
aw_sync_key bound to one source for a phone sync app; it can only write to that source.
Then connect Claude or another client to https://mcp.example.com/mcp as described in the quickstart, and read the receipts in the console as you ask.
To serve your own users as a developer, create a developer key in the console and follow the quickstart against https://api.example.com. Get legal advice about health-data rules where you and your users are before you hold anyone else's data.
Run locally
Wrangler can run several Workers in one local session, with service bindings, D1, KV, R2 and Durable Objects simulated on your machine:
npx wrangler d1 migrations apply askwearables-control --local -c workers/gate/wrangler.jsonc
npx wrangler dev -c workers/edge/wrangler.jsonc -c workers/gate/wrangler.jsonc \
-c workers/vault/wrangler.jsonc -c workers/planner/wrangler.jsonc \
-c workers/auth/wrangler.jsonc -c workers/console/wrangler.jsonc
Local secrets go in a .dev.vars file next to each config. It is ignored by git; keep it that way. Use synthetic data locally; scripts/quickstart.ts generates some.
Operating it
- Cron.
gateruns daily to copy each user's receipt-chain head to R2 and to clear expired nonces;authpurges expired OAuth data and sessions. - Logs. Health values are never written to logs, traces or error messages. Keep it that way if you add code.
- Updates. Pull, run
npm run check, apply any new migrations, and deploy in the same order. - Deletion. "Delete everything" in the console removes health data and revokes access. Back up
MASTER_KEYseparately from any data backup.
