mcp-starter
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
Remote MCP starter for Cloudflare Workers
A complete, self-hosted starting point for exposing your application to AI agents through the Model Context Protocol (MCP). It runs entirely on Cloudflare Workers: a Hono app, a stateless streamable-HTTP MCP endpoint, passkey accounts, and one SQLite-backed Durable Object per account.
The MCP surface is deliberately tiny and generic:
Tool | Purpose |
| List the operations this connection may use, with compact summaries or full JSON Schemas. |
| Run list/get operations with validation and pagination metadata. |
| Run create/update/delete operations with explicit uncertainty reporting. |
A demo “notes” resource is included so the whole flow works immediately. Replace it with your own operations when you are ready; the account, connection, security and MCP layers stay the same.
Contents
Related MCP server: AgentGate
What you get
Passkey-only accounts using
@simplewebauthn/server. No passwords, no email recovery, no password reset flow to secure.Secure browser sessions in
HttpOnly; Secure; SameSite=Strictcookies with a CSRF token required for every mutation.Per-connection MCP URLs shaped like
https://your-worker.example/mcp/<account>.<secret>. Only a domain-separated SHA-256 hash of the full token is stored.Encrypted upstream credentials using AES-GCM with a versioned Worker-secret keyring and additional authenticated data bound to the account and connection.
Explicit per-resource access policy enforced inside the Durable Object on every read and write. New connections start read-only.
Connection lifecycle — rename, replace credential, rotate URL, disable, enable and revoke. Rotation and revocation invalidate the old URL immediately.
Versioned discovery — clients send the catalogue version they discovered; stale clients get a structured
SCHEMA_CHANGEDand must rediscover.Structured errors with stable codes, partial-page signalling, read-back after writes, and no automatic retry of uncertain writes.
Tests that run in the real Workers runtime, including synthetic WebAuthn registration and login, connection creation, discovery, authorized reads/writes, denied access, rotation and revocation.
CI that lints, typechecks and tests on every push, then deploys
mainwithCLOUDFLARE_API_TOKENandCLOUDFLARE_ACCOUNT_ID.No app-specific assumptions — the domain layer is replaceable and the security layer is generic.
How it fits together
Browser MCP client
│ │
│ passkey + session cookie │ POST /mcp/<account>.<secret>
▼ ▼
┌────────────────────────────────────────────────────────────┐
│ Cloudflare Worker (Hono) │
│ • static UI and /api account routes │
│ • WebAuthn verification and signed ceremony cookies │
│ • stateless MCP streamable-HTTP handler │
└───────────────┬────────────────────────────────────────────┘
│ RPC by account id
▼
┌────────────────────────────────────────────────────────────┐
│ AccountStore Durable Object (SQLite) │
│ • account, passkeys, sessions, used challenges │
│ • connections, encrypted credentials, access policy │
│ • demo notes │
└────────────────────────────────────────────────────────────┘
│ (replace the demo)
▼
your application APIThe Worker is the only public entry point. The Durable Object has no public
fetchhandler; it only exposes typed RPC methods to the Worker.Each account gets one Durable Object named after the 64-hex account id. The account id is the first part of every connection URL, so routing needs no global index.
MCP requests are stateless. The handler validates the token, resolves the connection revision and policy, runs the tool, and returns. There are no MCP sessions to keep in sync with revocation.
Local development
Prerequisites
Node.js 24.11 or newer (
.node-versionis included for version managers).npm.
A browser with passkeys (Safari, Chrome, Edge, Firefox with a platform or security-key authenticator).
http://localhostis treated as a secure context, so local passkeys work without TLS.For deployment only: a Cloudflare account and
wrangler login.
First run
npm install
cp .var.dev.example .var.dev
npm run secrets
npm run devnpm run secrets fills the missing CEREMONY_KEY and ENCRYPTION_KEYS values in .var.dev. It never prints them and never rotates values that already exist.
Open http://localhost:8787, click Sign up, create a passkey, then create a connection. The demo accepts a credential such as:
demo_local_developmentCopy the MCP URL shown once, then use it in a client (see below).
wrangler devstores local Durable Object data under.wrangler/. Local accounts and notes are completely separate from production.
Useful commands
Command | What it does |
| Start the Worker on |
| Run the Vitest suite in the Workers runtime. |
| Run TypeScript with no emit. |
| Check formatting and lint rules with Biome. |
| Apply safe formatting and lint fixes. |
| Lint, typecheck and test in one go. |
| Generate or preserve local development secrets. |
| Regenerate |
| Exercise an existing connection with the MCP client. Requires |
Smoke test against a running local Worker
Create a connection in the browser, copy its URL, then:
MCP_URL='http://localhost:8787/mcp/<account>.<token>' npm run smokeThe script lists tools, discovers operations, reads a page and attempts a write if the connection permits it. It never prints the URL or token.
Deploy
1. Choose the hostname first
WebAuthn binds passkeys to an exact hostname. Decide now whether you will use the default workers.dev hostname or a custom domain.
Edit wrangler.jsonc:
{
"name": "your-mcp-starter",
"vars": {
"APP_NAME": "Your app",
"ENVIRONMENT": "production",
"ENCRYPTION_KEY_VERSION": "v1",
"WEBAUTHN_RP_ID": "your-mcp-starter.your-subdomain.workers.dev",
"WEBAUTHN_ORIGIN": "https://your-mcp-starter.your-subdomain.workers.dev"
}
}Rules:
WEBAUTHN_RP_IDis a bare hostname: no scheme, port or path.WEBAUTHN_ORIGINis the exact browser origin, includinghttps://and any non-default port.They must refer to the same host.
localhostis the only host allowed over plainhttp.If you later move to a custom domain, change both values and expect existing passkeys to stop working for the old hostname. Plan the move before inviting users.
2. Create the two production secrets
The Worker needs independent signing and encryption keys:
# Generate local values if you have not already.
npm run secrets
# Read the two values from .var.dev (do not paste secrets into shell history on a shared machine).
npx wrangler secret put CEREMONY_KEY
npx wrangler secret put ENCRYPTION_KEYSENCRYPTION_KEYS is a JSON object mapping key versions to 32-byte base64url keys, for example:
{ "v1": "<43-character-base64url-key>" }ENCRYPTION_KEY_VERSION must name the active entry. To rotate later, add a new version, switch the active version, keep the old key for decryption, and re-save each connection credential when convenient. See docs/OPERATIONS.md.
3. Deploy
npm run deployThe first deploy creates the AccountStore Durable Object migration. Open the deployed origin, create an account and create a connection. The URL shown at creation is the only time the full token is available.
4. Test the deployment
MCP_URL='https://your-host/mcp/<account>.<token>' npm run smokeConnect an MCP client
The connection URL is a bearer credential. Treat it like a password.
General steps:
In your MCP client, add a custom remote MCP server / connector.
Paste the full
https://…/mcp/<account>.<token>URL.Choose No authentication (the URL itself authorizes the connection).
Save and ask the agent to discover operations.
See docs/CLIENTS.md for client-specific notes and troubleshooting.
If a client only accepts an origin without a path, or insists on OAuth discovery, it cannot use this bearer-URL pattern. Use a client that supports custom remote MCP servers with headers/paths, or put an authenticating proxy in front.
The three tools
discover
Inputs:
{ "operation_id": "notes:list", "detail": true, "limit": 50, "cursor": "<next_cursor>" }Default output is compact: operation id, resource, kind, summary and description.
Results are paginated:
limitdefaults to 50 and is capped at 100. Passnext_cursorback unchanged whilehas_moreis true.operation_idreturns one full contract and ignoreslimit/cursor.detail: truereturns JSON Schemas and examples for the returned page.The response includes
catalog_version,total_operations,has_moreandnext_cursor. Sendcatalog_versionback with every execution.An invalid or foreign cursor returns
INVALID_CURSOR.
execute_read
{
"operation_id": "notes:list",
"catalog_version": "<hash from discover>",
"arguments": { "limit": 10, "status": "open" }
}Only list/get operations are accepted.
Arguments are validated with Zod on the server before execution.
Paginated results include
has_moreand an opaquenext_cursor. A partial page is never presented as complete.A stale
catalog_versionreturnsSCHEMA_CHANGEDwithmutation_sent: false.
execute_write
{
"operation_id": "notes:create",
"catalog_version": "<hash from discover>",
"arguments": { "title": "Call the supplier" }
}Only create/update/delete operations are accepted.
Access is checked again inside the Durable Object.
Successful writes are read back before being reported.
An unexpected failure returns
WRITE_UNCERTAIN,mutation_sent: "unknown",write_outcome: "uncertain",requires_readback: trueandautomatic_retry: false.The agent should read current state before retrying an uncertain write. The server never retries by itself.
Updates preserve unspecified fields. The demo also supports
expected_updated_atfor optimistic concurrency and returnsCONFLICTwith the current record.
Error codes
Code | Meaning |
| Arguments do not match the operation schema. |
| No such operation id. |
| The operation exists but is outside this connection’s policy. |
| Reads must use |
| The catalogue or connection revision changed. Rediscover. |
| Use a cursor returned by the same catalogue or list. |
| The record does not exist or is not visible. |
| Optimistic concurrency check failed; |
| The write may have been applied. Read before retrying. |
| Passkey/session verification failed. |
| A mutation is missing a valid CSRF token. |
| Wait and retry the HTTP request later. |
| A generic infrastructure failure with no safe detail. |
Access model
Each connection stores a policy document:
{
"version": 1,
"resources": {
"notes": { "read": true, "create": false, "update": false, "delete": false }
}
}readgateslistandget.create,updateanddeletealso requireread, because every write is read back.A connection with no policy starts read-only for every resource.
Operations outside the policy are omitted from
discoverand rejected withACCESS_DENIEDeven if a client guesses the operation id.Saving a policy increments the connection revision. The next MCP request re-resolves the revision; clients do not need to reconnect, but they must rediscover to see the new operation set.
The UI exposes this as Control access per connection.
Security design
Passkeys only. Registration, login and add-passkey ceremonies are verified with
@simplewebauthn/server, requiring user presence and user verification. Supported algorithms are ES256 and RS256.Signed ceremony state. Ceremony data lives in a
__Host-cookie signed with HMAC-SHA-256; it is bound to the purpose, origin, RP ID and, for add-passkey, the account and session hash.Sessions. Session tokens are 256-bit random values. Only their SHA-256 hash is stored. Cookies are
HttpOnly,Secure,SameSite=Strict,Path=/and host-only.CSRF. Mutations require
X-CSRF-Token, derived from the session token. The check is timing-safe.Origin checks. Browser API routes require the exact configured
Originand reject cross-site requests. JSON bodies are required for mutations.Replay protection and counters. Used WebAuthn challenges are recorded; authentication counters must advance. Session and challenge tables are pruned.
Rate limits. A per-address limiter protects authentication and a per-account limiter protects connection creation. Limits are approximate and per Cloudflare location.
Connection tokens. Each token contains the account id plus 256 random bits. Only a domain-separated SHA-256 hash is stored. URLs are returned only at creation or rotation; the UI clears them on page hide.
Encryption at rest. Upstream credentials are encrypted with AES-256-GCM. Additional authenticated data binds the ciphertext to the format version, account id, connection id and key version, so copying an envelope to another connection fails.
No secret logging. The Worker logs neither tokens, URLs, arguments nor credentials. Observability has
invocation_logsandredact_query_stringconfigured, andupload_source_mapsonly affects source maps.Small public surface. No public Durable Object fetch handler, no wildcard CORS, no
/debugendpoint, no query-string secrets.Revocation is immediate. Every MCP request resolves the current token hash, status, disabled flag and revision before running a tool.
Writes do not retry. Ambiguous outcomes are reported explicitly so an agent can read before acting.
See docs/SECURITY.md for the threat model and operational guidance.
Replace the demo app
The app-specific code is isolated in four files:
File | Responsibility |
|
|
| Resource and operation definitions, Zod validators, JSON Schemas, examples and the catalogue hash. |
| Demo implementation against the account SQLite database. |
| The |
Steps
Edit
src/app/catalogue.ts:Change
RESOURCES.Replace
OPERATIONSwith your operations. Give each a stable id, resource, kind, summary, description, Zod input schema, JSON Schema and examples.
Replace
src/app/demo.tswith your implementation, or delete it and call your upstream API fromsrc/index.ts.Keep the
AppSourcecontract:type AppSource = { catalogue(): Promise<Catalogue>; read(operationId: string, args: Record<string, unknown>): Promise<Record<string, unknown>>; write(operationId: string, args: Record<string, unknown>): Promise<Record<string, unknown>>; };Throw
AppErrorfor safe, structured failures. SetmutationSentwhen you know whether an upstream mutation was sent.Optionally replace
validateDemoCredentialwith a real upstream credential check.Remove the
demo_notestable fromsrc/accounts/schema.sqland the seed call insrc/accounts/object.tsonce your data no longer lives in the Durable Object.Update
public/index.html,public/how-it-works.htmlandsrc/mcp/server.tsinstructions to describe your app.
docs/REPLACING_THE_DEMO.md walks through a complete example with an upstream REST API.
Design guidance for operations
Prefer explicit operations over a generic query language. They are easier to validate, audit and scope.
Give list operations a bounded page size and an opaque cursor.
Include a
getoperation so agents can read before writing.For updates, accept partial changes and preserve unspecified fields.
Offer optimistic concurrency (
expected_updated_ator an etag) where stale writes matter.Never expose raw SQL, arbitrary URLs, shell commands or unrestricted HTTP as operations.
Keep descriptions short but state when to use the operation, what it returns and how pagination behaves.
Tests and checks
npm run checkWhat is covered:
tests/security.test.ts— credential encryption AAD/keyring boundaries, token routing and hash separation, ceremony signing/expiry/tampering, origin validation, access-policy normalization and catalogue visibility.tests/account-flow.test.ts— a real synthetic WebAuthn registration and login, session cookies and CSRF, connection creation with a credential, MCP tool listing, discovery, authorized read, denied write on a read-only connection, policy update, read-back write, rotation, revocation, and invalid tokens.
The tests run inside the Workers runtime via @cloudflare/vitest-plugin, with fresh keys generated by vitest.config.ts. They do not need Cloudflare credentials or network access.
Free-tier notes
Workers Free (checked November 2026):
Resource | Free allowance |
Worker requests | 100,000 per day (all Workers on the account) |
Worker CPU time | 10 ms per invocation |
Durable Objects | SQLite-backed only |
Durable Object requests | 100,000 per day |
Durable Object duration | 13,000 GB-s per day |
SQL rows read | 5 million per day |
SQL rows written | 100,000 per day |
Durable Object storage | 5 GB total |
Static asset requests | Free and unlimited |
Practical implications:
This starter is a good fit for a personal or small-team deployment, but 10 ms of CPU per request is tight for WebAuthn verification. If passkey registration or login intermittently fails with “Worker exceeded resource limits” (error 1102), move to the Workers Paid plan, which raises the CPU limit and includes 10 million requests and 30 million CPU-ms per month.
Every MCP tool call is a Worker request plus one or more Durable Object RPC requests. Each read/write also counts SQL rows. A chatty agent can exhaust the daily row-write allowance with rapid writes.
Rate limiting counters are approximate and per location. They are abuse protection, not a strict global quota.
Durable Objects are per-account and single-threaded; this design is intentionally simple and scales by adding accounts, not by sharding one account.
See docs/FREE_TIER.md for the full breakdown and cost-control suggestions. Always confirm current limits on Cloudflare’s pricing pages before relying on them.
Project layout
.
├── src/
│ ├── index.ts Worker entry, Hono routes, MCP mount
│ ├── app/
│ │ ├── types.ts AppSource and policy types
│ │ ├── catalogue.ts Operation definitions and JSON Schemas
│ │ ├── demo.ts Demo notes implementation
│ │ └── errors.ts Structured application errors
│ ├── accounts/
│ │ ├── object.ts AccountStore Durable Object
│ │ ├── schema.sql Account and demo SQLite schema
│ │ ├── routes.ts WebAuthn and session routes
│ │ ├── connection-routes.ts Connection and access management
│ │ ├── config.ts WebAuthn/origin/rate-limit validation
│ │ ├── ceremony.ts Signed ceremony cookies
│ │ ├── session.ts Session cookie helpers
│ │ ├── crypto.ts Token routing and AES-GCM envelopes
│ │ ├── keyring.ts Versioned keyring parsing
│ │ ├── access.ts Access policy schemas
│ │ ├── connections.ts Connection schemas and cursors
│ │ └── model.ts Account models and limits
│ └── mcp/
│ └── server.ts Three-tool MCP server
├── public/ Self-contained UI (no build step)
├── tests/ Workers-runtime tests
├── scripts/ Secrets generator and smoke test
├── docs/ Setup, security, operations, clients
├── .github/workflows/main.yml CI and deploy
├── wrangler.jsonc
└── vitest.config.tsTroubleshooting
Passkeys do not appear
Check
WEBAUTHN_RP_IDandWEBAUTHN_ORIGINmatch the exact address in your browser.http://is only allowed forlocalhost. Everything else needshttps://.If you changed hostnames, old passkeys are bound to the old hostname. Create a new account or add a passkey while still on the old hostname.
Some browsers require a platform authenticator or a security key. Try a different browser before changing code.
“Worker exceeded resource limits” / error 1102
WebAuthn verification or encryption may exceed the Free plan’s 10 ms CPU allowance. Move to Workers Paid, or test again with a smaller payload. The error code is visible in Workers metrics.
“Too many passkey requests”
The per-address authentication limiter fired. Wait about a minute. The limiter is per Cloudflare location. If you are testing, use a fresh browser profile or wait.
A connection URL returns 404
The token is unknown, revoked, rotated or disabled. A 404 is intentional: it does not reveal whether the account exists. Create or rotate a connection to get a working URL.
The URL was lost after creating a connection
By design it is shown once. Rotate the connection to get a new URL; all previously issued URLs for that connection stop working.
wrangler secret put complains about missing configuration
Run npx wrangler deploy --dry-run first to validate wrangler.jsonc. Secrets must be set per environment; if you add a Wrangler environment later, set them there too.
MCP client reports “unsupported protocol version”
Update the client. This server speaks the current MCP revision and supports the 2025-era stateless fallback. A very old client that requires sessionful transport may not work.
Local data vanished
wrangler dev may clear .wrangler/state depending on flags and version. Local data is disposable. Never treat it as production data.
Further documentation
docs/SETUP.md— deployment, secrets, custom domains, CI and first-run checklist.docs/ARCHITECTURE.md— request flow, Durable Object methods, storage schema and lifecycle.docs/SECURITY.md— threat model, token and key handling, revocation, incident response.docs/REPLACING_THE_DEMO.md— adapt the starter to a real upstream API.docs/CLIENTS.md— client setup patterns and compatibility notes.docs/OPERATIONS.md— key rotation, connection rotation, backup and recovery.docs/FREE_TIER.md— limits and cost control.
Use this starter as a starting point, not a finished product. Review the access scopes, operation set, logging and upstream credential handling for your own threat model before exposing it to users.
License
MIT. Use it for any project, commercial or otherwise. See LICENSE.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Connect AI agents to 580+ APIs with OAuth or API-key auth. Hosted gateway; API pricing varies.
Give your AI hands. Identity, credential vault, and API gateway for autonomous agents.
Connect AI agents to 1000+ apps with managed authentication and tool-calling.
Verified, pay-per-use API tools for AI agents through one authenticated connection.
Related MCP Servers
- AlicenseAqualityDmaintenanceEnables AI agents to make authenticated API calls and run commands with secrets injected, while keeping credentials completely hidden from the model, with policy enforcement, grants, and audit logging.6MIT
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to call external endpoints under per-endpoint policy enforcement, with credentials and personal data kept inside a hardware enclave and every allowed or denied attempt recorded to an immutable audit ledger.2ISC
- AlicenseNot gradedqualityAmaintenanceEnables AI agents to invoke upstream APIs without ever holding reusable credentials, using short-lived scoped capabilities and server-side secret injection. Also provides execution controls and x402 facilitator routing for secure agent actions.Apache 2.0
- AlicenseNot gradedqualityCmaintenanceExposes enterprise tools to third-party AI agents through a single guard that authorizes each call against default-deny, purpose-scoped entitlements, executes it, and writes a hash-chained, tamper-evident decision trace the firm owns. It also verifies signed vendor webhooks and enforces a strict versioned contract, so agent activity stays scoped, auditable, and portable across vendors.MIT