402-mcp
402-mcp
Nostr: npub1mgvlrnf5hm9yf0n5mf9nqmvarhvxkc6remu5ec3vf8r0txqkuk7su0e7q2
L402 + x402 client MCP that gives AI agents economic agency. Discover, pay for, and consume any payment-gated API — no human registration, no API keys, no middlemen.
Discover paid APIs on Nostr — no URLs needed upfront
Auto-pay with Lightning (NWC), Cashu ecash, or human QR fallback
Credentials cached and encrypted at rest (AES-256-GCM)
Works with any L402 server — toll-booth, Aperture, or any future implementation
Quick start
1. Install
npx 402-mcp2. Connect to Claude Code
claude mcp add 402-mcp -- npx 402-mcp3. Try it
Ask Claude: "Search for paid joke APIs using l402-search" — no wallet needed, just discovery.
Ready to make paid calls? See the full quickstart guide to set up a wallet and watch your agent pay for its first API call.
How it works
graph LR
A["1. l402-config()"] --> B["2. l402-discover(url)"]
B --> C["3. Agent reasons<br/>about pricing"]
C --> D["4. l402-buy-credits()<br/>or l402-fetch()"]
D --> E["5. l402-fetch(url)<br/>with credentials"]
E --> F["6. Data returned<br/>+ balance cached"]Example session:
Agent: "I need routing data from routing.trotters.cc"
1. l402-config()
-> nwcConfigured: true, maxAutoPaySats: 1000
2. l402-discover("https://routing.trotters.cc/api/route")
-> 10 sats/request, toll-booth detected, tiers available
3. Agent reasons: "I need ~20 requests. The 500-sat tier
gives 555 credits. Better value."
4. l402-buy-credits(url, amountSats=500)
-> Paid 500 sats, received 555 credits
5. l402-fetch("https://routing.trotters.cc/api/route?from=...&to=...")
-> 200 OK, route data, 545 credits remainingFor detailed architecture and payment flow diagrams, see docs/architecture.md.
Configuration
Variable | Default | Description |
| - | Nostr Wallet Connect URI for autonomous Lightning payments |
| - | Path to Cashu token store file |
| 1000 | Safety cap; payments above this require human confirmation |
|
| Persistent macaroon/credential storage |
|
| Transport mode: |
| 3402 | HTTP server port (when |
|
| Preferred transport order for multi-URL services (comma-separated) |
| - | SOCKS5 proxy for |
| - | Generic SOCKS5 proxy for all requests when set |
| - | HTTP gateway for Handshake ( |
Transport selection and fallback
When a kind 31402 event advertises multiple URLs (one per transport), 402-mcp selects the best one based on your configuration:
Preference first — if
TRANSPORT_PREFERENCE=torand a.onionURL is available, it is tried first.Availability fallback — if the preferred transport is unreachable (proxy not configured, timeout), the client falls back to the next URL in the list.
Clearnet default — if no preference is set, clearnet URLs are tried before
.onionor HNS entries.
Services can announce multiple endpoints for the same service (same pricing, same macaroon key) on different transports. This is purely for censorship resistance; you do not need to re-authenticate when switching transports. To reach Tor or HNS endpoints you must configure the corresponding proxy/gateway env vars above.
Tools
Core L402 (any server)
Tool | Description |
| Introspect payment capabilities (wallets, limits, credential count) |
| Probe an endpoint to discover pricing without paying |
| HTTP request with L402 support; auto-pays if within budget |
| Pay a specific invoice (NWC, Cashu, or human-in-the-loop) |
| List stored credentials and cached balances |
| Check cached credit balance for a server |
| Discover L402 services on Nostr relays (kind 31402 announcements) |
| Store an L402 token obtained from a payment page |
toll-booth extensions
Tool | Description |
| Browse and purchase volume discount tiers |
| Redeem Cashu tokens directly (avoids Lightning round-trip) |
Payment methods
Three payment rails, tried in priority order:
NWC (Nostr Wallet Connect) — fully autonomous; pays from your connected wallet
Cashu — fully autonomous; melts ecash tokens to pay invoices
Human-in-the-loop — presents QR code, polls for settlement
The agent can override the method per-call, or you can configure only the methods you want.
l402-fetch handles four HTTP 402 challenge variants transparently:
Protocol | Challenge header | Payment |
L402 |
| Lightning invoice via wallet stack |
IETF Payment ( |
| Lightning invoice via wallet stack |
xCashu (NUT-18) |
| Ecash token sent directly (requires Cashu wallet) |
x402 |
| On-chain EVM transfer; surfaced to human with EIP-681 deeplink |
Safety
MAX_AUTO_PAY_SATS caps any single autonomous payment. Above this limit, the agent must ask the human for approval. The agent can read this limit via l402-config and factor it into purchasing decisions.
Privacy
402-mcp stores credentials locally on your machine only (~/.402-mcp/credentials.json, encrypted at rest). No data is sent to any third party. No accounts, no tracking, no analytics. Payments use Lightning or Cashu — pseudonymous by design.
Ecosystem
Browse live L402 services at 402.pub — the decentralised marketplace for payment-gated APIs.
Project | Role |
Payment-rail agnostic HTTP 402 middleware | |
Pay-per-token AI inference proxy (built on toll-booth) | |
MCP client — AI agents discover, pay, and consume L402 + x402 APIs | |
Publish L402 services on Nostr for decentralised discovery |
402-mcp is the payment-rail agnostic alternative to Lightning Labs' lightning-agent-tools and Coinbase's x402 — no Lightning node required, multiple wallets, encrypted credentials.
402-mcp | Lightning Labs agent tools | |
Payment rails | NWC + Cashu + human fallback | Lightning only |
Node required? | No — connects to any NWC wallet | Yes — runs LND |
Server compatibility | Any L402 server | Aperture-focused |
Spend safety | Per-payment cap + rolling 60s window | Per-call max-cost |
Credential storage | Encrypted at rest (AES-256-GCM) | File permissions |
Privacy | No PII, SSRF protection, error sanitisation | Standard |
Use Lightning Labs' tools if you want agents that run their own Lightning node. Use 402-mcp if you want agents that pay from any wallet without infrastructure.
See CONTRIBUTING.md for development setup and guidelines.
Built by @forgesworn.
Lightning tips:
thedonkey@strike.meNostr:
npub1mgvlrnf5hm9yf0n5mf9nqmvarhvxkc6remu5ec3vf8r0txqkuk7su0e7q2
Part of the ForgeSworn Toolkit
ForgeSworn builds open-source cryptographic identity, payments, and coordination tools for Nostr.
Library | What it does |
Deterministic sub-identity derivation | |
SAG/LSAG ring signatures on secp256k1 | |
Pedersen commitment range proofs | |
Coercion-resistant spoken verification | |
Human-speakable verification tokens | |
L402 payment middleware | |
Geohash toolkit with polygon coverage | |
NIP-VA verifiable attestations | |
Epoch-based encrypted access control | |
Privacy-preserving Web of Trust |
Licence
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/forgesworn/402-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server