x402 Facilitator Proxy

io.github.seob5285-alt由 GitHub 账号 seob5285-alt 发布v1.0.1更新于 Oct 24, 2026

Multi-tenant HTTP 402 infrastructure gateway and stdio MCP server for machine payments.

概览

AI 生成的概览

让助手通过托管网关处理 HTTP 402 机器支付,在 Base L2 上验证并结算 USDC 交易。

可以做什么
该 MCP 服务器通过 stdio 向智能体开放 x402 支付流程:注册支付工具、解析 HTTP 402 支付请求、执行 USDC 分账转账,并提交到托管验证网关。网关在 Base L2 上验证链上结算,并将资金按 99% 给商户、1% 给平台金库拆分。配套的 Express 中间件与 LangChain/CrewAI 模板演示商户如何对 API 收费以及智能体如何付费。
适用场景
当助手需要以程序化方式为 API 访问付费或变现时适用,例如自主智能体访问付费接口并按请求以 USDC 结算费用。对无需付费的普通 API 调用没有用处。
运行要求
需要 Node.js 与 npm 在本地安装并运行该 stdio 服务器,仅支持桌面端。需要提供有资金的钱包私钥,通过 AGENT_PRIVATE_KEY 或 FACILITATOR_PRIVATE_KEY 等环境变量传入,并需要访问托管网关与 Base L2 的网络连接。智能体模板还引用了 OPENAI_API_KEY。
安装前请注意
该服务器处理钱包私钥(AGENT_PRIVATE_KEY、FACILITATOR_PRIVATE_KEY)并转移真实 USDC,可能产生实际支出,且 1% 平台费会转入第三方金库。支付会发送到远程网关端点并上链,README 也警告不要在代码中硬编码密钥。使用前请了解网关运营方与费用流向。

安装

在 SourceWeft 中

  1. 打开 控制台中的 x402 Facilitator Proxy,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

X402 Facilitator Proxy - Multi-Tenant Payment Gateway

A decentralized, autonomous payment infrastructure for API monetization on Base L2 with programmatic fee routing and agent-compatible settlement protocols.

🏗️ Architecture Overview

The X402 Facilitator Proxy implements a complete multi-tenant payment gateway that enables merchants to monetize APIs through HTTP 402 "Payment Required" responses, while autonomous agents can seamlessly settle transactions using USDC on Base L2.

x402-facilitator-proxy/├── src/                                    # Core Cloudflare Worker Engine│   ├── index.ts                           # Main proxy gateway endpoint│   └── backend/automation/│       └── sweeper.ts                     # Automated fee collection├── x402-client-sdk/                       # Core Interface Rails│   ├── src/│   │   ├── client-library.ts             # TypeScript SDK│   │   └── mcp-server.ts                 # Model Context Protocol Server│   ├── package.json                      # SDK dependencies│   └── tsconfig.json                     # TypeScript configuration└── templates/                             # Integration Templates    ├── express-middleware/    │   └── x402-guard.js                 # Merchant-Side API Gating    ├── langchain-ts/    │   ├── agent.ts                      # TypeScript Agent Template    │   ├── package.json                  # LangChain dependencies    │   └── README.md                     # Setup instructions    └── crewai-python/        └── agent.py                      # Python Agent Template

🚀 Core Components

1. Cloudflare Worker Proxy Engine

The core backend (src/index.ts) operates as a serverless payment verification gateway deployed on Cloudflare's edge network:

  • Endpoint: https://x402-facilitator-proxy.seob5285.workers.dev/api/v1/verify-and-settle
  • Platform Vault: 0x2E3DADfb314718849A93c49A78618E586c3b2C60
  • Fee Structure: Automated 1% platform fee routing

Key Features:

  • Multi-tenant transaction verification
  • Base L2 USDC settlement validation
  • Automated fee splitting (99% to merchant, 1% to platform)
  • Edge-deployed for global low-latency access

2. Model Context Protocol (MCP) Server

The MCP server (x402-client-sdk/src/mcp-server.ts) provides a standardized interface for AI agents to interact with the payment system:

bash
# Start the MCP server locally via stdionpm run mcp:start

Protocol Features:

  • Standard I/O communication interface
  • Agent-compatible payment tool registration
  • Automatic transaction handling and verification
  • Cross-platform AI framework compatibility

3. Merchant-Side API Gating

The Express middleware (templates/express-middleware/x402-guard.js) enables merchants to protect APIs with HTTP 402 challenges:

javascript
import { x402TollboothGuard } from './templates/express-middleware/x402-guard.js';
app.use('/api/premium', x402TollboothGuard("0.10", "0xYourWalletAddress"));

Middleware Behavior:

  1. Challenge: Returns HTTP 402 with payment instructions when headers are missing
  2. Verification: Validates payment through the proxy gateway
  3. Access: Grants API access upon successful payment verification

4. Autonomous Agent Templates

