x402 Universal Payer

io.github.nirholas由 GitHub 帳號 nirholas 發布v1.0.2更新於 Oct 24, 2026

Pay any x402 endpoint on the open web: auto-paying bridge with Bazaar discovery and spend caps.

概覽

AI 產生的概覽

讓助理呼叫 x402 付費網頁端點,在支出上限內自動簽署並結算 EVM 鏈或 Solana 上的 USDC 付款。

可以做什麼
此橋接提供 call_paid_endpoint,可存取任意 URL,若伺服器回應 402 Payment Required 就自動付款,並回傳回應與結算憑證。它也會探索 x402 Bazaar 上列出的服務,為每個資源註冊一個動態工具,並提供 list_bazaar_tools 與 refresh_bazaar 來檢視與重新載入清單。付款支援 EVM exact、EVM 批次結算與 Solana exact 方案,批次通道狀態會跨重新啟動保存。
適用情境
當助理需要以按次付費方式使用 x402 計費的 API 或資料服務,並希望自動付款且具備單次與工作階段限額時使用。對免費端點或不涉及花錢的任務沒有幫助。
執行需求
透過 npx @three-ws/mcp-bridge 以 stdio 在本機執行,需要 Node.js。必須提供 MCP_BRIDGE_EVM_PRIVATE_KEY 或 MCP_BRIDGE_SVM_PRIVATE_KEY 其中之一,並存入 USDC。選用變數可設定上限、允許清單、探索數量、RPC 覆寫與通道儲存。需要連線至目標端點與 Bazaar 的網路。
安裝前請注意
此伺服器持有私鑰並花費真實 USDC,請使用專用的低餘額錢包,因為私鑰等同現金。付費工具被標註為非唯讀且非幂等,重試付費呼叫會產生新費用。上限與允許清單(MCP_BRIDGE_MAX_PRICE_PER_CALL_ATOMIC、MCP_BRIDGE_MAX_TOTAL_ATOMIC、MCP_BRIDGE_ALLOWED_PAYTO、MCP_BRIDGE_ALLOWED_HOSTS)可限制風險,但應刻意設定。對外請求會送往第三方主機,非本機開發時不應開啟 MCP_BRIDGE_ALLOW_HTTP。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 x402 Universal Payer,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

[three.ws]

@three-ws/mcp-bridge

One MCP server that can pay any x402-paid endpoint on the open web — the universal x402 payer for AI agents.

[npm] [downloads] [license] [node] [MCP Registry] [three.ws]

Quick start · Security · Tools · Environment · three.ws


A Model Context Protocol server that can pay any x402-paid endpoint on the open web. Point your agent at a URL that answers 402 Payment Required; the bridge signs, pays, retries, and hands back the response plus the settlement receipt — EVM exact, EVM batch-settlement, and Solana exact, all behind hard spending caps. It also pre-loads a tool per service discovered on the Coinbase x402 Bazaar, so the entire paid-API economy shows up in your tool list.

Quick start

Claude Code:

bash
claude mcp add x402-bridge -e MCP_BRIDGE_SVM_PRIVATE_KEY=... -- npx -y @three-ws/mcp-bridge

Use -e MCP_BRIDGE_EVM_PRIVATE_KEY=0x... instead (or as well) to pay on Base and other EVM chains. At least one key is required.

Claude Desktop (claude_desktop_config.json) or Cursor (~/.cursor/mcp.json):

json
{	"mcpServers": {		"x402-bridge": {			"command": "npx",			"args": ["-y", "@three-ws/mcp-bridge"],			"env": {				"MCP_BRIDGE_EVM_PRIVATE_KEY": "0x…buyer key…",				"MCP_BRIDGE_SVM_PRIVATE_KEY": "…base58 64-byte secret key…",				"MCP_BRIDGE_MAX_PRICE_PER_CALL_ATOMIC": "100000",				"MCP_BRIDGE_DISCOVER_LIMIT": "20"			}		}	}}

Restart the client and ask for something like "pay $0.01 on Base for a weather report" — the model picks a matching Bazaar tool (or call_paid_endpoint), and the bridge auto-pays via x402.

Security and spending controls

