agent mcp-pay端到端演示

它展示了什么
- 免费工具直通 --没有价格的工具会立即执行,不会触发付款流
- 透明的自动支付 --当付费工具返回时
PAYMENT_REQUIRED,客户端会自动检测到挑战,签署付款证明,并在不更改代理代码的情况下重试 - 多工具支付 --两种不同价格的付费工具(
translate0.01美元,summarize0.05美元) - 预算跟踪 —
client.getSpendingStats()每期回报和每日支出总额 - 收款流程 --每次成功的付费通话都会返回一个
_receipt工具结果旁边的块
如何跑步
npm install
npm run demo需要Node.js 18+。
预期输出
=== agentic-mcp-pay End-to-End Demo ===
Server and client connected
--- Test 1: Free tool (echo) ---
Result: Echo: Hello world!
Free tool works — no payment needed
--- Test 2: Paid tool (translate, $0.01) ---
Auto-paying $0.01 for "translate" via mock
Result: [Translated to Spanish]: Hello world
Paid tool works — payment handled transparently
--- Test 3: Paid tool (summarize, $0.05) ---
Auto-paying $0.05 for "summarize" via mock
Result: Summary of "The quick brown fox jumps over the lazy dog. This ...": This is a key point.
Second paid tool works
--- Test 4: Spending stats ---
Total spent: $0.06
Today: $0.06
Calls: 2
Budget tracking works
=== All tests passed! ===
The full payment loop works:
Agent calls tool -> Gateway returns PAYMENT_REQUIRED
-> Client auto-detects -> Checks budget -> Signs payment
-> Retries with proof -> Gateway verifies -> Tool executes
-> Receipt returned -> Spending tracked循环是如何工作的
Agent calls tool
│
▼
Gateway checks pricing table
│
├─ No price set ──────────────────► Execute immediately (passthrough)
│
└─ Price set, no _payment arg ───► Return PAYMENT_REQUIRED + challenge
│
▼
Client receives challenge
│
Check budget limits
│
Sign payment proof
│
Retry call with _payment arg
│
▼
Gateway verifies proof
│
Execute tool, return result + receipt另见
- 代理mcp支付 --服务器端支付网关包
- 代理mcp付费客户端 --买方客户端SDK包
- 教程:在5分钟内将MCP工具货币化
