MCP server + Lightning — AI agents that create invoices and process payments programmatically.
This diagram shows how AI agents (Claude, GPT, custom agents) use the SatsRail MCP server to programmatically create orders, generate Lightning invoices, and process payments — no browser, no forms, no redirects. The MCP server wraps the SatsRail REST API and exposes it as tool calls that any MCP-compatible agent can invoke.
| Tool | Description | Used In |
|---|---|---|
create_order |
Create a payment order with optional auto-generated Lightning invoice | Phase 2 |
get_order |
Get order details by ID (expandable: invoice, payment, merchant) | Phase 2 |
list_orders |
List orders with optional status filter | Phase 4 |
cancel_order |
Cancel a pending order | Error recovery |
get_invoice |
Get invoice details including bolt11 Lightning string | Phase 2 |
check_invoice_status |
Real-time payment status check against the Lightning node | Phase 2, 3 |
generate_invoice |
Generate a new invoice for an existing order (on expiry) | Error recovery |
list_payments |
List confirmed payments with optional date range filter | Phase 4 |
get_payment |
Get payment details | Phase 4 |
create_checkout_session |
Create a hosted checkout session with redirect URL | Phase 3 |
get_merchant |
Get the current merchant's profile and settings | Phase 1 |
list_wallets |
List connected wallets | Phase 1 |
Add the SatsRail MCP server to your AI agent's configuration:
{
"mcpServers": {
"satsrail": {
"command": "npx",
"args": ["-y", "satsrail-mcp"],
"env": {
"SATSRAIL_API_KEY": "sk_live_your_key_here"
}
}
}
}
The MCP server authenticates with the SatsRail API using the
sk_live_
key and exposes 12 tools to the agent.
When the MCP server starts, it connects to the SatsRail API, validates the key, and advertises all available tools (create_order, check_invoice_status, etc.) to the agent. The agent can now invoke any tool as part of a conversation.
The agent determines a payment is needed (based on conversation context or autonomous task) and calls:
create_order({
amount_cents: 2500,
currency: "usd",
description: "Monthly subscription",
generate_invoice: true,
payment_method: "lightning"
})
SatsRail creates an Order, converts USD → sats, generates a BOLT-11 Lightning invoice from the merchant's node (non-custodial), and returns the order with the bolt11 string.
The agent now has a BOLT-11 invoice string. Three paths:
After payment, the agent calls
check_invoice_status
to verify:
generate_invoice
to create a new invoice for the same order at the current BTC rate
For more complex sales, the agent calls
create_checkout_session
to generate a hosted checkout URL. The agent shares this link with the customer (in chat, email, Slack, etc.). The customer completes the payment through the standard SatsRail checkout flow. The agent polls for completion using
check_invoice_status
and confirms when paid.
The agent can query transaction history for reporting:
list_payments — retrieve all payments with date range filterslist_orders — check order statusesget_merchant — get merchant profile and settingsAll MCP-initiated transactions are also visible in the SatsRail Dashboard, where the merchant can see agent-initiated vs manual transactions side by side.
| Error | Trigger | Agent Behavior | Recovery |
|---|---|---|---|
| MCP Connection Failure | MCP server process crashes or fails to start | Agent detects tool unavailability | Retry MCP connection or fall back to direct REST API calls |
| Invalid Tool Parameters | Agent passes wrong types or missing required fields | MCP server returns structured error with field details | Agent corrects parameters and retries the tool call |
| 429 Rate Limited | Too many API calls per minute | Agent receives rate limit error | Agent implements exponential backoff before retrying |
| Invoice Expired | BOLT-11 invoice TTL exceeded (typically 1 hour) | check_invoice_status returns "expired" | Agent calls generate_invoice for a new invoice at current rate |
| Lightning Routing Failure | No route found to recipient node | Payer's wallet returns routing error | Retry later (channel liquidity may change) |
| Invalid API Key | sk_live_ key is wrong or revoked | MCP server fails to start / returns auth error | Developer checks SATSRAIL_API_KEY env variable |
User "Charge me $25 for the monthly subscription"
Agent → calls create_order(amount_cents: 2500, generate_invoice: true)
Agent "Here's your Lightning invoice. Scan this QR code or copy the payment string:"
lnbc250u1pj...kqq5yxmetu
User "Paid!"
Agent → calls check_invoice_status(invoice_id: "inv_...")
Agent "Payment confirmed! 25,000 sats received. Your subscription is now active."
User "Show me all payments this month"
Agent → calls list_payments(from_date: "2024-01-01")
Agent "You received 3 payments totaling 75,000 sats ($75.00) this month."
Give your AI agents the power to create invoices and process Bitcoin payments.