pontage

pontage

Enables MCP tools to be gated behind per-call USDC micropayments with direct on-chain verification and settlement, removing the need for third-party payment facilitators.

Category
访问服务器

README

pontage

<p align="center"> <img src="docs/assets/402-payment-required.png" alt="402 Payment Required" width="400"> </p>

A self-settling x402 payment gateway for MCP tools. Gate any Model Context Protocol tool behind a per-call USDC micropayment — and verify and settle the payment directly against the chain, with no third-party facilitator in the path.

License: MIT  ·  Python 3.12  ·  Base + USDC (EIP-3009)

pontage (n.) — the medieval toll paid to cross a bridge. The agent pays pontage; the gateway takes it straight across to the chain.


Why

AI agents increasingly consume gated tools, APIs, and data with no human in the loop to click "subscribe." x402 revives HTTP 402 as the protocol for this: the server answers 402 Payment Required, the agent signs a stablecoin payment, and the server serves the resource once paid.

The reference x402 deployments (Cloudflare, AWS) delegate payment verification and settlement to a hosted facilitator. pontage collapses that role into the server itself:

   reference x402:   Agent ──▶ Server ──▶ Facilitator ──▶ Blockchain
   pontage:          Agent ──▶ Gateway ─────────────────▶ Blockchain

The buyer signs an EIP-3009 transferWithAuthorization — a gasless authorization that moves USDC directly from the buyer's wallet to the seller's receiving address. The gateway only verifies the signature and broadcasts the authorization. It never custodies buyer funds and never holds spendable revenue. The single key it holds pays gas and holds dust — the entire drainable surface (see Custody model).

Why not just have the agent pay and hand us the txid?

That's the naive design — and it's exactly what the attack harness below exists to break. It looks simple until you actually build it:

  • A txid can be replayed. Nothing stops an agent from handing you a txid from a payment it already redeemed against you (or from a totally different service). Without a server-issued, single-use nonce that you atomically claim, "here's a txid" is just a receipt you have no way to invalidate.
  • A raw transfer isn't bound to what it paid for. A token transfer says "A sent B tokens" — nothing more. It doesn't say which tool call, which arguments, or which price it was authorizing. Without binding the payment to the exact request up front, an agent can pay the cheap price once and swap in a more expensive call before you check.
  • "I sent a txid" isn't "the money moved." The transaction could still be pending, get dropped, get replaced, or fall out of the chain in a reorg. Serving as soon as you see a txid — instead of after on-chain confirmation — means you're trusting the agent's claim, which is the exact trust problem HTTP 402 exists to remove.
  • You need to check it against a live chain anyway. Confirming a payment really landed means an RPC call (or your own node), decoding the receipt, confirmation-depth logic that scales with price, and idempotent handling so a slow confirmation doesn't get double-charged or double-served.
  • The agent still needs to learn the price and address first. Even in the "just send a txid" version, there's an implicit handshake before payment — which is precisely what the 402 challenge formalizes instead of leaving ad hoc.

So the job doesn't go away — mint a challenge, bind it to the request, verify the payment against it, atomically claim it exactly once, wait for on-chain confirmation, then serve. pontage's bet isn't that this job is avoidable; it's that you don't need to hand it to a third-party facilitator to do it correctly. Verification and settlement happen in-process, directly against the chain.

What makes it different

  • No facilitator dependency. Verify + settle happen in-process over plain JSON-RPC. No hosted service, no third-party account, no facilitator economics.
  • A reproducible attack-test harness. The paper Five Attacks on x402 found every audited open-source x402 SDK exploitable. pontage ships each attack class as a runnable test that succeeds against a naive gateway and fails against this one — so you verify the defenses yourself instead of trusting a claim. See tests/attacks/.
  • Payment bound to the exact request. The gateway issues the EIP-3009 nonce and binds it to a specific tool + argument set, closing the request↔payment binding gap that underlies most x402 replay attacks.
  • Clean settlement-adapter interface. The engine depends only on a SettlementAdapter protocol; the Base/USDC EIP-3009 implementation is one swappable module.

Quick start

Requires uv and Python 3.12.

uv sync

# Run the gateway with an in-memory fake chain (no wallet, no network needed).
PONTAGE_CHAIN_MODE=fake \
PONTAGE_PAY_TO_ADDRESS=0x2222222222222222222222222222222222222222 \
uv run python -m pontage

In another terminal, run the example paying agent end-to-end:

uv run python examples/client.py --tool lucky_number --args '{"seed": "pontage"}'
→ calling lucky_number (no payment)
← 402 challenge: $0.001 USDC on base-sepolia to 0x2222…2222
→ paying and re-calling lucky_number
← tool result: { "seed": "pontage", "luckyNumber": 37, ... }
← settlement receipt: { "success": true, "transaction": "0x0f3c…10ed", ... }

The client fetches the 402 challenge, signs the EIP-3009 authorization with the server-issued nonce, and re-calls the tool with the payment in _meta["x402/payment"] — the x402 MCP transport pattern.

Defining a paid tool

from pontage.transport.paid_tool import paid_tool

@paid_tool(mcp, get_engine, price_atomic=1_000)  # $0.001 (USDC has 6 decimals)
async def market_lookup(symbol: str) -> dict:
    """Premium market data for a symbol."""
    return await fetch_quote(symbol)

The first call returns a 402-style challenge; the paid retry runs the tool and returns a settlement receipt. Payment travels in _meta, never in the tool arguments — the tool's public schema stays clean.

Payment flow (Mode A: confirm-before-serve)

  1. Agent calls the tool with no payment.
  2. Gateway records a challenge (server-issued nonce, price, recipient, expiry) and returns the x402 402 challenge.
  3. Agent signs an EIP-3009 authorization over the challenge's nonce and re-calls.
  4. Gateway verifies the payload against the stored challenge (signature, recipient, amount, validity window, resource binding), atomically claims the nonce (DB unique constraint — the replay lock), then broadcasts the authorization and waits for on-chain confirmation.
  5. Only after funds have moved does the tool run; the receipt (tx hash) is returned in _meta["x402/payment-response"].

Serving is gated on money moved, not on signature validity — the core defense against the "unpaid service" attack.

Custody model

Key Held where Can spend Worst case if the gateway is fully compromised
Receiving address Cold wallet; gateway knows the public address only Seller revenue Cannot be drained via the gateway. At most, future challenges point at an attacker address — detectable (receipts stop matching) and reversible.
Submitter key Gateway host (env / secret store) Gas only — holds dust Gas dust lost. Bounded by construction.

Because EIP-3009 moves funds buyer → receiving address directly, the total drainable surface is gas dust plus whatever revenue cap you configure (PONTAGE_FLOAT_CAP_ATOMIC).

Configuration

Environment variables, prefix PONTAGE_:

Variable Default Meaning
PAY_TO_ADDRESS (required) Receiving address (public only)
CHAIN_MODE rpc rpc (real chain) or fake (in-memory demo chain)
CHAIN_ID 84532 8453 Base mainnet · 84532 Base Sepolia
RPC_URL https://sepolia.base.org JSON-RPC endpoint
SUBMITTER_PRIVATE_KEY Gas-paying key (dust); required in rpc mode
DATABASE_URL sqlite+aiosqlite:///./pontage.db Postgres in production
CONFIRMATION_THRESHOLD_ATOMIC 100000 Prices ≥ this wait for more confirmations
FLOAT_CAP_ATOMIC 50000000 Refuse new challenges past this cumulative revenue ($50)

See .env.example and docs/ for the full list.

The attack harness

uv run pytest tests/attacks/ -v

Each test attacks both a deliberately-naive gateway and the real engine under identical on-chain conditions (a real in-memory chain model, not a mock), and asserts the exploit succeeds against naive, fails against pontage:

Attack Class Defense
1 Replay across HTTP/chain boundary Atomic nonce claim (DB unique constraint)
2 Request/resource binding flaw Server-issued nonce bound to tool + arguments
3 Authorization weaknesses Every field checked against the challenge; signer recovered
4 Stale/expired authorization Expiry + settlement-headroom checks
5 Settlement-path inconsistency Confirm-before-serve + idempotent retry

Status & scope

pontage is v0.1 — a working, demonstrable slice: one FastAPI service, an MCP server with paid tools, EIP-3009 verify + settle on Base, and the attack harness. It is a reference implementation, not a hardened financial system; run the public demo on a capped mainnet float, and read the custody model before pointing real money at it.

Deferred to later milestones: a Go settlement core, serve-on-verify (Mode B), prepaid tabs, a plain-HTTP middleware surface, and additional chain adapters (the interface stays generic).

Development

uv sync
uv run ruff check src tests        # lint
uv run ruff format src tests       # format
uv run mypy src/pontage           # strict type check
uv run pytest                      # tests (no network needed)

License

MIT — see LICENSE.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选