AgentOTP
by kuanlinb
README.md
# AgentOTP
**2FA codes for AI agents, approved on your phone.**
Your agent hits a login that asks for a 2FA code. With AgentOTP it asks for the code over MCP or REST, you get a push
notification with the agent's reason, and one tap with Face ID lets exactly that code through. Agents only see the
accounts you picked, and every code they read is logged.
It is a self-hosted TOTP vault on the Cloudflare Workers free plan, with a passkey-only web app for people.
[](https://deploy.workers.cloudflare.com/?url=https://github.com/kuanlinb/agentotp)
[繁體中文說明](README.zh-TW.md) · [Deploy guide](docs/deploy.md) · [Threat model](THREAT_MODEL.md) · [Backup and key rotation](docs/backup.md) · [Security policy](SECURITY.md)
## What it does
**For people** (an installable web app that works well as an iPhone home-screen app)
- Passkey sign-in only (Face ID, Touch ID, Windows Hello, a password manager). No passwords. Invite-only.
- Codes with a countdown ring, tap to copy, search, English and Traditional Chinese.
- Add accounts by camera QR scan, screenshot upload, pasted `otpauth://` links, manual entry, or a Google Authenticator export QR.
- Each user has their own vault. Share a single account with another user; they see codes, never the secret.
- Export any time: encrypted backup file, Google Authenticator QR codes, or plain `otpauth://` links. An offline
decrypt script needs nothing but Node.js. See [docs/backup.md](docs/backup.md).
**For AI agents**
- Remote MCP server at `https://<your-instance>/mcp` with OAuth (claude.ai, the Claude apps, Claude Code and other
MCP clients), or a static `abx_…` token.
- REST: `GET /api/v1/accounts` and `GET /api/v1/code?query=github` with `Authorization: Bearer abx_…`.
- Each connection only sees the accounts you chose, and every code request is written to the activity log.
**Approvals**
- Mark an account "ask me first". An agent's request sends a push notification with the agent's stated reason;
you approve with a passkey.
- Grant once, for 15 minutes, 1 hour or 8 hours, or always. Revoke grants and connections at any time.
- Optional notification on every agent access, per account.
## Agent API in one minute
```bash
curl -H "Authorization: Bearer abx_..." \
"https://<your-instance>/api/v1/code?query=github&reason=deploy%20PR%2012&wait_seconds=20&min_validity_seconds=10"
```
| Parameter | Range | Meaning |
|---|---|---|
| `query` | | Account id, exact label, or a partial match on issuer or label |
| `reason` | short text | Shown to you, marked as untrusted text, when approval is needed |
| `wait_seconds` | 0–25, default 20 | How long the request waits for your approval before it returns |
| `min_validity_seconds` | 0–20, default 0 | If the current code expires sooner than this, wait for the next one |
The response is either `status: "ok"` with `code`, `expires_in` and `next_code`, or `status: "pending_approval"`
(HTTP 202 with a `Retry-After` header) with `approval_id` and `retry_after_seconds`. Pending approval is not an
error: call again with the same arguments after `retry_after_seconds`. The MCP tools `list_2fa_accounts` and
`get_2fa_code` take the same arguments and return the same fields.
## How it compares
| | AgentOTP | Phone authenticator apps (Google Authenticator, Aegis, 2FAS) | Password managers with TOTP (1Password, Bitwarden) | Self-hosted TOTP web apps (for example 2FAuth) |
|---|---|---|---|---|
| Runs on | Your Cloudflare account, free plan | Your phone | Vendor cloud, or your server | Your server (PHP and a database) |
| Sign-in | Passkey only | Device unlock | Master password and/or passkey | Password, optional WebAuthn |
| AI agent access | MCP (OAuth) and REST, limited per connection | No | CLI and service accounts | REST API |
| Phone approval per agent request | Yes, per account, with time-boxed grants | No | No | No |
| Stores passwords | No | No | Yes | No |
| Cost | Free plan | Free | Paid tiers | Free, plus hosting |
Based on public documentation as of November 2026. Corrections are welcome in an issue.
## Limitations
- **Free-plan CPU.** A Worker request gets 10 ms of CPU on the free plan. Opening the vault page decrypts every
account and computes its codes, which fits roughly **150 accounts per user**. Above that the page can fail with a
CPU-limit error.
- **Daily free-plan quotas** (100,000 requests, D1 and KV write limits) can be used up by a flood of requests. That
stops the service until UTC midnight; it does not leak data. See [THREAT_MODEL.md](THREAT_MODEL.md).
- **OAuth client registration** (Dynamic Client Registration) is limited to 5 new clients per IP per day and 100 per instance.
- **MCP versions:** `2026-07-28` (no `initialize`; the version travels in each request's `_meta`) plus the legacy
`2025-11-25`, `2025-06-18` and `2025-03-26` handshake.
- **Agent limits:** 20 codes per minute and 500 per day per connection; 30 approval requests per day per connection.
- **TOTP only.** No HOTP, Steam Guard or password storage. No offline mode.
- **One URL per instance.** Passkeys are bound to the domain. After setup, other hostnames redirect (GET) or get HTTP 421.
- **iPhone push** needs iOS 16.4 or later and the app added to the home screen.
- **No professional security audit.** Read the [threat model](THREAT_MODEL.md): whoever controls the Cloudflare
account can read every secret.
## Deploy
The short version; [docs/deploy.md](docs/deploy.md) has the details.
1. Click **Deploy to Cloudflare** above. Cloudflare copies the repository to your GitHub account, creates the D1
database and KV namespace, and asks for one secret, `AGENTOTP_SECRET` (`openssl rand -base64 32`).
**Save that secret in your password manager.**
2. Open `https://<worker-name>.<your-subdomain>.workers.dev/`, paste the root secret on the setup page and create your
passkey. The secret stays in the browser; the page only sends an HMAC proof.
3. Invite other people from Settings. Connect agents from the AI connections page.
From the command line instead:
```bash
npm ci
npx wrangler login
npx wrangler secret put AGENTOTP_SECRET # paste the output of: openssl rand -base64 32
npm run deploy # builds, creates D1 and KV on the first run, applies migrations
```
## Develop
```bash
npm ci
npm run dev:setup # writes .dev.vars with a throwaway root secret and TEST_MODE=1
npm run dev # http://localhost:5173
npm run typecheck && npm test
npm run e2e # resets the local database, starts Vite, runs the Playwright e2e and the MCP SDK test
```
The e2e test needs Playwright's Chromium (`npx playwright install chromium`, or point `PW_CHROME` at a Chrome
binary). The MCP SDK test needs a Python venv in `.venv` with `tests/requirements.txt`. See [CONTRIBUTING.md](CONTRIBUTING.md).
| Part | Where |
|---|---|
| Worker entry: security headers, routing, OAuth provider, daily cleanup | `worker/index.ts` |
| Passkeys, invites, sessions, first-run setup and break-glass recovery | `worker/routes/auth.ts`, `session.ts`, `setup.ts` |
| Web app API | `worker/routes/app.ts` |
| MCP and REST | `worker/routes/agent.ts` |
| Permissions, audit, rate limits, approvals | `worker/lib/core.ts` |
| Encryption (AES-256-GCM, versioned keyring, HKDF from one root secret) | `worker/lib/crypto.ts`, `worker/lib/keys.ts`, `shared/keys.ts` |
| TOTP, otpauth, Google Authenticator migration format | `shared/otp.ts` |
| Schema | `migrations/` |
| Web app (React and shadcn/ui) | `web/src/` |
## License
[Apache-2.0](LICENSE)
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues