Skip to main content
Glama

🔒 local402

一键为 AI 智能体设置本地支付墙

几秒钟内将任何本地服务器转变为可付费资源。 非常适合测试那些需要先付费才能访问你的 API 或 MCP 工具的智能体。

npx local402 --target http://localhost:3000 --price 0.001

npm version license node PRs welcome


这是什么?

local402任何本地 HTTP 服务器或 MCP 工具前放置一个 x402 风格的 HTTP 402 Payment Required 支付墙——只需一条命令,零配置,无需区块链。

未支付的请求会返回一个干净的 402。已“支付”的请求会直接代理到你的真实服务器。仅此而已。

默认情况下,它运行在完全模拟模式:无需钱包、无需燃料费、无需外部服务、无需等待。只需即时、确定性的 402,你可以本地构建和测试。

agent ──▶  local402 (402 paywall)  ──▶  your server
             │
             └── no payment? → 402 Payment Required
                 paid?       → proxied response ✅

Related MCP server: 402-mcp

💸 为什么需要 local402?

智能体正在学会为事物付费——API 调用、工具调用、数据、计算。x402 协议让 HTTP 原生支付成为现实。但存在一个差距:

如何在不花真钱、不部署钱包、不每次搭建完整支付栈的情况下测试一个会付费的智能体?

你不想仅仅为了检查智能体是否注意到 402 并携带支付重试而部署一个 Facilitator 并为一个测试网钱包充值。你想要的是一条命令就能搭建、同样快速拆除的支付墙。

这就是 local402

没有 local402

有了 local402

搭建 Facilitator + 钱包 + 测试网资金

npx local402 --target ...

每次测试运行都发起真实交易

即时、免费、确定性

测试循环中带有区块链延迟

0毫秒——完全本地

支付逻辑与你的应用纠缠在一起

一个放在应用前面的反向代理

难以重现“未支付”路径

按需保证 402

用它来:

  • ✅ 测试你的 AI 智能体是否处理 402 并携带 x-payment 头部重试

  • ✅ 演示“按调用付费”的 API 或 MCP 工具,而无需接触区块链

  • ✅ 离线、在飞机上、在 CI 中开发 x402 客户端逻辑

  • ✅ 在承诺真实结算之前原型设计定价


⚡ 快速开始

你甚至不需要安装它。

# 1. Have any local server running (your API, MCP tool, whatever)
#    e.g. something on http://localhost:3000

# 2. Put a paywall in front of it
npx local402 --target http://localhost:3000 --price 0.001

local402 正在监听 http://localhost:4020 并保护你的服务器。

# ❌ No payment → 402 Payment Required
curl -i http://localhost:4020/

# ✅ "Pay" → request is proxied to your real server
curl -i http://localhost:4020/ -H "x-payment: simulated"

将你的智能体指向 http://localhost:4020 而不是你的真实服务器,然后看着它学会支付。🎉


🛠 用法

local402 --target <url> [options]

标志

别名

默认值

描述

--target <url>

-t

(必需)

要保护的服务器,例如 http://localhost:3000

--port <number>

-p

4020

local402 监听的端口

--price <string>

0.001

402 响应中广告的价格

--asset <string>

USD

价格的货币/资产标签

--simulate

true

模拟模式——无需区块链,即时(默认)

--no-simulate

保留用于真实 x402 结算 (即将推出)

--no-color

禁用彩色控制台输出

规则

  • 没有 x-payment 头部402 Payment Required(带有 JSON 主体和头部)。

  • x-payment: simulated (或 paid) → 请求被代理到 --target,真实响应原样返回。

在模拟模式下,任何非空的 x-payment 值都被接受——simulatedpaid 只是标准值。

示例

# Guard an MCP tool on a custom port, charge 0.01
local402 --target http://localhost:8787 --port 9000 --price 0.01

# Free status check — always open, never paywalled
curl http://localhost:4020/__local402

🔍 工作原理

