l402-kit-mcp
l402-kit
Füge jeder API Bitcoin Lightning Pay-per-Call hinzu. 3 Zeilen Code.
▶ End-to-End-Demo ansehen — installieren → 402 → bezahlen → 200 OK
Live-Traktion
SDK | Version | Downloads |
📦 TypeScript · npmjs.com/package/l402-kit | ||
🐍 Python · pypi.org/project/l402kit | ||
🦀 Rust · crates.io/crates/l402kit | ||
🔌 VS Code Extension · marketplace | ||
🦫 Go · pkg.go.dev |
🇺🇸 Charge for your API in Bitcoin Lightning. 3 lines of code. 🇧🇷 Monetize sua API com Bitcoin Lightning. 3 linhas de código. 🇪🇸 Monetiza tu API con Bitcoin Lightning. 3 líneas de código. 🇨🇳 用 3 行代码,通过比特币闪电网络收费。 🇮🇳 अपने API को Bitcoin Lightning से 3 लाइनों में मोनेटाइज़ करें। 🇸🇦 اكسب من API الخاص بك عبر Bitcoin Lightning. 3 أسطر فقط. 🇫🇷 Monétisez votre API en Bitcoin Lightning. 3 lignes de code. 🇩🇪 Monetarisiere deine API mit Bitcoin Lightning. 3 Zeilen Code. 🇷🇺 Монетизируй свой API через Bitcoin Lightning. 3 строки кода. 🇯🇵 Bitcoin LightningでAPIを3行で収益化。 🇮🇹 Monetizza la tua API con Bitcoin Lightning. 3 righe di codice.
📖 Offizielle Dokumentation: 🇺🇸 · 🇧🇷 · 🇪🇸 · 🇨🇳 · 🇮🇳 · 🇸🇦 · 🇫🇷 · 🇩🇪 · 🇷🇺 · 🇯🇵 · 🇮🇹
Installation
npm install l402-kit # TypeScript / Node.js / Express
pip install l402kit # Python / FastAPI / Flask
go get github.com/shinydapps/l402-kit/go@v1.8.2 # Go / net/http / Chi / Gin
cargo add l402kit # Rust / axumKI-Agenten / LLMs: Siehe
llms.txtfür maschinenlesbare Anweisungen. Agenten-Discovery:/.well-known/agent.json·/.well-known/l402.json
Related MCP server: Bitcoin-MCP-Server
Für KI-Agenten
l402-kit ist die Zahlungsschicht für autonome Agenten. Agenten können ohne menschliches Eingreifen für APIs bezahlen.
System-Prompt-Schnipsel — füge dies jedem Agenten hinzu, um L402-Zahlungen zu ermöglichen:
You have access to paid APIs via the L402 protocol.
When you call an API that returns HTTP 402, use the L402Client from l402-kit
to pay automatically with Bitcoin Lightning.
Budget limit: {BUDGET_SATS} sats per session. Never exceed this limit.Agent SDK Schnellstart:
import { l402Client, buildWallet } from "l402-kit/agent";
const client = l402Client({
wallet: buildWallet(process.env), // auto-detects BLINK_API_KEY or ALBY_TOKEN
budgetSats: 1000,
});
const data = await client.fetch("https://api.example.com/paid-endpoint");MCP-Server (für Claude Desktop, Cursor und jeden MCP-kompatiblen Agenten):
{
"mcpServers": {
"l402-kit": {
"command": "npx",
"args": ["l402-kit-mcp"],
"env": { "BLINK_API_KEY": "your-key" }
}
}
}Kompatibel mit: LangChain · OpenAI Agents · CrewAI · Vercel AI SDK · AutoGPT · Jedem MCP-Client
Protokoll-Unterstützung: L402 (Bitcoin Lightning) · x402 (USDC/Coinbase) kompatibel
Funktionsweise
1. Client calls your API
↓
2. API returns HTTP 402 + BOLT11 invoice + macaroon
↓
3. Client pays (any Lightning wallet, < 1 second, any country)
↓
4. Client sends Authorization: L402 <macaroon>:<preimage>
↓
5. API verifies SHA256(preimage) == paymentHash ✓
↓
6. HTTP 200 OK + your data
── Fee flow (managed mode) ─────────────────────────────────
Payment → 99.7% → your Lightning Address (instant)
→ 0.3% → ShinyDappsSchnellstart
TypeScript
import express from "express";
import { l402, AlbyProvider } from "l402-kit";
const app = express();
const lightning = new AlbyProvider(process.env.ALBY_TOKEN!);
app.get("/premium", l402({ priceSats: 100, lightning }), (_req, res) => {
res.json({ data: "Payment confirmed." });
});
app.listen(3000);Python
from fastapi import FastAPI, Request
from l402kit import l402_required
app = FastAPI()
@app.get("/premium")
@l402_required(price_sats=100, owner_lightning_address="you@yourdomain.com")
async def premium(request: Request):
return {"data": "Payment confirmed."}Go
package main
import (
"fmt"
"net/http"
l402kit "github.com/shinydapps/l402-kit/go"
)
func main() {
http.Handle("/premium", l402kit.Middleware(l402kit.Options{
PriceSats: 100,
OwnerLightningAddress: "you@yourdomain.com",
}, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, `{"data": "Payment confirmed."}`)
})))
http.ListenAndServe(":8080", nil)
}Rust
use axum::{middleware, routing::get, Router};
use l402kit::{l402_middleware, Options};
use std::sync::Arc;
#[tokio::main]
async fn main() {
let opts = Arc::new(Options::new(100).with_address("you@yourdomain.com"));
let app = Router::new()
.route("/premium", get(|| async { "Payment confirmed." }))
.route_layer(middleware::from_fn_with_state(opts, l402_middleware));
let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await.unwrap();
axum::serve(listener, app).await.unwrap();
}Live testen
# Step 1 — triggers 402 + returns invoice
curl http://localhost:3000/premium
# ← { "error": "Payment Required", "invoice": "lnbc1u...", "macaroon": "eyJ..." }
# Step 2 — pay the invoice with any Lightning wallet, then:
curl http://localhost:3000/premium \
-H "Authorization: L402 <macaroon>:<preimage>"
# ← { "data": "Payment confirmed." }▶ Interaktive Demo ausprobieren
Warum nicht Stripe?
Stripe | l402-kit | |
Mindestgebühr | $0.30 | < 1 sat (~$0.001) |
Abwicklungszeit | 2–7 Tage | < 1 Sekunde |
Rückbuchungen | Ja | Unmöglich — kryptografischer Nachweis |
Erfordert Konto | Ja | Nein — jedes Lightning-Wallet |
KI-Agenten-Support | Nein | Ja — 4 SDKs, nativ |
Blockierte Länder | ~50 | 0 — standardmäßig global |
Umkehrbar | Ja | Nein — endgültig bei Erhalt |
Open Source | Nein | Ja — MIT |
Anbieter
import { BlinkProvider, OpenNodeProvider, LNbitsProvider } from "l402-kit";
// Blink (recommended — free, instant setup)
const provider = new BlinkProvider(process.env.BLINK_API_KEY!, process.env.BLINK_WALLET_ID!);
// OpenNode (production, custodial)
const provider = new OpenNodeProvider(process.env.OPENNODE_KEY!);
// LNbits (self-hosted)
const provider = new LNbitsProvider(process.env.LNBITS_KEY!, "https://your.lnbits.host");Bring deinen eigenen Node mit — implementiere das LightningProvider-Interface in 5 Zeilen:
import type { LightningProvider } from "l402-kit";
class MyNode implements LightningProvider {
async createInvoice(amountSats: number) { /* return Invoice */ }
async checkPayment(paymentHash: string) { /* return boolean */ }
}Sicherheitsmodell
Invoice creation: paymentHash = SHA256(preimage)
Client payment: Lightning Network releases preimage to payer
API verification: SHA256(preimage) == paymentHash ✓
Replay protection: each preimage is marked used — works exactly once
Token expiry: macaroons expire after 1 hourNicht fälschbar — SHA256 ist eine Einwegfunktion; ein Preimage kann nicht gefälscht werden
Keine Rückbuchungen — kryptografische Abwicklung, keine umkehrbare Kartenautorisierung
Replay-sicher — MemoryReplayAdapter (Entwicklung) oder RedisReplayAdapter (Produktion, Multi-Instanz)
600+ automatisierte Tests über 5 Runtimes (TS, Python, Go, Rust, Cloudflare Workers) — produktionsreife Zuverlässigkeit für autonome Agenten-Workflows
Vollständig prüfbar — MIT, jede Zeile ist Open Source
VS Code Extension
Überwache jeden Sat in Echtzeit, ohne deinen Editor zu verlassen.
⚡ Live-Zahlungs-Feed pro Endpunkt
📊 Balkendiagramm — 1T / 7T (kostenlos) · 30T / 1J / ALLE (Pro)
🌍 11 Sprachen integriert
🎨 Hell / Dunkel / Auto-Design
🔧 Keine Konfiguration — einfach deine Lightning-Adresse festlegen
Lightning-Adresse erhalten (kostenlos)
Registriere dich unter dashboard.blink.sv — kostenlos, keine Kreditkarte, sofort einsatzbereit.
Deine Adresse: deinname@deinedomain.com
Andere Wallets: Wallet of Satoshi · Phoenix · Zeus · Alby
Links
Ressource | URL |
📖 Doku (11 Sprachen) | |
📦 npm | |
🐍 PyPI | |
🦫 Go | |
🦀 Rust | |
🔌 VS Code | |
⚡ Lightning | |
🐙 GitHub |
MIT — frei nutzen, frei bauen.
Bitcoin kennt keine Grenzen.
Entwickelt mit ⚡ von ShinyDapps
Doku · Demo · VS Code · npm
Available Tools
4 toolsl402_balanceCheck Lightning budgetARead-onlyIdempotent
Returns the remaining Bitcoin Lightning budget for this MCP session. Use this before calling l402_fetch to confirm you have enough sats — avoids wasted attempts when budget is exhausted. Returns: ' sats remaining of total (spent: sats)'. Read-only — does not trigger any payment or side effect. Budget is set at server startup via BUDGET_SATS (default: 1000 sats ≈ $0.60); to increase it, restart the MCP server.
Inputs: no named parameters.
l402_fetchFetch L402-protected URLA
Fetch a URL that may require a Bitcoin Lightning payment (L402 protocol). Side effect: deducts sats from the session budget when a payment is required — check l402_balance first if budget is limited. Flow: sends request → if 402 received, pays the Lightning invoice (1 attempt) → retries once with payment proof → returns response body as text. Fails with error if: budget is exhausted, URL is unreachable, or the Lightning payment fails. Do NOT use for regular (non-L402) URLs — use a standard fetch tool instead. Do NOT use if l402_balance shows 0 sats remaining.
Inputs: url (required), method, body, headers.
l402_set_budgetCheck budget statusARead-onlyIdempotent
Returns the session budget cap configured at startup (via BUDGET_SATS env var). Use this to confirm what hard spending limit is in effect — useful at the start of a session before making any API calls. Read-only: this tool CANNOT set or change the budget at runtime. To raise or lower the cap, stop and restart the MCP server with a different BUDGET_SATS value. For remaining balance during a session, use l402_balance instead.
Inputs: no named parameters.
l402_spending_reportLightning spending reportARead-onlyIdempotent
Returns a full audit of all Bitcoin Lightning payments made in this MCP session. Includes: total sats spent, remaining budget, sats spent per domain, and chronological transaction list (timestamp + sats + URL). Use this instead of l402_balance when you need to know which APIs were called and how much each cost, not just the remaining balance. Read-only — does not trigger any payment or side effect. Returns '(none yet)' for domains and transactions if no payments have been made this session.
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 4 tools
Each tool has a clearly distinct purpose: checking remaining budget, fetching with optional payment, viewing the budget cap, and obtaining a spending audit. There is no overlap in functionality.
All tools share the consistent 'l402_' prefix and use snake_case, but the naming pattern varies between noun (balance, spending_report) and verb (fetch, set_budget). This minor inconsistency prevents a perfect score.
With 4 tools, the server is well-scoped for its purpose: managing an L402 payment session. Each tool is essential and none are extraneous.
The tool set covers all core operations for an L402 session: checking budget, fetching with automatic payment, viewing the budget cap, and auditing spending. There are no obvious gaps.
Maintenance
Related MCP Connectors
Pay-per-action access to APIs and MCP tools over Lightning L402 and Base USDC x402.
MCP server for Boson Protocol — on-chain agentic commerce for physical & digital goods.
Monetize any MCP server: x402 paywall, pay-per-call billing in USDC on Base, agent marketplace.
Agent-commerce MCP server for x402/USDC payments and affiliate splits on Base.
Related MCP Servers
AlicenseBqualityBmaintenanceConnects a Bitcoin Lightning wallet to your LLM using Nostr Wallet Connect, enabling payments and interactions with Lightning Network features.1151 npm66TypeScriptApache 2.0- AlicenseAqualityDmaintenanceThe first MCP Server dedicated to Bitcoin ecosystem236MIT
- 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
- AlicenseAqualityBmaintenanceBitcoin-powered AI tools via Lightning Network micropayments (L402). Image generation, text generation, video, music, speech, 3D models, file conversion, and SMS — no signup or API keys required.49209 npm2MIT