AI agents are getting good at doing things. They write code, research topics, call APIs, orchestrate workflows. But the moment a service costs money, your agent hits a wall. It can't enter credit card details. It can't authenticate with OAuth to process a payment. Subscription API keys don't scale to agent-to-agent transactions where neither party is a human.
This is the missing piece in agentic infrastructure: agents need a way to pay for things programmatically, in real time, without human intervention at the moment of purchase.
I built an MCP server Bitcoin wallet to solve this. It gives any AI agent a Lightning Network wallet, so it can send and receive real Bitcoin payments as naturally as it calls any other tool.
What is MCP and Why Does It Matter Here?
MCP -- Model Context Protocol -- is an open standard created by Anthropic for giving AI models access to external tools. Instead of hardcoding API calls into prompts, you expose capabilities as MCP tools that the model can invoke when it decides they're useful. Claude Code, Cursor, Windsurf, and a growing number of agent frameworks support MCP natively.
An MCP server is just a process that exposes tools over a standard protocol. Your agent discovers what tools are available, understands their parameters from the schema, and calls them when needed. No special prompting required.
An MCP server Bitcoin wallet, then, is exactly what it sounds like: an MCP server that exposes Bitcoin payment tools. Your agent gets tools like check_balance, pay_invoice, pay_l402_api, and create_invoice. It can check how much money it has, pay for things, and receive payments -- all through the same tool interface it uses for everything else.
The Lightning Wallet MCP Package
The package is called lightning-wallet-mcp, available on npm. It works two ways: as an MCP server for Claude Code, Cursor, and other MCP-native clients, and as a CLI tool (the lw command) for any agent framework with shell access.
Installation is one line:
npm install -g lightning-wallet-mcp
For MCP-native clients, you configure it in your settings file. Here's the Claude Code configuration for ~/.claude/settings.json:
{
"mcpServers": {
"lightning-wallet": {
"command": "npx",
"args": ["lightning-wallet-mcp"],
"env": {
"LIGHTNING_WALLET_API_KEY": "your-api-key-here"
}
}
}
}
The same configuration pattern works for Cursor, Windsurf, and other MCP clients. You can also skip the API key in the config entirely and ask the agent to register a new account -- it has a register_operator tool that handles the whole flow.
For CLI-first agents like OpenClaw or anything with Bash access, you use the lw command directly. Set LIGHTNING_WALLET_API_KEY as an environment variable and call lw balance, lw pay-api, lw pay, etc. All output is JSON, designed to be piped to jq.
The Operator/Agent Model
The wallet uses an operator/agent hierarchy, and this is one of the key design decisions that makes it practical for production use.
Think of it like corporate cards. You, the human operator, register an account and deposit Bitcoin via Lightning. You're the one with the master key and the recovery code. Then you create agents under your account. Each agent gets its own API key, its own balance, and -- critically -- its own spending limit.
Here's the workflow:
1. Register as an operator (you get an API key and recovery code)
2. Deposit sats to your operator account by paying a Lightning invoice
3. Create one or more agents, each with an optional budget cap
4. Fund agents by transferring sats from your operator balance
5. Give each agent its API key -- that's all it needs to start transacting
The operator can see every transaction across all agents, adjust budgets in real time, sweep funds back, deactivate agents that go rogue, or delete them entirely. Remaining balance always returns to the operator.
This matters because you never want an AI agent to have unconstrained access to money. Budget limits are your circuit breaker. If you set an agent's budget to 5,000 sats, it literally cannot spend more than that. The platform enforces it.
What the Agent Can Actually Do
Once configured, your agent has access to 37 tools. The most important ones:
check_balance -- See current balance in satoshis.
pay_l402_api -- The big one. Make a request to any URL. If the server returns HTTP 402 (Payment Required) with L402 or X402 headers, the wallet automatically pays the invoice and retries the request with proof of payment. Your agent gets the response data. It supports both L402 (Lightning payments) and X402 (USDC on Base) protocols, with automatic detection.
pay_invoice -- Pay any BOLT11 Lightning invoice directly. Useful for tipping, purchasing services, or settling debts between agents.
create_invoice -- Generate a Lightning invoice so the agent can receive payments. Any Lightning wallet in the world can pay it.
keysend -- Send sats directly to a Lightning node by its public key, no invoice needed. Good for donations, streaming payments, or paying nodes that accept spontaneous payments.
pay_lightning_address -- Send sats to a Lightning address like user@domain.com. This is how agents pay humans (or other agents) who have Lightning addresses.
get_transactions -- Full transaction history with amounts, fees, timestamps, and running balance.
There are also tools for webhook management (get notified when payments arrive), budget status checks, invoice decoding (inspect an invoice before paying it), and LNURL-auth (authenticate to services using Lightning identity).
L402: The Protocol That Makes This Work
The L402 protocol is what turns the internet into a payable API layer. It works like this:
1. Your agent makes a GET request to an API endpoint
2. The server returns HTTP 402 Payment Required, along with a Lightning invoice in the headers
3. Your agent's MCP wallet pays the invoice (milliseconds on Lightning)
4. The agent retries the request with proof of payment
5. The server returns the actual data
From the agent's perspective, it just called pay_l402_api with a URL and got back data. The payment happened automatically, within the budget the operator set. No API keys to manage, no subscriptions to track, no billing accounts to reconcile.
This is what makes the MCP server Bitcoin wallet fundamentally different from giving an agent a Stripe key or a credit card number. L402 is per-request, trustless, and instant. The agent pays exactly for what it uses, nothing more.
The wallet also supports X402, Coinbase's protocol that uses USDC on Base. If an API only supports X402, the wallet handles the USDC payment automatically. Your agent still thinks in sats -- the conversion happens on the platform side. Both protocols are detected from the 402 response headers without any agent-side configuration.
Real Use Cases
Here are scenarios where this MCP server Bitcoin wallet is already being used or is immediately applicable:
Research agents that pay for premium data. An agent that needs real-time market data, academic papers behind paywalls, or premium API access can pay per-request instead of requiring a human to set up subscriptions in advance. The agent decides when the data is worth paying for.
Coding assistants buying compute. An agent that needs to run tests in the cloud, spin up a sandbox environment, or compile a project can pay for compute on demand. No pre-provisioned resources, no idle capacity charges.
Content agents purchasing assets. Stock photos, licensed datasets, translations -- any digital good that can be delivered via API becomes accessible to agents with a wallet.
Agent-to-agent commerce. Two AI agents can transact directly. One creates an invoice, the other pays it. No human intermediary, no payment processor taking a cut beyond routing fees. This is where things get interesting for multi-agent systems.
We actually ran an experiment with 16 AI agents (8 Claude, 8 GPT-4o) using real Bitcoin on Lightning to test exactly this. Over 100 rounds, they completed 2,839 real transactions -- trading, forming alliances, investing. The results are public at github.com/pfergi42/lf-game-theory.
Pricing and Fees
Transparency matters, so here's the fee structure: Lightning Faucet charges a 2% platform fee (minimum 1 sat) on outgoing payments. That covers L402 payments, invoice payments, keysend, withdrawals, and cross-operator transfers. Lightning routing fees are additional and vary by route.
Deposits are free. Receiving payments is free. Transfers between agents under the same operator are free. Webhooks are free.
Every payment response includes platform_fee_sats, routing_fee_sats, and total_cost, so there are no surprises.
Getting Started
Three links to get going:
1. Register an operator account at https://lightningfaucet.com/ai-agents/ -- this is where you get your API key and manage agents.
2. Browse the L402 API Registry at https://lightningfaucet.com/l402-registry/ -- a directory of APIs your agent can pay for, including demo endpoints for testing.
3. Install the npm package: npm install -g lightning-wallet-mcp -- gives you both the MCP server and the lw CLI.
The demo L402 endpoints on Lightning Faucet (fortune, joke, quote) cost 10-50 sats each and are a good way to verify your setup is working before pointing your agent at production APIs.
If you're building an API and want to accept Lightning payments, the L402 protocol is straightforward to implement on the server side -- and every agent running this MCP server becomes a potential customer automatically.
The source is MIT licensed. The MCP server itself, the protocol, and the agent wallet infrastructure are all designed to be open and composable. Agents need money. This is how they get it.