TypeScript/LangChain Agent (templates/langchain-ts/agent.ts)
typescript
import { createPaymentAgent } from './templates/langchain-ts/agent.js';
const agent = await createPaymentAgent();const result = await agent.invoke({  input: JSON.stringify({    agentPrivateKey: process.env.AGENT_PRIVATE_KEY,    developerWallet: "0x742d35Cc6297C24aE0E4838C4667C02693C4cB36",    amountUSD: "0.10"  })});
Python/CrewAI Agent (templates/crewai-python/agent.py)
python
from templates.crewai_python.agent import X402PaymentAgent
agent = X402PaymentAgent()result = agent.process_payment({    "agent_private_key": os.getenv("AGENT_PRIVATE_KEY"),    "developer_wallet": "0x742d35Cc6297C24aE0E4838C4667C02693C4cB36",    "amount_usd": "0.10"})

🔧 Quick Start

1. Deploy the Proxy Engine

bash
npm installnpm run deploy

2. Setup the MCP Server

bash
cd x402-client-sdknpm installnpm run mcp:start

3. Integrate Merchant Middleware

bash
# Copy the Express middleware to your projectcp templates/express-middleware/x402-guard.js your-project/middleware/
# Install in your Express appimport { x402TollboothGuard } from './middleware/x402-guard.js';app.use('/api/protected', x402TollboothGuard("0.05", "0xYourWallet"));

4. Setup Agent Templates

bash
# For TypeScript/LangChain agentscd templates/langchain-tsnpm installnpm run dev
# For Python/CrewAI agentscd templates/crewai-pythonpip install -r requirements.txtpython agent.py

🔐 Security & Environment Variables

Critical Security Guidelines

⚠️ NEVER HARDCODE PRIVATE KEYS IN REPOSITORY FILES

All sensitive credentials must be managed through secure environment variables:

Cloudflare Worker Environment (Production)

bash
# Set via Cloudflare Workers dashboard or wranglerwrangler secret put FACILITATOR_PRIVATE_KEYwrangler secret put PLATFORM_VAULT_ADDRESS

Local Development Environment

Create .env files for local testing:

env
# .env (root directory - for Cloudflare Worker development)FACILITATOR_PRIVATE_KEY=0x1234567890abcdef...PLATFORM_VAULT_ADDRESS=0x2E3DADfb314718849A93c49A78618E586c3b2C60
# Agent execution environmentsAGENT_PRIVATE_KEY=0xabcdef1234567890...OPENAI_API_KEY=sk-...

Agent Runtime Security

  • TypeScript Agents: Use process.env.AGENT_PRIVATE_KEY
  • Python Agents: Use os.getenv("AGENT_PRIVATE_KEY")
  • MCP Server: Loads keys from system environment at runtime

🌐 Platform Reference

Core Infrastructure

  • Verification Gateway: https://x402-facilitator-proxy.seob5285.workers.dev/api/v1/verify-and-settle
  • Platform Vault: 0x2E3DADfb314718849A93c49A78618E586c3b2C60
  • Network: Base L2 (Chain ID: 8453)
  • Payment Token: USDC (0x833589fCD6eDb6E08f4c7C32d4f71b54bda02913)

Fee Structure

  • Merchant Revenue: 99% of payment amount
  • Platform Fee: 1% automatically routed to platform vault
  • Gas Optimization: Batched transfers for cost efficiency

📖 Integration Patterns

HTTP 402 Payment Flow

  1. API Request: Client attempts to access protected endpoint
  2. Payment Challenge: Server responds with HTTP 402 and payment instructions
  3. Agent Processing: Autonomous agent detects 402, executes USDC payment split
  4. Verification: Proxy gateway validates on-chain transaction
  5. Access Granted: Original API request succeeds with payment headers

Agent Integration Workflow

mermaid
graph TD    A[Agent API Call] --> B{HTTP 402?}    B -->|Yes| C[Parse Payment Requirements]    C --> D[Execute USDC Split Transfer]    D --> E[Submit to Proxy Gateway]    E --> F[Retry Original Request]    F --> G[Access Granted]    B -->|No| G

🛠️ Development Commands

bash
# Core proxy developmentnpm run dev              # Start local development servernpm run deploy           # Deploy to Cloudflare Workersnpm run cf-typegen       # Generate Cloudflare types
# SDK developmentcd x402-client-sdknpm run build           # Build TypeScript SDKnpm run mcp:start       # Start MCP server
# Template testingcd templates/langchain-tsnpm run dev            # Test TypeScript agent
cd templates/crewai-pythonpython agent.py        # Test Python agent
# Automated fee collectionnpm run sweep          # Execute fee sweeping automation

📚 Documentation

🤝 Contributing

  1. Fork the repository
  2. Create feature branches for new integrations
  3. Test against Base L2 testnet before mainnet deployment
  4. Submit pull requests with comprehensive test coverage

📄 License

This project is licensed under the MIT License - enabling open-source innovation while maintaining platform sustainability through programmatic fee routing.


Built for the autonomous economy. Powered by Base L2. Secured by multi-tenant verification.

来源:README.md,提交 c76feb4

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

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

评分

已满足适用检查项的 40%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分

    请在仓库或注册中心条目中声明许可证。