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.

Deploy to Cloudflare

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

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.

WorkerHostBindingsSecrets and variables
siteexample.comASSETS (static files only)none
consoleapp.example.comASSETS; service GATEAUTH_URL, CONSOLE_ORIGIN
authauth.example.comKV OAUTH_KV; D1 DB; service GATEISSUER, MCP_RESOURCE, API_RESOURCE, RP_ID, COOKIE_DOMAIN, CONSOLE_URL; secret OWNER_SETUP_TOKEN
edgeapi.example.com, mcp.example.comservices AUTH, GATE, PLANNER; optional rate limiter RLISSUER, MCP_RESOURCE, API_RESOURCE, MCP_HOST, API_HOST
plannernoneWorkers AI AIPLANNER_MODEL, PLANNER_FALLBACK_MODEL; optional AI_GATEWAY_ID
gatenoneD1 DB; services VAULT, AUTH; a daily cronsecret GATE_SECRET
vaultnoneDurable Object USER_VAULT (SQLite); R2 ANCHORSsecret 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:

VariableExample
ISSUERhttps://auth.example.com
MCP_RESOURCEhttps://mcp.example.com/mcp
API_RESOURCEhttps://api.example.com/v1
MCP_HOST, API_HOSTmcp.example.com, api.example.com
RP_ID, COOKIE_DOMAINexample.com
CONSOLE_URL, CONSOLE_ORIGINhttps://app.example.com
AUTH_URLhttps://auth.example.com
PLANNER_MODEL, PLANNER_FALLBACK_MODELWorkers 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

  1. Open https://auth.example.com/setup?token=<OWNER_SETUP_TOKEN> and register a passkey. Setup works only while no owner exists.
  2. You land in the console at https://app.example.com. Set your time zone first: a "day" is your local day.
  3. Optionally remove the OWNER_SETUP_TOKEN secret afterwards.

Bring in data

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