
x402 Trinity
io.github.devmster由 GitHub 帳號 devmster 發布v0.2.4更新於 Oct 24, 2026
Give an agent a wallet. Pays for x402 resources within hard limits. Base + USDC, gasless.
概覽
本機 MCP 伺服器,為 AI 助理提供一個 USDC 錢包,讓它能在硬性支出上限內查詢價格並支付 x402 付費資源。
- 可以做什麼
- 在不付款的情況下查詢某個付費資源的標價
- 抓取資源,若回應 HTTP 402 且在限額內就自動完成付款
- 查看付款錢包的位址、餘額、已花費金額與剩餘預算
- 依環境變數而非模型輸入執行單次上限、總額上限、主機白名單與防重複付款檢查
- 適用情境
- 當助理需要向回應 HTTP 402 的付費 API、資料集、檔案或其他代理服務購買內容,且希望支出由固定限額而非模型判斷來控制時使用。
- 執行需求
- 以 stdio 在本機執行,通常透過 npx 啟動。需要 X402_PRIVATE_KEY(付款錢包私鑰)、X402_MAX_PER_REQUEST 與 X402_TOTAL_BUDGET(以最小單位計),缺少則拒絕啟動。選用:X402_BUDGET_FILE 讓預算在重新啟動後保留、X402_ALLOW_HOSTS、X402_NETWORKS(預設 base)。錢包需在 Base 上持有 USDC,不需 gas。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 x402 Trinity,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
x402-trinity
A drop-in fetch replacement that lets an AI agent pay for things by itself — with hard
spending limits, no hosted wallet service, and no changes to the agent's own code.
Zero runtime dependencies. 7 KB gzipped. Buyer and seller in TypeScript; buyer in Python.
Copy-paste setup
A ready-made brief for your coding agent. Paste it in and it does the install, the wallet, your spending limits, the price check and the purchase — you just say what you are buying and what it may spend.
Buying from a paid API, a dataset, a file, or another agent's service — anything that answers HTTP 402.
More setups, and a marketplace for you to earn for your products or buy from the marketplace, at x402trinity.com.
Why
When an agent hits a paid resource it gets 402 Payment Required. Without something to
handle that, the request simply fails.
x402-trinity handles it: reads the challenge, checks it against limits you set, signs, retries. All of it locally — no hosted wallet service, no third-party API, and the key never leaves your process.
Gas exists but the payer doesn't pay it — under EIP-3009 the facilitator submits the transfer, so an agent's wallet only ever needs USDC.
Buy (agent pays for things)
Or patch the global so unmodified code pays automatically:
Confirm which wallet will pay before funding anything:
It prints the address and its balance on every chain, and never prints the key. If the address is not the wallet you meant, stop before sending anything.
Sell (charge for a resource, get paid)
Both required fields are deliberate. There is no default facilitator because settling is someone's real money and guessing an endpoint is not a default. And the replay guard has to outlive the process: an in-memory one forgets every settled payment on restart, so a buyer could re-present a spent authorization and get the resource again for free. The constructor throws rather than let either be implicit.
The seller never holds a private key and never touches funds. It quotes a price and asks a facilitator to verify and settle; money moves buyer → you directly on-chain.
This release ships Base + USDC only. Any other EVM chain works through
customChains; your address is the same on all of them.
What it does
Another chain
Base is the default. The signing is chain-agnostic, so add whatever you need — including a testnet to rehearse on:
Verify the entry against the deployed contract first: call DOMAIN_SEPARATOR() and check it
equals what this library computes. A wrong name or version produces a signature that looks
valid and the contract rejects.
It deliberately will not
Broadcast to a chain · hold funds · need gas or an RPC · take a cut of a payment (structurally impossible — EIP-3009 has one recipient) · require a hosted signer · pay without limits · guess at a protocol it doesn't speak.
Safety — read this before real money
Caps are mandatory. maxAmountPerRequest and totalBudget have no defaults; the wrapper
refuses to construct without them. An auto-payer without limits is a money leak controlled by
whoever runs the server.
totalBudget alone is per-instance. It is an in-memory counter that resets on restart, on
a new client, and on every Cloudflare Worker isolate — which is per request. On mainnet that
turns a lifetime cap into a per-request cap. Mainnet therefore requires a durable
budgetStore, or an explicit acknowledgeEphemeralBudget: true:
The key is in the process. That is the trade for having no hosted signer. Bound it:
use a dedicated wallet holding only what you would accept losing, set allowPayTo so an
exfiltrated key still cannot pay a stranger through this wrapper, and use remoteSign if you
need enclave-grade custody.
Timing hardening is hardening, not a proof. Secret scalars use blinding plus always-add-and-double, which cut the timing spread from 99.6% to 12% (Python: 99.9% → 1.1%). BigInt arithmetic is itself variable-time and no pure-JS implementation removes that.
MCP server — give an agent a wallet
MCP is how an assistant gets tools. This exposes three:
A model decides when these run. It cannot be reasoned with about budgets, and a
paywalled page can claim any price it likes. So the limits are not parameters the model can
set — they come from the environment, and the server refuses to start without
X402_PRIVATE_KEY, X402_MAX_PER_REQUEST and X402_TOTAL_BUDGET.
Set X402_BUDGET_FILE too, or the lifetime ceiling resets every restart. Set
X402_ALLOW_HOSTS and nothing else can be paid, however convincing the challenge looks.
Use a wallet holding only what you would accept losing.
Python
Same protocol, standard library only. Buyer only — to charge for a resource, use the TypeScript seller. Aimed at long-lived processes: on-body agents, robotics controllers, harvesting scripts.
Or as a decorator, so payment-unaware code just works:
The warm path is 1.1 µs — a long-lived controller is warm after its first payment.
Development
esbuild, typescript and wrangler are dev dependencies only, used for building.
The shipped package has zero runtime dependencies.
License
Business Source License 1.1. The source is open to read, modify and use non-commercially; production use is granted except as a hosted or managed service offering its functionality to third parties. It converts to MIT on 2029-08-25. See LICENSE.
This software moves money — read the additional notice there, and set your spending caps.
Convenience fee: 0.1% per transaction and 1 cent every 100 transactions.
來源:README.md,提交 edd7bf6
工具
0版本歷史
4- v0.2.4最新Sep 27, 2026
- v0.2.3Sep 22, 2026
- v0.2.2Sep 18, 2026
- v0.2.1Sep 16, 2026
評分
已滿足適用檢查項的 40%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分
請在儲存庫或註冊中心條目中宣告授權條款。