local402 是一个微小的反向代理,只有一个观点:先付费,再通过。

                        ┌──────────────────────────────┐
                        │           local402            │
                        │        :4020 (paywall)        │
   ┌─────────┐          │                               │          ┌──────────────┐
   │  agent  │ ───────▶ │  x-payment header present?    │          │ your server  │
   │ / curl  │          │                               │          │  :3000       │
   └─────────┘          │   NO  ─▶ 402 Payment Required │          └──────────────┘
        ▲               │                               │                 ▲
        │               │   YES ─▶ proxy the request  ──┼─────────────────┘
        │               │         return real response  │                 │
        └───────────────┤◀──────────────────────────────┼─────────────────┘
              402 or proxied response                    │
                        └──────────────────────────────┘

未支付响应 (HTTP 402):

{
  "x402Version": 1,
  "error": "Payment Required",
  "message": "This resource costs 0.001 USD. Retry with header 'x-payment: simulated'.",
  "accepts": [
    {
      "scheme": "simulated",
      "network": "local",
      "maxAmountRequired": "0.001",
      "asset": "USD",
      "payTo": "local402-simulated",
      "resource": "/",
      "description": "local402 simulated paywall",
      "mimeType": "application/json"
    }
  ],
  "hint": "x-payment: simulated"
}

402 响应头部:

HTTP/1.1 402 Payment Required
x-payment-required: true
x-payment-amount: 0.001
x-payment-asset: USD
x-payment-network: local
accept-payment: x-payment: simulated

已支付请求上,local402 会附加一个模拟的结算收据,以便你的客户端可以端到端验证流程:

x-payment-response: <base64 JSON receipt with a sim txHash>

🗺 路线图

local402 最初设计得很简单。计划如下:

  • v0.1 — 模拟模式。 即时、本地、无区块链的 402 支付墙。(你在这里)

  • v0.2 — 真实 x402 结算。 通过可插拔的 Facilitator 验证真实的 X-PAYMENT 载荷。

  • v0.3 — MCP 原生模式。 为 MCP 工具/资源提供头等支付墙,而不仅是 HTTP。

  • v0.4 — 按路由定价。 不同路径和方法的不同价格。

  • v0.5 — 使用仪表板。 请求、支付和收入的实时 TUI。

想要塑造它?提交一个问题。


🤝 贡献

欢迎所有贡献、想法和错误报告——这是一个友好的小工具。

git clone https://github.com/wushu75/local402.git
cd local402
npm install
npm run dev -- --target http://localhost:3000   # run from source
npm run build                                    # compile to dist/
  1. Fork 它 🍴

  2. 创建一个分支 (git checkout -b feat/amazing-thing)

  3. 提交你的更改 (git commit -m 'feat: amazing thing')

  4. 推送并打开一个 PR

没有太小的贡献——即使是一个拼写错误修复也有帮助。 n *** n

📄 许可证

MIT © local402 贡献者。你想怎么用都行。


⭐ 如果这个工具有用,请给仓库点个星

如果 local402 让你免于为了测试一个智能体而搭建支付栈,点个星吧——它真的能帮助其他人发现它。 n **⭐ 在 GitHub 上给 local402 点星 n n 为那些自费前行的智能体而生。 🔒 n

A
license - permissive license
-
quality - not tested
B
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    -
    quality
    D
    maintenance
    Ag402 is the payment layer for Coinbase's x402 protocol. Wrap any API or MCP server with a paywall in one command (ag402 serve), or let your AI agent auto-pay for paid APIs (ag402 run). Zero code changes for both buyers and sellers. Solana USDC, ~0.5s settlement, non-custodial, 648+ tests, MIT licensed. Works with Claude Code, Cursor, OpenClaw, LangChain, AutoGen, CrewAI out of the box.
    9
    MIT
  • A
    license
    -
    quality
    A
    maintenance
    L402 + x402 client MCP. AI agents discover, pay for, and consume any payment-gated API autonomously. Supports Lightning (NWC), Cashu ecash, stablecoins, and human-in-the-loop payments.
    371
    MIT

View all related MCP servers

Related MCP Connectors

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/wushu75/local402'

If you have feedback or need assistance with the MCP directory API, please join our Discord server