The Model Context Protocol (MCP) lets an AI assistant discover and call tools on a remote server. What it does not specify is how the server gets paid for a single call. API keys and monthly plans work, but they force a sign-up before the first request. This article walks through a pay-per-call pattern that uses Lightning invoices and L402, so a client can try a tool, pay a few satoshis, and get the result, without creating an account.
The examples use a public MCP endpoint that speaks this flow. You can run the same commands against your own server if you implement the same steps.
What MCP gives you, and what it does not
A remote MCP server is typically reached over Streamable HTTP. The payload is JSON-RPC. Two methods matter for tools:
-
tools/listreturns the names, descriptions and input schemas. -
tools/callruns one tool with a JSON argument object.
A first handshake uses initialize and advertises a protocol version (this article uses 2025-06-18). After that, a client can list tools and call them. None of those methods mentions money, invoices, or credentials. If you want payment, you have to add it on top, without breaking clients that only speak MCP.
What L402 adds
L402 (Lightning HTTP 402) is a protocol from Lightning Labs. The idea is simple:
- The server issues a Lightning invoice (BOLT 11) and a macaroon that is cryptographically bound to that invoice's payment hash.
- The client pays the invoice with any Lightning wallet and receives the preimage.
- The client retries the request with the macaroon and the preimage. The server checks that
sha256(preimage)equals the payment hash.
If the check passes, the caller has paid that invoice. The server does not need a user table for this. A credential is valid for that payment, not as a reusable API key.
A caveat on the standards: L402 is specified by Lightning Labs. A write-up as bLIP-26 is still an open pull request in the Lightning specifications, not a merged standard. Treat it as a working protocol, not as something every Lightning stack already implements.
A flow that fits tools/call
Here is a pattern that has worked for us when putting L402 in front of MCP tools.
Reject bad input for free. If the arguments fail validation, return the error immediately and do not issue an invoice. That saves the client a payment for a call that would never have succeeded, and it stops a typo from locking sats in an invoice that then expires.
On a valid paid call, return the invoice instead of the result. The MCP tool result (or an HTTP 402 on a plain REST API) includes the BOLT 11 invoice and the macaroon. The price should already have been advertised, for example in the tool description or via a separate free quote tool.
The client pays, then retries the same call. Same tool name, same arguments, plus l402_macaroon and l402_preimage. The server re-validates the input, checks the preimage, and only then runs the expensive part and returns the result.
Offer free quote and status tools. A quote tool can return the price, and sometimes pre-check the input, without an invoice. A status tool can poll a previous job (for example a timestamp waiting for a Bitcoin confirmation) without paying again.
A client should also do two boring but important checks before it pays: the invoice amount must match the advertised price, and the expiry must still be in the future. That check belongs in the wallet or the MCP client, not in a prompt that asks the model to "please be careful".
Try the handshake (no account)
These two requests need no login and no Lightning payment. They only show that the server speaks MCP:
curl -sS -X POST https://api.bitrovas.ch/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-H 'MCP-Protocol-Version: 2025-06-18' \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"demo","version":"0"}}}'
The result includes serverInfo and the protocol version. Then list the tools:
curl -sS -X POST https://api.bitrovas.ch/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-H 'MCP-Protocol-Version: 2025-06-18' \
-d '{"jsonrpc":"2.0","id":2,"method":"tools/list"}'
You should see paid tools (for example a PSBT pre-sign check or a Swiss QR-bill check) and free ones (quote and status tools such as bitrovas_psbtcheck_quote or bitrovas_adresswaechter_info). A free tool is just tools/call with the tool name and empty or minimal arguments, still without a payment.
The OpenAPI and protocol docs live at https://api.bitrovas.ch/docs and https://api.bitrovas.ch/llms.txt if you prefer to read the REST side of the same services.
Wiring a wallet
The agent needs a Lightning wallet it is allowed to spend from. A few practical rules:
- Use a dedicated wallet with a hard daily cap, not the wallet that holds savings.
- NWC (Nostr Wallet Connect) is a convenient way to let an agent pay invoices within that cap.
- Keep receipts: payment hash, preimage, amount, tool name, and time. You will want them when a retry fails or when you debug a client.
- If the first paid call returns an invoice and the retry with the preimage still fails, do not pay a second invoice for the same input until you understand why. The first invoice may still be unpaid, expired, or already settled.
What can go wrong
- The model invents an amount. Always parse the invoice and compare it with the published price.
- A retry changes the arguments. The macaroon is bound to a payment, and the server should also re-check that the input still matches what was quoted. If the client tweaks a field, it should expect a new invoice, not a free retry.
- Expiry. Lightning invoices expire. A client that waits too long has to start again, and should not reuse a preimage from a different payment.
- Double spend of attention, not of sats. Paying twice for the same work is usually a client bug (lost preimage, second call with different JSON). Persist the credential next to the request body until the result is in.
Where this is useful
This pattern fits tools that are cheap, deterministic, and called occasionally: checking a Bitcoin PSBT before it is signed, validating a file, stamping a hash, deriving watch-only addresses. It fits less well when a call is tiny and frequent enough that the Lightning fee and the round trips cost more than the work itself. In that case a prepaid balance or a short-lived session might be the better shape, still without a traditional account if you want that.
Sources
- MCP transports: https://modelcontextprotocol.io/specification/2025-03-26/basic/transports
- L402 specification: https://github.com/lightninglabs/L402/blob/master/protocol-specification.md
- bLIP-26 (open pull request): https://github.com/lightning/blips/pull/26
The public MCP server used in the examples is Bitrovas, listed in the official MCP Registry as io.github.bitrovas/mcp. Connector page: https://glama.ai/mcp/connectors/io.github.bitrovas/mcp
Top comments (0)