local402

local402

A one-command paywall for local servers that enables testing AI agents' payment flows by simulating HTTP 402 Payment Required responses. It proxies requests with valid payment headers to the actual server, making it easy to develop and test x402 client logic without real blockchain transactions.

Category
访问服务器

README

<div align="center">

🔒 local402

One-command local paywall for AI agents

Turn any local server into a payable resource in seconds. Perfect for testing agents that need to pay before they can access your API or MCP tool.

<br />

<!-- Upload your demo clip to assets/demo.gif in this repo, then this renders automatically. --> local402 demo

<br />

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

<br />

npm version license node PRs welcome

Website · npm · Report a bug

</div>


What is this?

local402 drops an x402-style HTTP 402 Payment Required paywall in front of any local HTTP server or MCP tool — with a single command, zero config, and no blockchain.

Requests without payment get a clean 402. Requests that "pay" get proxied straight through to your real server. That's it.

It runs in fully simulated mode by default: no wallets, no gas, no external services, no waiting. Just instant, deterministic 402s you can build and test against locally.

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

💸 Why local402?

Agents are learning to pay for things — API calls, tool invocations, data, compute. The x402 protocol makes HTTP-native payments real. But there's a gap:

How do you test a paying agent without spending real money, standing up a wallet, or wiring a whole payment stack — every single time?

You don't want to deploy a facilitator and fund a testnet wallet just to check that your agent notices a 402 and retries with payment. You want a paywall you can throw up in one command and tear down just as fast.

That's local402.

Without local402 With local402
Stand up a facilitator + wallet + testnet funds npx local402 --target ...
Real transactions on every test run Instant, free, deterministic
Blockchain latency in your test loop 0ms — it's all local
Payment logic tangled into your app One reverse proxy in front of it
Hard to reproduce the "unpaid" path Guaranteed 402 on demand

Use it to:

  • ✅ Test that your AI agent handles 402 and retries with an x-payment header
  • ✅ Demo a "pay-per-call" API or MCP tool without touching a chain
  • ✅ Develop x402 client logic offline, on a plane, in CI
  • ✅ Prototype pricing before committing to real settlement

⚡ Quick Start

You don't even need to install it.

# 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 is now listening on http://localhost:4020 and guarding your server.

# ❌ 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"

Point your agent at http://localhost:4020 instead of your real server, and watch it learn to pay. 🎉


🛠 Usage

local402 --target <url> [options]
Flag Alias Default Description
--target <url> -t (required) The server to protect, e.g. http://localhost:3000
--port <number> -p 4020 Port local402 listens on
--price <string> 0.001 Price advertised in the 402 response
--asset <string> USD Currency / asset label for the price
--simulate true Simulated mode — no blockchain, instant (default)
--no-simulate Reserved for real x402 settlement (coming soon)
--no-color Disable colored console output

The rule

  • No x-payment header → 402 Payment Required (with a helpful JSON body + headers).
  • Has x-payment: simulated (or paid) → request is proxied to --target, and the real response comes back untouched.

In simulated mode, any non-empty x-payment value is accepted — simulated and paid are just the canonical ones.

Examples

# 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

🔍 How it works

local402 is a tiny reverse proxy with one opinion: pay first, then pass through.

                        ┌──────────────────────────────┐
                        │           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                    │
                        └──────────────────────────────┘

The unpaid 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"
}

Response headers on a 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

On a paid request, local402 attaches a simulated settlement receipt so your client can verify the flow end-to-end:

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

🗺 Roadmap

local402 starts simple on purpose. The plan:

  • [x] v0.1 — Simulated mode. Instant, local, blockchain-free 402 paywall. (you are here)
  • [ ] v0.2 — Real x402 settlement. Verify actual X-PAYMENT payloads via a pluggable facilitator.
  • [ ] v0.3 — MCP-native mode. First-class paywalling for MCP tools/resources, not just HTTP.
  • [ ] v0.4 — Per-route pricing. Different prices for different paths and methods.
  • [ ] v0.5 — Usage dashboard. Live TUI of requests, payments, and revenue.

Want to shape it? Open an issue.


🤝 Contributing

Contributions, ideas, and bug reports are all welcome — this is meant to be a friendly little tool.

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 it 🍴
  2. Create a branch (git checkout -b feat/amazing-thing)
  3. Commit your changes (git commit -m 'feat: amazing thing')
  4. Push and open a PR

No contribution is too small — even a typo fix helps.


📄 License

MIT © the local402 contributors. Do whatever you want with it.


<div align="center">

⭐ Star the repo if this is useful

If local402 saved you from standing up a payment stack just to test an agent, drop a star — it genuinely helps other people find it.

⭐ Star local402 on GitHub

<br />

Built for the agents that pay their way. 🔒

</div>

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选