Build native Streamable HTTP MCP servers that charge per call with x402.
Warning
Security notice (2026-11-18): forks made before commit c87bc07 let anyone call paid tools for free. If your server is based on this template, check whether you're affected and update. See SECURITY.md.
Requires Node.js 22 or newer.
npm install
npm run setup
npm run devDefault setup is NETWORK_MODE=test so you can start with Base Sepolia before switching to live mode.
| Command | What it does |
|---|---|
npm run setup |
creates .env, generates SEED_PHRASE (never overwrites one) |
npm run wallet:create |
prints a new receiver seed phrase |
npm run wallet:info |
shows receiver address plus Base/Plasma balances |
npm run calls:recent |
shows recent paid/trial calls from SQLite |
npm run dev |
starts the native MCP server at /mcp |
npm run build && npm start |
runs compiled server |
npm test |
runs the payment-enforcement tests (no chain or network needed) |
npm run check |
lint, typecheck, build and test |
- Native MCP endpoint:
POST/GET/DELETE /mcp - Compatibility listing endpoint:
GET /mcp/tools - Health check:
GET /health
Tool authoring stays in src/tools.ts. The server automatically exposes those tools over MCP and enforces x402 for tools/call.
- Every
tools/callfor a listed tool needs an x402 payment, unless the caller still has free trial calls. - Each POST must be a single JSON-RPC message with
Content-Type: application/json. Batch requests are rejected. - Calls with unknown tools or invalid arguments are rejected before any tool code runs, and are never charged.
- If a paid tool fails, the payment is not settled, so the caller is not charged.
- A payment signature can only be used by one request at a time.
FREE_TRIAL_CALLSsets the free calls per client IP: 10 by default in test mode, 0 in live mode.- Trial calls are reserved before the tool runs, so concurrent requests cannot exceed the quota. A failed trial call is given back.
- Behind a proxy (Fly.io, Railway), set
TRUST_PROXY=1so the real client IP is used.deploy/fly.tomlalready does this. - IP limits can be bypassed by clients with many addresses. Keep live-mode trials low for expensive tools.
src/tools.ts- define paid tools (name,description,priceUsdt, schema, handler)src/server.ts- MCP transport + per-tool x402 enforcement + trial handlingsrc/config.ts- env validationsrc/log.ts- SQLite call loggingsrc/payments.ts- facilitator + x402 scheme wiring
See .env.example for all variables.
NETWORK_MODE=test|livepicks the defaults: Base Sepolia USDC with the x402.org facilitator in test mode; Base mainnet USDC with the Coinbase CDP facilitator, plus Plasma USDT0, in live mode.- Leave
BASE_RPC_URL,USDC_ADDRESSandBASE_FACILITATOR_URLempty to use those defaults. - For the live Coinbase facilitator, set
CDP_API_KEY_ID+CDP_API_KEY_SECRET.
- Fly.io config:
deploy/fly.toml - Railway config:
deploy/railway.json - Dockerfile:
deploy/Dockerfile
deploy/fly.toml sets DB_PATH=/app/data/paidmcp.db so SQLite persists on the mounted volume, and TRUST_PROXY=1. On Railway, set TRUST_PROXY=1 in the service variables.
MIT. See LICENSE.