Deploy to Cloudflare Workers
Deployment mode D: agility-bridge as a Cloudflare Worker on D1, reachable from every device, no server to run. From nothing to a signed-in owner and a connected client: remote quickstart; running it afterwards: admin guide. Limits, measured costs and rate limits per plan: Cloudflare limits. Executed against a real account as recorded in verification.
Which Agility instances a Worker can reach
Section titled “Which Agility instances a Worker can reach”- Hosted Agility (
*.v1host.com) and any instance reachable from the internet with a publicly trusted certificate: yes. - On-premises Agility on a private network, or with a certificate from a private CA: Workers cannot trust a private
CA and cannot reach private networks. Either publish the instance through a
Cloudflare Tunnel with a public
hostname (it then has a publicly trusted certificate, and you decide who may reach it), or run
agility-bridge servenext to it (ADR-0014).
What you need
Section titled “What you need”- A Cloudflare account (the Free plan works) and a checkout of this repository with
pnpm installdone. wranglerlogged in to that account:pnpm --filter @agility-bridge/worker exec wrangler login. The setup script uses that login; it never reads or stores a Cloudflare token.
Create or update a deployment
Section titled “Create or update a deployment”pnpm cf:setup --name agility-bridge-staging --secrets-file ~/.config/agility-bridge/staging.secretsOne command, safe to run again (a second run only redeploys). For the deployment named by --name it:
- finds or creates the D1 database of the same name;
- writes
apps/worker/wrangler.<name>.local.jsonc(ignored by git: it holds the database id) from the committedapps/worker/wrangler.jsonc, withAB_PLAN(--plan free|paid, defaultfree),AB_ENVIRONMENT(productiononly for the nameagility-bridge,testotherwise, so non-production device tokens readab_test_…) andAB_PUBLIC_URL(--public-url, default the deployment’sworkers.devaddress, learnt from the first deploy); - deploys, keeping the variables you set in the Cloudflare dashboard (
keep_vars); - sets the secrets that are missing: a new master key (
AB_MASTER_KEY) and break-glass admin token (AB_ADMIN_TOKEN), passed to wrangler through stdin, never as arguments or variables. They are written to the--secrets-file(a new file, mode0600, created before anything is generated) and printed only with--show-secrets; without either the script refuses, because a lost master key means re-entering every token; - checks
GET /healthon the deployed address.
The database is migrated by the Worker at its first request. --dry-run shows the plan without changing anything.
Keep the secrets file like the master key of a self-hosted server: away from the data, backed up separately (secrets).
Turn on OAuth
Section titled “Turn on OAuth”Add --oauth on to switch the OAuth server on for apps such as claude.ai and Claude Code (--oauth off switches it off).
The value is written to the local config as AB_OAUTH and a later run without the flag keeps it. It needs a sign-in
provider (--sign-in) and public HTTPS; the whole procedure, the registration settings and the checks are in the
OAuth operator guide.
pnpm cf:setup --name agility-bridge --domain mcp.example.com --secrets-file ~/.config/agility-bridge/prod.secrets --oauth onThings that differ from a single server
Section titled “Things that differ from a single server”- Revocations reach every isolate within the access-cache time. Each isolate keeps resolved access for up to
AB_ACCESS_CACHE_TTLseconds (default 30, at most 60). A device token, grant or user you revoke stops at once on the isolate that handled the change and within that time on the others; setAB_ACCESS_CACHE_TTLlower for faster cut-off at the cost of more D1 reads. - Rate limits count per isolate, with Cloudflare’s Rate Limiting binding as a backstop (limits).
- Instances on private addresses cannot be reached from Workers at all, so the
AB_INSTANCE_PRIVATE_ADDRESSESsetting ofservedoes not exist here.
Sign-in settings
Section titled “Sign-in settings”Add --sign-in to set the identity providers (identity providers) in the same run:
pnpm cf:setup --name agility-bridge --domain mcp.example.com --secrets-file ~/.config/agility-bridge/prod.secrets --sign-in- Where the values come from. The environment first (the non-interactive mode, for CI):
AB_GOOGLE_CLIENT_IDandAB_GOOGLE_CLIENT_SECRET,AB_GITHUB_*,AB_OIDC_*,AB_CF_ACCESS_TEAMandAB_CF_ACCESS_AUD, and theAB_LOGIN_ALLOW_*allowlists withAB_LOGIN_AUTO_PROVISION. A provider whose client id (or Access team) is in the environment is configured; otherwise, in a terminal, the script asks which providers and then each value. Client secrets are read without echo. Without--sign-innothing is asked and nothing about sign-in changes. - Where they go. Client ids, the issuer, the allowlists and the rest are variables in the ignored
wrangler.<name>.local.jsonc. Client secrets go towrangler secret puton stdin, never an argument, a variable, a log line or a file (not even--secrets-file: the identity provider holds them, so lose one and you rotate it there). - Checked before anything is created. The values go through the parser the server boots with, so a half-configured
provider, a bad issuer or an unknown auto-provision mode stops the run with the variable’s name (never its value). The
server’s warnings are printed too, for example an allowlist while
AB_LOGIN_AUTO_PROVISION=off. - Run again. Variables of earlier runs are kept. In a terminal an empty answer keeps the shown value and the stored
secret, and
-clears an optional variable. A secret is sent only when you give one. To remove a provider, edit the local config and delete its secret in the dashboard. - Callback URLs. The end of the run lists the redirect URIs to register at each provider
(
https://<public URL>/auth/callback/<provider>; Cloudflare Access has none). They derive from the public URL, so give--domain(or--public-url) first: aworkers.devaddress learnt from the first deploy works, but the registrations break if the address changes.--dry-runasks nothing.
Staging and production stay apart
Section titled “Staging and production stay apart”Every resource is named after --name: agility-bridge is production, agility-bridge-staging (or any
agility-bridge-<suffix>) another environment with its own database, secrets and address. A local config whose worker
or database name differs from --name is refused, so a staging config can never be pointed at production by mistake
(THREAT_MODEL T34).
Housekeeping and key rotation
Section titled “Housekeeping and key rotation”A cron trigger (every 15 minutes, wrangler.jsonc) runs the jobs agility-bridge serve runs on timers, in small
slices that fit the Free plan’s limits per run:
| Job | Per run | Setting |
|---|---|---|
| Audit retention | up to 3,000 rows older than the retention | AB_AUDIT_RETENTION_DAYS (90; 0 keeps them) |
Expired kv entries |
up to 1,000 | — |
| Master-key rotation | 10 credentials re-encrypted with the current key | runs while AB_MASTER_KEY_PREVIOUS is set and credentials remain on it |
| Credential revalidation | 1 credential, the stalest | AB_CREDENTIAL_REVALIDATION_HOURS (24; 0 = never) |
Rotating the master key on Workers:
- Generate the next key:
agility-bridge init --key-file ./master-v2.key --version 2(one higher than the current). - With wrangler (
--config apps/worker/wrangler.<name>.local.jsonc, values through stdin), put the current key intoAB_MASTER_KEY_PREVIOUSand the new one intoAB_MASTER_KEY. - The cron re-encrypts ten credentials per run; each row is replaced only if it still holds what was read, so an
interrupted or overlapping run is safe, and a
kvlease keeps two runs off the same batch. Watch it withagility-bridge keys status(withAB_ADMIN_URLand the admin token, through the admin API). - When version 1 has no credentials left:
agility-bridge keys retire 1 --reason "rotation", then deleteAB_MASTER_KEY_PREVIOUS(secrets).
Move a self-hosted deployment to the Worker
Section titled “Move a self-hosted deployment to the Worker”Moves everything a self-hosted agility-bridge serve holds — users, instances, credentials (still encrypted),
workspaces, grants, device tokens, settings, audit — so nobody re-enters an Agility token and existing device tokens
keep working at the new address. One-way, into an empty deployment (L-078):
-
Make a backup on the server:
agility-bridge backup ./agility-bridge-backup.db(the live database is never read). -
Create the Worker with
pnpm cf:setup --name <worker> …and give it the server’s master key: with wrangler, put the content of the server’s key file intoAB_MASTER_KEY(stdin), replacing the generated one. To move to a new key at the same time, set the new key asAB_MASTER_KEYand the server’s asAB_MASTER_KEY_PREVIOUS; the cron then re-encrypts every credential (housekeeping). -
Open
https://<address>/healthonce (the Worker migrates its empty database and records the key). -
Copy the backup in:
Terminal window pnpm cf:migrate --name <worker> --from ./agility-bridge-backup.dbIt refuses, before writing anything, a target that already has users, instances, credentials, workspaces, grants, device tokens or settings (audit rows of refused requests are fine: they stay), a different schema version (upgrade the server and the Worker to the same release first), or a Worker without the server’s master key. It writes the rows as SQL (
0600, deleted afterwards; it holds ciphertext and token hashes), imports it withwrangler d1 execute --remote, and checks the row counts. Rate-limit counters and other transient state are not copied. -
Point the devices at
https://<address>/w/<slug>/mcp(their tokens are unchanged), then stop the old server and delete the backup.
A custom domain
Section titled “A custom domain”pnpm cf:setup --name agility-bridge --domain mcp.example.com --secrets-file ~/.config/agility-bridge/prod.secretsThe domain must be a zone in the same Cloudflare account. --domain adds a Workers custom domain (Cloudflare creates
the DNS record and the certificate), makes https://mcp.example.com the public URL (AB_PUBLIC_URL) and turns the
workers.dev address off, so the Worker has one address and refuses every other Host (T24). Clients then use
https://mcp.example.com/w/<slug>/mcp.
Bot protection must not challenge MCP clients (L-028). On the zone, Bot Fight Mode, Browser Integrity Check
and challenge rules answer non-browser clients with a challenge page, 403 or error 1010, and MCP clients cannot
pass them. Add a WAF custom rule Skip for http.request.uri.path wildcard "/w/*/mcp" (and /api/admin/* if you
use the admin API remotely) that skips Browser Integrity Check and the managed bot rules, or turn Bot Fight Mode off
for the zone. Leave the Worker’s own limits in place: they apply after the skip.
Rate limits for the OAuth routes
Section titled “Rate limits for the OAuth routes”wrangler.jsonc declares three Rate Limiting bindings (RL_IP, RL_AUTH, and RL_OAUTH for /oauth/*); with AB_OAUTH=on
the Worker warns at start when RL_OAUTH is missing. A zone you own can also block floods before the Worker with a WAF rate
limiting rule. Both options, the limits and what they save are in Cloudflare limits.
| Free | Workers Paid (from 5 USD a month) | |
|---|---|---|
| Requests | 100,000 a day | 10 million a month included |
| CPU per request | 10 ms (measured: warm calls fit, a new isolate’s first request does not yet, P3-14) | 30 s default |
| Agility requests per tool call | 45 (preset and ceiling) | 1,000 |
| D1 | 5 million rows read and 100,000 written a day | 25 billion read and 50 million written a month included |
| Scheduled housekeeping | every 15 minutes, in small slices | same |
Every MCP request reads a few D1 rows (access resolution is one batch, the access cache saves most of it) and writes an audit row per tool call, so the Free plan’s 100,000 written rows a day are the first limit for a busy team. Prices and allowances: Workers pricing, D1 pricing (checked 2026-10).
First setup of a workspace
Section titled “First setup of a workspace”With the admin token from the secrets file, create the instance, credential, workspace, grant and device token through the admin API, or with the management commands pointed at the Worker:
AB_ADMIN_URL=https://agility-bridge-staging.<your-subdomain>.workers.dev \AB_ADMIN_TOKEN_FILE=./staging.admin-token \agility-bridge instance add "Main" https://www7.v1host.com/YourInstance(AB_ADMIN_TOKEN_FILE holds only the token: copy the AB_ADMIN_TOKEN= value from the secrets file into a 0600
file.) Then connect each device to https://<address>/w/<slug>/mcp with its own token (devices).
agility-bridge is an unofficial, community project. It is not affiliated with, endorsed by, or supported by Digital.ai. Digital.ai, Agility and VersionOne are trademarks of their respective owners.