AI agents discover, pay for, and consume any Lightning-gated API autonomously
Copy the AI prompt to install this server into Claude Code, Cursor, or another agent β or use 1-click editor setup below.
We haven't yet run this listing's install command through our automated sandbox check. This isn't a red flag β we're steadily working through the catalog.
π‘ Paste the JSON block into your client's configuration file under mcpServers, then restart the application.
Inspect callable tools, capabilities, and parameters exposed to AI agents by 402 MCP.
l402-configIntrospect payment capabilities (wallets, limits, credential count)
l402-discoverProbe an endpoint to discover pricing without paying
l402-fetchHTTP request with L402 support; auto-pays if within budget
l402-payPay a specific invoice (NWC, Cashu, or human-in-the-loop)
l402-credentialsList stored credentials and cached balances
l402-balanceCheck cached credit balance for a server
Nostr: npub1mgvlrnf5hm9yf0n5mf9nqmvarhvxkc6remu5ec3vf8r0txqkuk7su0e7q2
L402 client MCP that gives AI agents economic agency. Discover, pay for, and consume Lightning and ecash payment-gated APIs within limits you set: no human registration, no API keys, no middlemen.
1. Install
2. Connect to Claude Code
3. 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.
Requires Node.js 22 or newer.
Example session:
For detailed architecture and payment flow diagrams, see docs/architecture.md.
| Variable | Default | Description |
|---|---|---|
NWC_URI_FILE | - | Path to a private 0600 file containing the NWC bearer URI |
CASHU_TOKENS | - | Path to Cashu token store file |
LNURLCASH_NOTES | - | Path to LNURLcash bearer note store file (LUD-25) |
MAX_AUTO_PAY_SATS | 1000 | Most a single automatic payment may cost. Anything dearer is not paid; the challenge goes back to the agent |
MAX_SPEND_PER_MINUTE_SATS | 10000 | Automatic spend allowed in any rolling 60 seconds. 0 blocks all auto-pay |
MAX_SPEND_PER_DAY_SATS | 5000 | Automatic spend allowed in any rolling 24 hours, kept in ~/.402-mcp/spend-ledger.json so a restart does not reset it. 0 blocks all auto-pay |
CREDENTIAL_STORE | ~/.402-mcp/credentials.json | Persistent macaroon/credential storage |
TRANSPORT | stdio | Transport mode: stdio or http |
PORT | 3402 | HTTP server port (when TRANSPORT=http) |
BIND_ADDRESS | 127.0.0.1 | HTTP bind address |
HTTP_AUTH_TOKEN_FILE | - | Private 0600 file holding the bearer token HTTP clients must send. Required when TRANSPORT=http |
HTTP_ALLOWED_HOSTS | - | Extra Host header values the HTTP transport accepts (comma-separated), such as a reverse proxy's name |
TRANSPORT_PREFERENCE | onion,hns,https,http | Preferred transport order for multi-URL services (comma-separated) |
TOR_PROXY | - | SOCKS5 proxy for .onion addresses only (e.g. socks5h://127.0.0.1:9050) |
SOCKS_PROXY | - | SOCKS5 proxy for every paid-API request (e.g. Tor at socks5h://127.0.0.1:9050). Set this or TOR_PROXY, not both |
HNS_GATEWAY_URL | https://query.hdns.io/ | DNS-over-HTTPS resolver used for Handshake names. Any host name that ordinary DNS cannot find is looked up here |
When a kind 31402 event advertises multiple URLs (one per transport), 402-mcp selects the best one based on your configuration:
TRANSPORT_PREFERENCE order, onion,hns,https,http by default. Use onion, hns, https and http as the values. A URL counts as hns when its TLD is .hns. One whose TLD is merely unfamiliar (.pub, .fyi) is more likely an ICANN name, so it is tried just after https..onion URLs are skipped unless TOR_PROXY or SOCKS_PROXY is set, so without a proxy the default order starts at HNS and clearnet.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.
TOR_PROXY sends .onion requests through the proxy. Everything else connects directly.SOCKS_PROXY sends every request to a paid API through the proxy, including redirects. Host names are resolved by the proxy, never by this machine, so a Tor proxy hides both your IP and the names you look up. The SSRF guard still refuses private IP literals and local names such as localhost; it cannot see what a name resolves to on the far side, which Tor exits refuse for private ranges anyway.Neither setting covers wallet or discovery traffic: NWC relays, Cashu and LNURLcash mints, and the Nostr relays l402-search queries still connect directly. Handshake lookups are switched off under SOCKS_PROXY, because the DNS-over-HTTPS query would go around the proxy.
SOCKS5 support comes from undici's Socks5ProxyAgent, which Node marks experimental; expect one ExperimentalWarning on stderr when a proxy is configured.
| Tool | Description |
|---|---|
l402-config | Introspect payment capabilities (wallets, limits, credential count) |
l402-discover | Probe an endpoint to discover pricing without paying |
l402-fetch-preview | Show what an endpoint costs without paying; drives the payment confirmation widget |
l402-fetch | HTTP request that pays a 402 challenge when autoPay is set and the price is within the limits |
l402-pay | Pay a challenge returned by l402-fetch or l402-discover, by its payment hash. Any other invoice needs the human's approval |
l402-reconcile | List or resolve payments whose outcome is unknown; auto-pay to that service is paused until they are resolved |
l402-credentials | List stored credentials and cached balances |
l402-balance | Check cached credit balance for a server |
l402-search | Discover L402 services on Nostr relays (kind 31402 announcements) |
l402-store-token | Store an L402 token obtained from a payment page |
| Tool | Description |
|---|---|
l402-service-directory | Interactive, searchable directory of services found by l402-search |
l402-wallet-dashboard | Interactive view of wallet status, limits and stored credentials |
l402-fetch-preview also has a payment confirmation widget.
| Tool | Description |
|---|---|
l402-buy-credits | Browse and purchase volume discount tiers |
l402-redeem-cashu | Redeem Cashu tokens directly (avoids Lightning round-trip) |
Four payer methods, tried in priority order:
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, plus an experimental x402 format:
| Protocol | Challenge header | Payment |
|---|---|---|
| L402 | WWW-Authenticate: L402 | Lightning invoice via wallet stack |
IETF Payment (draft-ryan-httpauth-payment-01) | WWW-Authenticate: Payment | Lightning invoice via wallet stack |
| LNURLcash (LUD-25) | X-LNURLcash: lnurlcashreq1β¦ | Bearer note handed over directly (requires a note store) |
| xCashu (NUT-18) | X-Cashu: creqA⦠| Ecash token sent directly (requires Cashu wallet) |
| x402 (experimental, custom format) | X-Payment-Required: x402 + JSON body | A custom format, not the x402 specification (whose servers send a base64 PAYMENT-REQUIRED header), so real x402 services are not supported. Payment details are shown to the human, who pays from their own wallet |
An LNURLcash challenge is tried first. A bearer note is already money in hand, so paying one costs no Lightning hop and no swap at the mint: the note goes straight into the retry header and the server settles it. When the price does not match a note exactly, one is split at the mint and the change stays in the store. If no note covers it, the other rails are tried as usual.
Factual signals from GitHub, npm, and our automated checks β not a rating.
No reviews yet β be the first to share how this listing worked for you.
Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.
[](https://allmcps.com/mcp/402-mcp)<a href="https://allmcps.com/mcp/402-mcp"><img src="https://allmcps.com/api/badge/402-mcp?style=directory" alt="402 MCP on AllMCPs" /></a>