AI Agent Integration
Lightning Enable provides MCP (Model Context Protocol) servers that enable AI agents like Claude to automatically access L402-protected APIs with Lightning payments.
The MCP server is open-source (MIT) and free to install. Wallet, invoice, L402, budget, and API-discovery tools work out of the box with just a wallet — no account or API key required. Producer tools (sell access via L402) and Agent Service Agreement tools (agent-to-agent commerce over Nostr) unlock with a Lightning Enable API key. See the MCP Complete Guide for the full tool list.
Overview
When an AI agent encounters an L402-protected resource, the MCP server automatically:
- Detects the 402 Payment Required response
- Pays the Lightning invoice via your configured wallet (Strike, LND, or NWC — must return preimage for L402)
- Retries the request with the L402 credential
- Returns the response to the agent
The MCP server can also pay Lightning invoices directly using the pay_invoice tool, enabling AI agents to make arbitrary Lightning payments on your behalf.
This enables seamless pay-per-request API access without user intervention.
User → Claude → MCP Server → L402 API
↓
Lightning Wallet (Strike, LND, or NWC)
L402 auto-pay requires the payment preimage. These wallets work:
- LND (self-hosted) - Best for guaranteed L402, always returns preimage
- NWC with CoinOS - Free, easy, returns preimage
- NWC with CLINK - Nostr users, returns preimage
- Strike - Easy setup, returns preimage via
lightning.preImage - Alby Hub - You hold the keys, returns preimage
These do NOT work for L402 (no preimage return):
- OpenNode - No preimage
- Primal - No preimage
Available Implementations
Python MCP Server
Recommended for Claude Desktop on all platforms.
pip install lightning-enable-mcp
Or use uvx (no installation needed):
{
"mcpServers": {
"lightning-enable": {
"command": "uvx",
"args": ["lightning-enable-mcp"],
"env": {
"NWC_CONNECTION_STRING": "nostr+walletconnect://..."
}
}
}
}
.NET MCP Server
For Windows users or .NET environments:
dotnet tool install -g LightningEnable.Mcp
Configuration (for L402, use LND, Strike, or NWC with CoinOS/CLINK):
{
"mcpServers": {
"lightning-enable": {
"command": "dotnet",
"args": ["tool", "run", "lightning-enable-mcp"],
"env": {
"NWC_CONNECTION_STRING": "nostr+walletconnect://..."
}
}
}
}
Configuration
Wallet Options
The MCP server supports multiple wallet providers. Choose one based on your needs:
| Wallet | Best For | Setup Complexity | L402 Auto-Pay |
|---|---|---|---|
| LND (self-hosted) | L402 auto-pay (guaranteed) | Hard (run a node) | ✅ Yes |
| NWC (CoinOS/CLINK) | L402 auto-pay (easy) | Medium (wallet setup) | ✅ Yes |
| Alby | L402 auto-pay | Medium (wallet setup) | ✅ Yes |
| Strike | USD users, everyday spending | Easy (API key) | ✅ Yes |
| OpenNode | Direct payments only | Easy (API key) | ❌ No* |
*OpenNode does not return the payment preimage, which is required for L402 credential verification. Use only for direct pay_invoice calls.
If multiple wallets are configured, they are used in this order (optimized for L402):
- LND (if
LND_REST_HOST+LND_MACAROON_HEXare set) - NWC (if
NWC_CONNECTION_STRINGis set) - Strike (if
STRIKE_API_KEYis set) - OpenNode (if
OPENNODE_API_KEYis set)
Override with WALLET_PRIORITY environment variable or config file wallets.priority.
Option 1: Strike (Recommended for USD Users)
Strike is ideal if you prefer managing funds in USD. It provides easy on/off ramps and supports both Bitcoin and USD balances.
- Create an account at https://strike.me
- Get your API key from https://dashboard.strike.me
- Fund your Strike account
{
"mcpServers": {
"lightning-enable": {
"command": "dotnet",
"args": ["tool", "run", "lightning-enable-mcp"],
"env": {
"STRIKE_API_KEY": "your-strike-api-key"
}
}
}
}
| Variable | Required | Default | Description |
|---|---|---|---|
STRIKE_API_KEY | Yes | - | Strike API key |
Strike now returns the payment preimage via lightning.preImage, enabling full L402 support. Strike works for both direct payments (pay_invoice) and L402 auto-pay (access_l402_resource). Ensure your Strike account has BTC balance (payments use BTC, not USD).
Additional Strike features:
get_btc_price- Get current BTC/USD priceget_all_balances- View USD and BTC balancesexchange_currency- Convert between USD and BTCsend_onchain- Send on-chain Bitcoin payments
Option 2: OpenNode (Direct Payments Only)
Use your OpenNode account to pay invoices directly. Note: OpenNode does not return preimages, so it cannot be used for L402 auto-pay.
- Get your API key from https://app.opennode.com (or https://dev.opennode.com for testnet)
- Ensure the API key has withdrawal permissions
- Fund your OpenNode account
{
"mcpServers": {
"lightning-enable": {
"command": "dotnet",
"args": ["tool", "run", "lightning-enable-mcp"],
"env": {
"OPENNODE_API_KEY": "your-opennode-api-key",
"OPENNODE_ENVIRONMENT": "dev"
}
}
}
}
| Variable | Required | Default | Description |
|---|---|---|---|
OPENNODE_API_KEY | Yes | - | OpenNode API key with withdrawal permissions |
OPENNODE_ENVIRONMENT | No | production | production for mainnet, dev for testnet |
Option 3: Nostr Wallet Connect (NWC)
NWC connects the MCP server to a Lightning wallet via the Nostr protocol. L402 compatibility depends on the wallet.
| Wallet | L402 Works | Cost |
|---|---|---|
| CoinOS | ✅ Yes | Free |
| CLINK | ✅ Yes | Free (Nostr users) |
| Alby | ✅ Yes | Self-host or paid cloud |
| Primal | ❌ No | Free (no preimage) |
| Variable | Required | Default | Description |
|---|---|---|---|
NWC_CONNECTION_STRING | Yes | - | Nostr Wallet Connect URI |
Getting an NWC Connection String
Available NWC providers:
| Wallet | L402 | Setup |
|---|---|---|
| CoinOS | ✅ Yes | Settings → NWC (Free, recommended) |
| CLINK | ✅ Yes | Nostr-native wallet |
| Alby Hub | ✅ Yes | Dashboard → Connections |
| Primal | ❌ No | Settings → Wallet → NWC (direct payments only) |
The connection string format:
nostr+walletconnect://<pubkey>?relay=<relay-url>&secret=<secret>
Claude Desktop Setup (For L402 - Use LND or NWC)
Add to your Claude Desktop config:
Windows: %APPDATA%\Claude\claude_desktop_config.json
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Linux: ~/.config/claude/claude_desktop_config.json
Option A: LND (Guaranteed L402)
{
"mcpServers": {
"lightning-enable": {
"command": "dotnet",
"args": ["tool", "run", "lightning-enable-mcp"],
"env": {
"LND_REST_HOST": "localhost:8080",
"LND_MACAROON_HEX": "your-admin-macaroon-in-hex"
}
}
}
}
Option B: NWC with CoinOS (Free, Easy)
{
"mcpServers": {
"lightning-enable": {
"command": "dotnet",
"args": ["tool", "run", "lightning-enable-mcp"],
"env": {
"NWC_CONNECTION_STRING": "nostr+walletconnect://..."
}
}
}
}
Available Tools
access_l402_resource
Fetch a URL with automatic L402 payment handling.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
url | string | Yes | - | URL to fetch |
method | string | No | GET | HTTP method |
headers | object | No | Additional headers | |
body | string | No | - | Request body |
max_sats | int | No | 1000 | Max payment |
confirmation_nonce | string | No | - | Confirmation code from the server console (confirmationNonce in .NET). Required on the retry when the first call returned requiresConfirmation=true |
Example conversation:
User: Fetch the premium data from https://api.example.com/l402/proxy/data
Claude: I'll access that L402-protected resource.
[Uses access_l402_resource]
The request required 50 sats which was automatically paid.
Here's the response: {"data": "premium content..."}
pay_l402_challenge
Manually pay an L402 invoice when you have the components.
| Parameter | Type | Required | Description |
|---|---|---|---|
invoice | string | Yes | BOLT11 invoice |
macaroon | string | No | Base64 macaroon. Omit for MPP (Machine Payments Protocol) mode — invoice + preimage only |
max_sats | int | No | Max payment |
confirmation_nonce | string | No | Confirmation code from the server console (confirmationNonce in .NET). Required on the retry when confirmation was requested |
Returns: L402 credential macaroon:preimage (or the bare preimage in MPP mode)
check_wallet_balance
Check connected wallet balance and session spending.
User: Check my wallet balance
Claude: [Uses check_wallet_balance]
Wallet Balance: 50,000 sats
Session Spending: 150 sats
Budget Remaining: 9,850 sats