P402

io.github.Z333Q由 GitHub 帳號 Z333Q 發布v1.0.0更新於 Nov 10, 2026

Multi-provider AI router with x402 micropayment settlement on Base L2. 1% flat fee.

已驗證STDIO僅桌面金融AI 與機器學習

概覽

AI 產生的概覽

P402 是本地 MCP 伺服器,讓助理在 300 多個大型語言模型供應商之間路由請求,並透過 Base 上的 x402 以 USDC 逐次結算。

可以做什麼
  • 透過單一相容 OpenAI 的端點送出對話請求,依成本、品質、速度或均衡模式挑選供應商
  • 建立並檢視工作階段預算,為自主代理設定消費上限
  • 經 x402 facilitator 在鏈上逐次結算,在 Base 上使用免 gas 的 USDC 轉帳
  • 透過 A2A JSON-RPC 協定與其他代理交換結構化任務
  • 查看即時花費分析與成本最佳化建議
適用情境
當你希望助理用一組金鑰呼叫多家大型語言模型供應商、把請求導向更便宜或更快的模型,或為自主代理設定硬性消費上限並進行鏈上結算時,適合使用。
執行需求
以 stdio 在本機執行,通常透過 npx 啟動 @p402/mcp-server 套件,因此需要 Node.js。需要 P402 帳號,並以 P402_API_KEY 環境變數提供 API 金鑰。需要能連線至 P402 路由器的網路;可用 P402_ROUTER_URL 覆寫基礎位址。VS Code 擴充功能也內建同一個伺服器。
安裝前請注意
請求會產生費用:收取 1% 固定手續費,且每次呼叫都在 Base 上以 USDC 結算,會動用真實資金。API 金鑰是有效憑證,應避免寫入共用設定。工作階段預算是防止代理失控消費的主要機制,讓代理無人看管執行前應先設定。提示詞與回覆會經過 P402 路由器及第三方模型供應商。

安裝

在 SourceWeft 中

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

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

其他 MCP 客戶端

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

README

P402 Protocol

[npm @p402/sdk] [npm @p402/cli] [npm @p402/mcp-server] [npm @p402/mpp-method] [VS Code Marketplace] [License: MIT] [Docs]

AI payment router. Route across 300+ models, settle per request in USDC on Base or USDC.e on Tempo.

P402 sits between your AI application and every LLM provider. It handles intelligent multi-provider routing (cost / quality / speed / balanced), on-chain micropayment settlement via the x402 protocol and mppx on Base and Tempo, and spending guardrails for autonomous agents.


Why P402

ProblemP402 Solution
Hardcoded to one AI providerRoute across 300+ models automatically
$0.30 payment fees kill micropaymentsUSDC on Base: fractions of a cent per settlement
No spending limits for AI agentsSession budgets + AP2 mandate governance
Fragmented provider APIsOne OpenAI-compatible endpoint
No visibility into AI costsReal-time analytics + optimization suggestions

Quick Start (VS Code / Cursor / Windsurf)

Install the extension — the MCP server is embedded, tools appear in Copilot agent mode immediately, no config files required:

ext install p402-protocol.p402

Then run P402: Configure API Key from the command palette.

→ VS Code Marketplace · Open VSX


Quick Start (Claude Desktop / any MCP client)

json
{  "mcpServers": {    "p402": {      "command": "npx",      "args": ["-y", "@p402/mcp-server"],      "env": { "P402_API_KEY": "p402_live_..." }    }  }}

→ MCP docs · MCP Registry


Quick Start (SDK)

bash
npm install @p402/sdk
typescript
import P402Client from '@p402/sdk';
const p402 = new P402Client({ apiKey: process.env.P402_API_KEY });
// Drop-in OpenAI replacement — P402 picks the best providerconst response = await p402.chat({  messages: [{ role: 'user', content: 'Explain x402 payments in one sentence.' }],  p402: { mode: 'cost' }   // cost | quality | speed | balanced});
console.log(response.choices[0].message.content);// p402_metadata: { provider: 'deepseek', cost_usd: 0.00031, latency_ms: 412 }

Quick Start (CLI)

bash
# Authenticate oncenpx p402 login
# Chat using the cheapest providernpx p402 chat "What is x402?" --mode cost
# Check facilitator healthnpx p402 health

Routing Modes

ModeOptimizes ForTypical Provider
costLowest priceDeepSeek V3, Haiku 4.5, GPT-4o-mini
qualityBest outputClaude Opus 4.6, GPT-5, Gemini 3 Pro
speedLowest latencyGroq LPU, Flash models
balancedEqual weight (default)Sonnet 4.6, GPT-4o, Gemini Flash

Session Budgets

Enforce hard spending caps for autonomous agents:

typescript
// Create a $10 session — agent cannot spend a cent moreconst session = await p402.createSession({ budget_usd: 10 });
// All chat requests are deducted from the sessionconst response = await p402.chat({  messages,  p402: { session_id: session.id, mode: 'cost' }});
// Check remaining budgetconst { budget } = await p402.getSession(session.id);console.log(`$${budget.remaining_usd} remaining`);

x402 Payments

x402 is a machine-native payment protocol using HTTP 402. AI agents pay for resources using gasless EIP-3009 USDC transfers on Base L2.

Client → signs EIP-3009 authorization       → POST /api/v1/facilitator/verify       → POST /api/v1/facilitator/settleFacilitator → executes transferWithAuthorization            → pays gas (user pays zero gas)            → returns { success, txHash, receipt }

Network: Base Mainnet (Chain ID: 8453) · Asset: USDC 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913

→ x402 payments guide


A2A Protocol

P402 implements the Google A2A spec over JSON-RPC 2.0. Agents communicate through structured tasks, discover capabilities via /.well-known/agent.json, and settle payments via the x402 extension.

typescript
// Discover P402's capabilitiesGET https://p402.io/.well-known/agent.json
// Submit a taskPOST https://p402.io/api/a2a{ "jsonrpc": "2.0", "method": "tasks/send", "params": { ... } }

→ A2A protocol guide


Packages

PackageDescriptionVersion
@p402/sdkTypeScript SDK — P402Client, types, EIP-712 mandate helpers[npm]
@p402/cliCLI tool — login, chat, sessions, mandates, analytics[npm]
@p402/mcp-serverstdio MCP server — 6 tools over Model Context Protocol[npm]
@p402/mpp-methodmppx payment methods — Base EIP-3009 and Tempo TIP-20 multi-rail settlement[npm]
p402 VS Code extensionEmbedded MCP server for VS Code, Cursor, and Windsurf — zero config[Marketplace]

Examples

ExampleWhat It Shows
01-quickstartLogin → chat → view spend in ~20 lines
02-openai-migrationDrop-in OpenAI SDK replacement
03-nextjs-session-budgetBudget-capped AI in a Next.js App Router project
04-a2a-agentsTwo agents communicating with x402 payment gate

Docs

Guide
Getting StartedAccount, API key, first request
AuthenticationAPI keys, env vars, security
Routing GuideModes, scoring, providers, models
x402 PaymentsEIP-3009, wire format, settlement
SessionsSession lifecycle + budget enforcement
A2A ProtocolJSON-RPC, mandates, Bazaar
CLI ReferenceFull CLI command reference
OpenAPI SpecMachine-readable API schema

Community


License

MIT © P402 Protocol

來源:README.md,提交 94c8cc9

工具

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

版本歷史

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

評分

已滿足適用檢查項的 50%

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

  • 近 30 天內可連通25 分

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

  • 已宣告認證方式10 分

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

  • 已列出工具15 分

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

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