This server holds private keys and spends real USDC. Read this section before configuring it.

  • Use a dedicated, low-balance wallet. MCP_BRIDGE_EVM_PRIVATE_KEY / MCP_BRIDGE_SVM_PRIVATE_KEY should never be a main wallet. Fund it with only what you are willing to let an agent spend.
  • Per-call cap. Any payment above MCP_BRIDGE_MAX_PRICE_PER_CALL_ATOMIC (default 100000 = $0.10 USDC) is refused before a payload is signed, with an error naming the network, asset, and cap.
  • Session ceiling. Cumulative spend per process is capped by MCP_BRIDGE_MAX_TOTAL_ATOMIC (default 1000000 = $1.00 USDC). This bounds the damage of a looping or prompt-injected agent: once the ceiling is reached, every further payment aborts until restart. The accumulator reserves atomically, so concurrent calls cannot jointly overshoot it.
  • Payee allowlist. Set MCP_BRIDGE_ALLOWED_PAYTO (comma-separated addresses) to refuse payment to any recipient you have not explicitly trusted.
  • SSRF guard. Every outbound payable URL — whether supplied by the model or by a Bazaar listing — passes one chokepoint that enforces an https-only scheme policy, resolves the hostname, and rejects the request if any resolved address is private, loopback, link-local (including 169.254.169.254 cloud metadata), CGNAT, ULA, or unspecified. Literal-IP hosts are checked directly; redirects are never followed (a public host cannot 3xx the bridge into internal infrastructure). http:// is available only behind the explicit MCP_BRIDGE_ALLOW_HTTP=1 dev opt-in.
  • Host allowlist. Set MCP_BRIDGE_ALLOWED_HOSTS (comma-separated hostnames) for strict mode: only listed hosts can be paid at all.
  • Deposit caps. Batch-settlement channel deposits are bounded by MCP_BRIDGE_MAX_DEPOSIT_ATOMIC (default $5.00) regardless of what a server requests.
  • Honest annotations. Every paying tool is annotated readOnlyHint: false, idempotentHint: false, openWorldHint: true, so MCP hosts apply their strictest confirmation policy. Retrying a paid call is a new charge.

What it exposes

On startup the bridge registers:

ToolWhat it does
call_paid_endpointUniversal fallback: hit any URL, auto-pay if it returns 402. Returns the response + parsed settlement.
list_bazaar_toolsReturns the cached list of Bazaar-discovered tools (name, resource, accepted payment terms). Free.
refresh_bazaarRe-queries the x402 Bazaar and re-registers dynamic tools without restarting. Free.
paid_<derived> …One tool per discovered Bazaar resource (up to MCP_BRIDGE_DISCOVER_LIMIT), with that endpoint's schema.

Tools whose prices all exceed the per-call cap are filtered out at discovery time, so the model never sees a tool it cannot afford.

Tool annotations

Every tool carries MCP ToolAnnotations so hosts can apply the right confirmation policy:

  • call_paid_endpoint and every dynamic paid_* tool: readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true. These spend real USDC — each call settles a payment (capped by MCP_BRIDGE_MAX_PRICE_PER_CALL_ATOMIC), and retrying is a new charge. They never delete or overwrite caller state, hence not destructive.
  • list_bazaar_tools: readOnlyHint: true, idempotentHint: true, openWorldHint: false. Pure in-process cache read; free, no network.
  • refresh_bazaar: readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true. Free (no payment), but it mutates the registered tool set from the live Bazaar feed, so repeat calls can differ.

Tool results that are plain objects are returned as both a JSON text block (backward compatible) and structuredContent for typed clients.

Payment schemes

Payment paths registered on the buyer client:

  • eip155:* → BatchSettlementEvmScheme (preferred when the server advertises it; voucher-based, no per-call gas)
  • eip155:* → ExactEvmScheme (used when the server advertises scheme: "exact")
  • solana:* and the x402 v1 Solana networks (solana, solana-devnet, solana-testnet) → ExactSvmScheme / ExactSvmSchemeV1 (USDC SPL transfer co-signed by the advertised fee payer), registered together by registerExactSvmScheme(). v1 is the wire format most of the open x402 bazaar still speaks; the client always prefers v2 when a seller advertises both. The spending-cap hook reads either amount (v2) or maxAmountRequired (v1) so both are capped the same way.

