AI Agent Integration
The open-source (MIT) Lightning Enable MCP server lets an AI agent such as Claude pay Lightning invoices and L402-protected APIs from a wallet you connect. Paying needs only a wallet; selling access (l402_producer) and some agent-marketplace actions need a Lightning Enable API key.
How auto-pay works
When the agent calls access_l402_resource on a URL that answers 402 Payment Required, the MCP server:
- Reads the Lightning invoice (and macaroon) from the 402 response.
- Checks the price against your budget limits, and asks you for a confirmation code if the payment is above your auto-approve threshold.
- Pays the invoice from your wallet and gets the preimage.
- Retries the request with
Authorization: L402 <macaroon>:<preimage>and returns the response.
User → Agent → MCP server → L402 API
↓
Your Lightning wallet (LND, NWC, or Strike)
L402 needs a wallet that returns the preimage: LND, Strike, or an NWC wallet such as CoinOS, CLINK, or Alby Hub. OpenNode and Primal can pay plain invoices with pay_invoice but can't complete L402.
Set it up
- Install and connect a client. Follow MCP Quick Start, or the client guides for Claude Code, Cursor, Hermes, or Buzz.
- Pick a wallet. See Wallet Configuration or LND Node Setup.
- Set spending limits in
~/.lightning-enable/config.jsonbefore the first payment. See AI Spending Security.
Tools you'll use most
| Tool | What it does |
|---|---|
access_l402_resource | Fetch a URL and pay its L402 challenge automatically |
pay_l402_challenge | Pay an invoice (and macaroon) you already hold; returns the credential |
pay_invoice | Pay any BOLT11 invoice and return the preimage |
discover_api | Search the L402 registry, or read one API's manifest and prices |
get_balance | Wallet balance and session spend |
budget | Read limits (action="status") or lower them for this session (action="tighten") |
receipts | List payments (source="durable" or source="session") |
The MCP Complete Guide lists every tool, its parameters, and the tool profiles.
Example
User: Get the 7-day forecast from the Lightning weather API at
https://api.example.com/l402/proxy/weather/forecast/7day
Agent: [Uses access_l402_resource]
The forecast cost 25 sats, paid from your wallet. Here it is: ...
Building your own integration
Outside an MCP client, use the L402 client libraries. They detect a wallet from the same environment variables (LND > NWC > Strike > OpenNode).
Python (l402-requests):
# pip install l402-requests
from l402_requests import AsyncL402Client
async with AsyncL402Client() as client:
response = await client.get("https://api.example.com/paid-resource")
print(response.json())
.NET (L402Requests):
// dotnet add package L402Requests
using L402Requests;
using var client = new L402HttpClient(new L402Options { MaxSatsPerRequest = 1000 });
var response = await client.GetAsync("https://api.example.com/paid-resource");
Console.WriteLine(await response.Content.ReadAsStringAsync());
Both packages document their budget controls and domain allowlists.
Next steps
- MCP Complete Guide - full tool and configuration reference
- AI Spending Security - read before letting an agent pay
- How It Works - the L402 protocol
- Proxy Configuration - put your own API behind L402