Documentation

Two things, one meter.

Tollgate is a billing SDK for MCP servers and a paid MCP server built on it. The server is the SDK's first customer — every claim in these docs is exercised in production by the thing serving them.

The SDK

@tollgate/sdk (TypeScript, MIT, zero runtime dependencies) wraps your MCP endpoint:

how a request flows
POST /mcp
  │
  ▼
tollgate.protect(request, next)
  ├─ parse JSON-RPC            // reject batches, bad JSON
  ├─ resolve Bearer tg_… key   // SHA-256 lookup, fail fast
  ├─ free method?  ────────────▶ next()   // initialize, tools/list, ping
  ├─ rate limit (120/min/key)  // -31429 with retry hint
  ├─ charge credits            // atomic; free pool, then paid
  │    └─ insufficient ───────▶ -31402 + checkout_url
  └─ next({ message, ctx })    // your handler, your tools

Storage is pluggable (D1Store for Cloudflare D1, MemoryStore for tests and toys), billing is pluggable (Lemon Squeezy → Stripe → mock, picked by which env keys exist), and the error surface is three documented JSON-RPC codes agents can act on.

Quickstart →

The hosted server

An MCP server with data agents actually pay for: current LLM API prices and limits, a snapshot of the official MCP registry, and changelogs of major AI tools. Every record carries source_url and collected_at — nothing is model-generated.

Endpoint, tools and clients →

Run it yourself

terminal — local, 5 minutes
$ git clone <repo> tollgate && cd tollgate
$ npm install
$ npm run db:apply:local      # D1 schema into local sqlite
$ npm run dev                 # wrangler dev on :8788
$ npm test                    # 55 unit tests
$ npm run e2e                 # official MCP client, full billing loop

No env vars needed locally: billing runs the mock driver, admin uses a dev token, and the data is bundled. Set keys when you go live — billing drivers.