Batch-settlement channel state is persisted to ~/.x402-mcp-bridge/channels/client/ so client restarts do not re-deposit on the next call.

Environment

VariableRequiredDefaultNotes
MCP_BRIDGE_EVM_PRIVATE_KEYone of EVM/SVM required—0x-prefixed 32-byte hex. Funds USDC payments on Base, Arbitrum, etc.
MCP_BRIDGE_SVM_PRIVATE_KEYone of EVM/SVM required—base58 64-byte secret key (Phantom/solana-keygen format) or 64-int JSON array.
MCP_BRIDGE_MAX_PRICE_PER_CALL_ATOMICno100000 (= $0.10 USDC at 6 decimals)Per-call spending cap. Payment aborts above this with a clear reason.
MCP_BRIDGE_MAX_TOTAL_ATOMICno1000000 (= $1.00 USDC)Cumulative session spending ceiling. Aborts further payments once reached.
MCP_BRIDGE_ALLOWED_PAYTOno— (any payee)Comma-separated payee allowlist. When set, unlisted payTo addresses are refused.
MCP_BRIDGE_ALLOWED_HOSTSno— (any public host)Comma-separated hostname allowlist for outbound paid requests.
MCP_BRIDGE_ALLOW_HTTPno0Set 1 to allow http:// targets. Local development only.
MCP_BRIDGE_DISCOVER_LIMITno20Max number of Bazaar tools to register dynamically. Set 0 to disable discovery.
MCP_BRIDGE_BAZAAR_URLnohttps://api.cdp.coinbase.com/platform/v2/x402/discovery/resourcesOverride to point at a self-hosted or alternative bazaar.
MCP_BRIDGE_BATCH_DEPOSIT_MULTIPLIERno5How many request-amounts to deposit at once when opening a batch channel.
MCP_BRIDGE_MAX_DEPOSIT_ATOMICno5000000 (= $5.00 USDC)Hard cap on the deposit amount per channel open / top-up.
X402_MCP_BRIDGE_CHANNELS_DIRno~/.x402-mcp-bridge/channelsOverride the directory used by FileClientChannelStorage.
RPC_URL_<chainId>noviem default public RPCPer-chain RPC override. Example: RPC_URL_8453=https://mainnet.base.org.

MCP_BRIDGE_* key vars also fall back to EVM_PRIVATE_KEY / SVM_PRIVATE_KEY if you already have those set.

Spending cap behavior

The pre-payment hook inspects the selected accepts entry and aborts payload creation if the amount exceeds the per-call cap, the payee is outside the allowlist, or the session ceiling would be crossed. The tool result then carries a clear error message naming the network, asset, and the limit that was hit — useful for the model to decide whether to ask you to raise it.

Inspecting without a client

bash
MCP_BRIDGE_SVM_PRIVATE_KEY=... npx -y @modelcontextprotocol/inspector npx -y @three-ws/mcp-bridge

The inspector connects over stdio and lists the static tools (call_paid_endpoint, list_bazaar_tools, refresh_bazaar) plus one dynamic tool per discovered Bazaar entry.

Programmatic use

Any Node module can consume an x402 endpoint through the same buyer client:

js
import { buildBuyerAxios } from '@three-ws/mcp-bridge/src/x402-axios-client.js';
const { api } = await buildBuyerAxios();const res = await api.get('https://api.example.com/some-paid-resource');

The same spending caps, SSRF guard, and channel-storage rules apply. Idle batch channels can be refunded out-of-band with the @x402 SDK's client.refund(resourceUrl, { amount }).

Tests

bash
npm test           # hermetic: url-guard SSRF policy, spending-cap hook, tool naming, stdio bootnpm run test:smoke # live: boots against the real Bazaar and asserts the cap blocks a real paid call

The hermetic suite generates throwaway keypairs in-process; no real keys or funds are ever involved.

License

All rights reserved. See LICENSE.

來源:mcp-bridge/README.md,提交 800052e

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v1.0.2最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分