mcp-l402-gate-example
mcp-l402-gate-example
一个极简的 MCP 服务器,展示了 @powforge/mcp-l402-gate 的实际应用。
该服务器提供一个工具 bitcoin_data,用于从 mempool.space 获取当前的 BTC/USD 价格以及推荐的内存池费用。每次调用都受到以下门控限制:
L402 闪电网络发票(调用者按次支付 sats)。
针对公共 PowForge 预言机的身份深度(DoI)评分查询。如果低于阈值,即使付费也无法通过。
L402 本身证明了调用者已付费。L402 + DoI 证明了他们不仅付费,而且拥有一个跨会话持续存在且伪造需要不可逆工作量的公钥声誉。后半部分是大多数 MCP 计费套件所忽略的。
快速开始
git clone https://github.com/zekebuilds-lab/mcp-l402-gate-example
cd mcp-l402-gate-example
cp .env.example .env # fill in GATE_HMAC_SECRET and LNBits creds
npm install
npm start服务器在启动时会记录工具 URL 和预言机地址。默认端口为 3100。
Related MCP server: l402-kit-mcp
使用 curl 进行测试
首次调用没有认证,因此门控返回 402 状态码和发票:
curl -i -X POST http://localhost:3100/tools/bitcoin_data \
-H 'Content-Type: application/json' \
-H 'X-Caller-Pubkey: 02a1b2c3...your-hex-pubkey' \
-d '{}'预期响应:
HTTP/1.1 402 Payment Required
WWW-Authenticate: L402 macaroon="...", invoice="lnbc1..."
Content-Type: application/json
{
"error": "payment required",
"macaroon": "...",
"invoice": "lnbc1...",
"payment_hash": "..."
}支付 invoice 字段(使用任何闪电网络钱包),获取原像(preimage),然后重试:
curl -i -X POST http://localhost:3100/tools/bitcoin_data \
-H 'Content-Type: application/json' \
-H 'X-Caller-Pubkey: 02a1b2c3...your-hex-pubkey' \
-H 'Authorization: L402 <macaroon>:<preimage>' \
-d '{}'你将获得 BTC 价格、内存池费用估算以及调用者的 DoI 评分。
对于检查工具目录的 MCP 客户端,清单也会被暴露:
curl http://localhost:3100/manifest.json配置
变量 | 描述 | 必需 | 默认值 |
| 用于签署 L402 宏(macaroons)的 HMAC 密钥。使用 | 是 | - |
| 你的 LNBits 实例基础 URL。 | 是 | - |
| LNBits 发票/读取密钥。切勿使用管理员密钥。 | 是 | - |
| DoI 预言机基础 URL。 | 否 |
|
| HTTP 端口。 | 否 |
|
| 每次调用收取的 sats 金额。 | 否 |
|
| 通过门控所需的最低 DoI 综合评分。 | 否 |
|
DoI 评分阈值
这些与预言机返回的 rank 分桶相同。请根据错误调用所带来的代价选择合适的阈值:
| 等级 | 适用场景 |
0 | unknown | 纯付费墙。身份不重要。 |
10 | emerging | 首次调用滥用会造成损害。大多数公共 MCP 工具的合理默认值。 |
40 | active | 该工具会消耗实际 GPU 或具有昂贵的副作用。 |
100 | established | 合规敏感或单租户 SaaS 风格的端点。 |
200 | trusted | 高信任度管理工具。 |
门控工作原理
如果没有门控,402 + 宏流程仅证明调用者支付了 10 sats。一个新的攻击者钱包支付同样的 10 sats 即可通过。这只是格式上的合规,对滥用的控制较弱。
@powforge/mcp-l402-gate 保留了 L402 发票并增加了第二项检查:当宏验证通过时,门控会为调用者的公钥调用 DoI 预言机,获取 Schnorr 签名的评分,并将其与 MIN_SCORE 进行比较。该评分由四个维度(社交、访问、担保、经济)上可观察的不可逆工作量组成,因此一个新的女巫攻击者无法在短时间内刷出高分。
完整的故障模式表位于 @powforge/mcp-l402-gate README。
文件
server.js- MCP 服务器,约 110 行代码。.env.example- 复制到.env并填写。package.json- 依赖于express和@powforge/mcp-l402-gate。
链接
文档与定价: powforge.dev/mcp
公共 DoI 预言机: identity.powforge.dev
许可证
MIT。
This server cannot be deployed
Maintenance
Related MCP Connectors
Pay-per-action access to APIs and MCP tools over Lightning L402 and Base USDC x402.
Monetize any MCP server: x402 paywall, pay-per-call billing in USDC on Base, agent marketplace.
Programmatic web-scraping MCP server powered by x402 micro-transactions on Base.
MCP server for Boson Protocol — on-chain agentic commerce for physical & digital goods.
Related MCP Servers
- AlicenseAqualityCmaintenanceMCP 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
- AlicenseAqualityBmaintenanceMCP server for l402-kit — enables AI agents (Claude, Cursor, etc.) to autonomously pay Bitcoin Lightning-protected APIs. Tools: l402_fetch, l402_balance, l402_spending_report. Run with: npx l402-kit-mcp486 npm4MIT
- AlicenseAqualityCmaintenanceMCP server that gates API calls to AI agents using proof-of-work (free) or Lightning payment (3 sats), providing challenge, verify, and status tools for per-call authentication without accounts.358 npm1MIT
- AlicenseBqualityDmaintenanceMCP server offering 26 Lightning-paid tools for Bitcoin mempool intelligence and sovereign on-prem AI inference, with no third-party APIs and pay-per-call in sats.2611 npm1MIT