L402 Gateway
Enables Bitcoin micropayments via the Lightning Network, allowing websites to implement paywalls and accept payments for digital services through the L402 Gateway.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@L402 Gateway Register my agent and check for available text analysis services"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
L402 Gateway ⚡
Multi-tenant L402 (Lightning HTTP 402) paywall-as-a-service. Add Bitcoin micropayments to any website in minutes. No Lightning node required.
Architecture
Runtime: Cloudflare Worker (TypeScript)
Database: Cloudflare D1 (SQLite)
Lightning: LNbits (external, via env secrets)
Auth: LNURL-auth (wallet login) + email signup
Revenue: Fee-on-creation (configurable %, default 2%)
Related MCP server: Lightning Enable MCP
Setup
Prerequisites
An LNbits instance with admin API key
Node.js 18+
1. Install dependencies
npm install2. Create D1 database
wrangler d1 create l402-gateway
# Update database_id in wrangler.toml with the returned ID3. Run migrations
wrangler d1 execute l402-gateway --file=schema.sql
wrangler d1 execute l402-gateway --file=migrations/002-api-key-hash.sql
wrangler d1 execute l402-gateway --file=migrations/003-email-verification.sql
wrangler d1 execute l402-gateway --file=migrations/004-lnurl-auth.sql
wrangler d1 execute l402-gateway --file=migrations/005-security-fixes.sql
wrangler d1 execute l402-gateway --file=migrations/006-resources.sql4. Set secrets
wrangler secret put LNBITS_URL # LNbits instance URL
wrangler secret put LNBITS_ADMIN_KEY # LNbits admin API key
wrangler secret put GATEWAY_ADMIN_TOKEN # Admin auth token
wrangler secret put MACAROON_SECRET # HMAC key for macaroon signing
wrangler secret put ENCRYPTION_KEY # AES-256-GCM key for tenant secrets5. Deploy
wrangler deployAPI Overview
Endpoint | Method | Auth | Description |
| GET | — | Health check |
| GET | — | LNURL-auth challenge |
| POST | — | Public self-service signup |
| POST | Admin | Create tenant (admin) |
| GET | Tenant | Get tenant info |
| POST | Tenant | Create L402 invoice |
| GET | L402 | Verify L402 token |
| GET | Tenant | Check payment status |
| GET | Tenant | List payments |
| GET | Tenant | Payment statistics |
| GET | Tenant | Wallet balance |
| POST | Tenant | LNURL-withdraw |
| POST/GET | Tenant | Manage resources |
| POST | Tenant | MCP Remote Server (JSON-RPC 2.0) |
Use with AI Agents — MCP Remote Server
L402 Gateway implements the Model Context Protocol (MCP) for seamless AI agent integration.
What is MCP?
MCP is a standardized protocol for AI models (Claude, etc.) to access external tools and data sources safely. The L402 Gateway exposes all payment and contract operations as MCP tools.
Available Tools (16 total)
Agent Registration:
l402_register— Create new agent account instantly
Wallet:
l402_balance— Check balancel402_deposit— Create deposit invoicel402_check_deposit— Check deposit statusl402_withdraw— Create withdrawal
Service Offers:
l402_create_offer— List a servicel402_list_offers— Browse servicesl402_get_offer— Get offer details
Contracts & Escrow:
l402_accept_offer— Accept and create contractl402_fund_contract— Fund escrowl402_list_contracts— List your contractsl402_get_contract— Get contract detailsl402_deliver— Submit delivery proofl402_confirm— Confirm & release escrowl402_dispute— Submit dispute
Accounting:
l402_ledger— View balance history
Configure in Claude Desktop
Add to ~/.claude/claude_desktop_config.json:
{
"mcpServers": {
"l402-gateway": {
"command": "npx",
"args": [
"@anthropic-ai/fetch-server",
"https://l402gw.nosaltres2.info/mcp"
],
"env": {
"X_L402_KEY": "l402_sk_your_api_key_here"
}
}
}
}Then restart Claude Desktop. You'll now be able to:
Register agents
Create and accept service offers
Manage payments & deposits
View transaction history
Example Agent Workflow
User: "Register my agent and check if any text analysis services are available"
Claude uses MCP:
1. l402_register → "agent-0xabc123"
2. l402_list_offers → Finds text analysis services
3. l402_get_offer → Gets pricing and terms
4. [Ready to accept and fund contracts]API Endpoint
POST https://l402gw.nosaltres2.info/mcp
Content-Type: application/json
X-L402-Key: l402_sk_...
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "l402_balance",
"arguments": {}
}
}See MCP-ENDPOINT.md for full specification.
Quick Integration (Web Paywalls)
<!-- 1. Register a resource via API -->
<!-- 2. Add the paywall snippet -->
<div data-l402-resource="premium">
<p>Preview text only...</p>
</div>
<script src="https://l402gw.nosaltres2.info/js/l402.js"
data-api-key="l402_sk_..."></script>Docs
Full documentation: l402gw.nosaltres2.info/docs
License
ISC
Available Tools
8 toolsl402_balanceB
Check the configured LNbits wallet balance.
Inputs: no named parameters.
l402_checkA
Probe a URL to see whether it is L402-protected, and report the invoice price and macaroon caveats when present.
Inputs: url (required).
l402_create_resourceC
Create or update a protected resource on the configured L402 gateway.
Inputs: price_sats (required), resource_id (required), description, ttl_seconds, +1 more.
l402_delete_resourceC
Delete a resource from the configured L402 gateway.
Inputs: resource_id (required).
l402_inspectC
Decode an L402 macaroon and show its identifier and caveats.
Inputs: macaroon (required).
l402_list_resourcesB
List resources from the configured L402 gateway.
Inputs: no named parameters.
l402_requestA
Run the full L402 flow: request a URL, detect the 402 challenge, pay the invoice via LNbits, retry with Authorization, and return the unlocked response.
Inputs: url (required), body, method, headers.
l402_statsB
Fetch gateway payment and usage statistics from the configured L402 gateway.
Inputs: no named parameters.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 8 tools
Each tool targets a distinct action (inspect, request, check, create/list/delete resources, stats, balance). There is some conceptual overlap between l402_check (probes URL, reports caveats) and l402_inspect (decodes macaroon) plus l402_request (also detects the 402 challenge), but the descriptions clarify the boundaries well enough for an agent to pick correctly.
All tools share the l402_ prefix and use a predictable verb_noun pattern (l402_create_resource, l402_list_resources, l402_delete_resource). The noun-only tools (l402_stats, l402_balance) are naturally read-only fetches and remain consistent with the scheme.
Eight tools is well-scoped for a gateway server covering resource CRUD, payment flow, macaroon inspection, and wallet/stat queries. Each tool earns its place with no filler.
The surface covers the core L402 lifecycle: resource CRUD (create/update, list, delete), payment flow, macaroon inspection, wallet balance, and stats. Minor gaps exist (no dedicated get-single-resource or standalone invoice-payment/macaroon-issuance tool), but agents can work around these via list and l402_request.
Maintenance
Related MCP Connectors
Give AI agents a Bitcoin wallet with Lightning Network payments and L402 support.
Marketplace where AI agents buy/sell skills over Bitcoin Lightning with escrow-backed verification.
Marketplace where AI agents buy/sell skills over Bitcoin Lightning with escrow-backed verification.
Pay-per-action access to APIs and MCP tools over Lightning L402 and Base USDC x402.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI models to interact with the Lightning Network by providing an MCP-compliant API to pay invoices.6MIT
- AlicenseAqualityBmaintenanceMCP server that enables AI agents to make autonomous Bitcoin Lightning Network payments using the L402 protocol. Agents can pay for API access, purchase resources, and complete transactions without human intervention — invoice comes in, sats go out, done.179MIT
- FlicenseNot gradedqualityBmaintenanceEnables any MCP-compatible LLM client to autonomously hold, spend, earn, and receive cryptocurrency using native MCP tools, no code required.84-
- AlicenseAqualityDmaintenanceMCP server that gives AI agents Lightning payments, L402 API access, trust verification, and service discovery.1113 npmMIT