AI 에이전트가 하드 스펜딩 리밋과 로컬 지갑 관리를 통해 USDC로 HTTP 402 리소스를 자율적으로 결제할 수 있게 합니다.
다른 이름 devmster/x402-trinity, x402-trinity
- 스타
- 3
- Tools
- —
- 다운로드, 30일
- —
- 최신 버전
- 0.2.4
- 마지막 커밋
- 2026년 9월 27일
- 라이선스
- —
x402 Trinity MCP란?
x402 Trinity은(는) MCP server입니다. AI 에이전트가 하드 스펜딩 리밋과 로컬 지갑 관리를 통해 USDC로 HTTP 402 리소스를 자율적으로 결제할 수 있게 합니다.
프로젝트 README에서 생성된 요약
x402 Trinity MCP server 정보
x402 Trinity는 AI 에이전트가 USDC를 사용하여 HTTP 402 Payment Required 응답을 자율적으로 처리할 수 있는 방법을 제공합니다. fetch를 즉시 대체할 수 있는 방식으로 작동하여, 에이전트가 수동 개입 없이 유료 API, 데이터셋 또는 파일에 접근할 수 있도록 합니다. 이 시스템은 로컬 지갑 관리를 위해 설계되었으므로 개인 키가 로컬 프로세스를 절대 벗어나지 않으며 제3자 호스팅 지갑 서비스가 필요하지 않습니다.
개발자는 요청당 최대 금액 및 전체 생애 예산을 포함한 필수 스펜딩 리밋을 통해 엄격한 안전 경계를 구성할 수 있습니다. 서버는 기본적으로 Base 네트워크를 지원하지만 커스텀 설정을 통해 모든 EVM 체인으로 확장할 수 있습니다. 에이전트가 가격을 확인하고, 결제를 실행하며, 지갑 상태를 모니터링할 수 있는 전용 도구를 포함합니다. 에이전트가 예산을 제어하므로, 모델이 재정적 제약을 우회하는 것을 방지하기 위해 서버 작동에는 X402_PRIVATE_KEY 및 X402_TOTAL_BUDGET과 같은 환경 변수가 필요합니다.
활용 사례
- 1안전한 로컬 트랜잭션사용자는 결제를 로컬에서 관리하여 개인 키가 제3자 API에 노출되지 않도록 보장할 수 있습니다.
프로젝트의 README를 바탕으로 작성되었습니다. 모든 활용 사례는 해당 내용의 인용문과 대조하여 확인합니다.
x402 Trinity MCP 설치 방법
형식 확인: 2026년 11월 10일Cursor에 추가Goose에 추가Claude Code에 x402 Trinity MCP 설치
$ claude mcp add --env 'X402_PRIVATE_KEY=<YOUR_X402_PRIVATE_KEY>' --env 'X402_MAX_PER_REQUEST=<X402_MAX_PER_REQUEST>' --env 'X402_TOTAL_BUDGET=<X402_TOTAL_BUDGET>' x402-trinity -- npx -y x402-trinityCursor에 x402 Trinity MCP 설치
~/.cursor/mcp.json
{
"mcpServers": {
"x402-trinity": {
"command": "npx",
"args": [
"-y",
"x402-trinity"
],
"env": {
"X402_PRIVATE_KEY": "<YOUR_X402_PRIVATE_KEY>",
"X402_MAX_PER_REQUEST": "<X402_MAX_PER_REQUEST>",
"X402_TOTAL_BUDGET": "<X402_TOTAL_BUDGET>"
}
}
}
}VS Code에 x402 Trinity MCP 설치
.vscode/mcp.json
{
"servers": {
"x402-trinity": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"x402-trinity"
],
"env": {
"X402_PRIVATE_KEY": "<YOUR_X402_PRIVATE_KEY>",
"X402_MAX_PER_REQUEST": "<X402_MAX_PER_REQUEST>",
"X402_TOTAL_BUDGET": "<X402_TOTAL_BUDGET>"
}
}
}
}VS Code CLI에 x402 Trinity MCP 설치
$ code --add-mcp '{"name":"x402-trinity","type":"stdio","command":"npx","args":["-y","x402-trinity"],"env":{"X402_PRIVATE_KEY":"<YOUR_X402_PRIVATE_KEY>","X402_MAX_PER_REQUEST":"<X402_MAX_PER_REQUEST>","X402_TOTAL_BUDGET":"<X402_TOTAL_BUDGET>"}}'Claude Desktop에 x402 Trinity MCP 설치
claude_desktop_config.json
{
"mcpServers": {
"x402-trinity": {
"command": "npx",
"args": [
"-y",
"x402-trinity"
],
"env": {
"X402_PRIVATE_KEY": "<YOUR_X402_PRIVATE_KEY>",
"X402_MAX_PER_REQUEST": "<X402_MAX_PER_REQUEST>",
"X402_TOTAL_BUDGET": "<X402_TOTAL_BUDGET>"
}
}
}
}Codex에 x402 Trinity MCP 설치
$ codex mcp add x402-trinity --env 'X402_PRIVATE_KEY=<YOUR_X402_PRIVATE_KEY>' --env 'X402_MAX_PER_REQUEST=<X402_MAX_PER_REQUEST>' --env 'X402_TOTAL_BUDGET=<X402_TOTAL_BUDGET>' -- npx -y x402-trinityCodex config.toml에 x402 Trinity MCP 설치
~/.codex/config.toml
[mcp_servers.x402-trinity] command = "npx" args = ["-y", "x402-trinity"] [mcp_servers.x402-trinity.env] X402_PRIVATE_KEY = "<YOUR_X402_PRIVATE_KEY>" X402_MAX_PER_REQUEST = "<X402_MAX_PER_REQUEST>" X402_TOTAL_BUDGET = "<X402_TOTAL_BUDGET>"
Gemini CLI에 x402 Trinity MCP 설치
$ gemini mcp add -s user -e 'X402_PRIVATE_KEY=<YOUR_X402_PRIVATE_KEY>' -e 'X402_MAX_PER_REQUEST=<X402_MAX_PER_REQUEST>' -e 'X402_TOTAL_BUDGET=<X402_TOTAL_BUDGET>' x402-trinity npx -- -y x402-trinityGemini settings.json에 x402 Trinity MCP 설치
~/.gemini/settings.json
{
"mcpServers": {
"x402-trinity": {
"command": "npx",
"args": [
"-y",
"x402-trinity"
],
"env": {
"X402_PRIVATE_KEY": "<YOUR_X402_PRIVATE_KEY>",
"X402_MAX_PER_REQUEST": "<X402_MAX_PER_REQUEST>",
"X402_TOTAL_BUDGET": "<X402_TOTAL_BUDGET>"
}
}
}
}구성
X402_PRIVATE_KEY필수비밀Private key of the wallet that pays. Use a dedicated wallet holding only what you would accept losing. The server refuses to start without it.
X402_MAX_PER_REQUEST필수Hard ceiling for a single payment, in atomic units (USDC has 6 decimals, so 50000 is $0.05). Required: a model decides when payments happen, so the cap cannot come from the model.
X402_TOTAL_BUDGET필수Lifetime ceiling across all payments, in atomic units. Required for the same reason as the per-request cap.
X402_ALLOW_HOSTSComma-separated hosts that may be paid. Anything else is refused however convincing the challenge looks.
X402_BUDGET_FILEPath to a file that makes the lifetime budget survive restarts. Without it the total resets every time the server starts.
X402_NETWORKSNetworks to accept. Defaults to base.
| 이름 | 설명 | 유형 |
|---|---|---|
| X402_PRIVATE_KEY | Private key of the wallet that pays. Use a dedicated wallet holding only what you would accept losing. The server refuses to start without it. | 필수비밀 |
| X402_MAX_PER_REQUEST | Hard ceiling for a single payment, in atomic units (USDC has 6 decimals, so 50000 is $0.05). Required: a model decides when payments happen, so the cap cannot come from the model. | 필수 |
| X402_TOTAL_BUDGET | Lifetime ceiling across all payments, in atomic units. Required for the same reason as the per-request cap. | 필수 |
| X402_ALLOW_HOSTS | Comma-separated hosts that may be paid. Anything else is refused however convincing the challenge looks. | |
| X402_BUDGET_FILE | Path to a file that makes the lifetime budget survive restarts. Without it the total resets every time the server starts. | |
| X402_NETWORKS | Networks to accept. Defaults to base. |
자동 검사
2026년 11월 14일에 실행됨전체 보고서 →자동 검사를 통과했습니다. 이는 보안 감사가 아닙니다. 코드를 직접 읽고 서버에 필요한 최소한의 권한만 부여하십시오. 검사 방식 · 점수를 높이기 위해 수정할 항목
- 소스 저장소 연결 및 접근 가능devmster/x402-trinity is public and reachablegithub.com/devmster/x402-trinity ↗통과
- 패키지가 이 저장소를 소스로 명시x402-trinity names devmster/x402-trinity as sourcenpmjs.com/package/x402-trinity ↗통과
- 빌드 출처(Sigstore 증명)No build attestation published for this release검사되지 않음
- 오픈 소스 라이선스 (OSI)No license결함 발견
- 최근 1년 내 커밋 또는 릴리스Last commit or release 2026-09-27github.com/devmster/x402-trinity ↗통과
- OpenSSF Scorecard검사되지 않음
- 패키지 이름이 인기 패키지와 유사하지 않음No popular package one edit away from x402-trinity통과
- 패키지 및 해당 종속성에 중요한 보안 권고 없음1 resolved dependencies checked; no critical advisoryosv.dev ↗통과
- 모델에 대한 숨겨진 지침 없음0 tool descriptions and the README read; no override phrases, credential paths or hidden characters통과
- 파괴적인 도구에 라벨 표시됨검사되지 않음
- 원격 엔드포인트가 MCP 핸드셰이크에 응답검사되지 않음
README
GitHub에서 보기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.
npm install x402-trinity
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)
import { createX402Fetch } from 'x402-trinity';
const x402Fetch = createX402Fetch({
privateKey: process.env.X402_PRIVATE_KEY, // never hardcode
policy: {
maxAmountPerRequest: '5000', // 0.005 USDC max per call (REQUIRED)
totalBudget: '1000000', // 1.00 USDC lifetime (REQUIRED)
allowHosts: ['api.example.com'],
allowPayTo: ['0x...'],
},
});
const r = await x402Fetch('https://api.example.com/data'); // 402 handled, returns 200
Or patch the global so unmodified code pays automatically:
import { installX402 } from 'x402-trinity';
const uninstall = installX402(cfg); // globalThis.fetch now pays 402s
Confirm which wallet will pay before funding anything:
X402_PRIVATE_KEY=0x... npx x402-trinity-whoami
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)
import { createX402Seller } from 'x402-trinity/seller';
import { createFileNonceStore } from 'x402-trinity/budget-file';
const seller = createX402Seller({
payTo: '0xYourWallet', // 100% of every payment lands here
price: '10000', // 0.01 USDC, atomic units
network: 'base',
facilitator: 'https://your-facilitator.example', // REQUIRED — no default exists
nonceStore: createFileNonceStore('./.x402-nonces.json'), // REQUIRED — see below
});
// in any fetch-style handler:
const gate = await seller.guard(request);
if (gate.response) return gate.response; // unpaid or refused — hand back the 402
return new Response(yourData, { headers: seller.receiptHeader(gate.settlement) });
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
| Protocols | x402 v1 and v2, detected per response. Unknown versions and MPP challenges declined with a clear reason, never guessed |
| Chains | Base mainnet + USDC, shipped as the default. Any other EVM chain via customChains |
| Networks | short names and CAIP-2 (eip155:8453) |
| Custody | privateKey, additive shards, or remoteSign (HSM/MPC) — your choice, not the architecture's |
| Speed | 3.2 µs warm / 1.0 ms cold (TypeScript); 1.2 µs / 1.7 ms (Python) |
| Runtime | auto-detects Cloudflare Workers and changes strategy; also Node, Bun, Deno |
| Safety | mandatory caps, allowlists, never-pay-twice reconciliation, timing-hardened signing |
Another chain
Base is the default. The signing is chain-agnostic, so add whatever you need — including a testnet to rehearse on:
const fetch2 = createX402Fetch({
privateKey: process.env.X402_PRIVATE_KEY,
maxAmountPerRequest: '10000',
totalBudget: '100000',
customChains: {
'base-sepolia': { id: 84532, asset: '0x036cbd53842c5426634e7929541ec2318f3dcf7e', name: 'USDC', version: '2' },
},
});
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:
import { createFileBudgetStore } from 'x402-trinity/budget-file';
createX402Fetch({
...,
budgetStore: createFileBudgetStore('./.x402-budget.json'), // survives restarts
});
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:
| tool | |
|---|---|
check_price |
what a resource costs, without paying |
pay_and_fetch |
fetch it, paying if it is within your limits |
wallet_status |
address, balance, spent, remaining |
{
"mcpServers": {
"x402-trinity": {
"command": "npx",
"args": ["-y", "x402-trinity-mcp"],
"env": {
"X402_PRIVATE_KEY": "0x...",
"X402_MAX_PER_REQUEST": "50000",
"X402_TOTAL_BUDGET": "1000000",
"X402_BUDGET_FILE": "./.x402-budget.json",
"X402_ALLOW_HOSTS": "api.example.com",
"X402_NETWORKS": "base"
}
}
}
}
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.
from x402_trinity import X402Client, Policy
client = X402Client(
private_key=os.environ["X402_PRIVATE_KEY"],
policy=Policy(max_amount_per_request=5000, total_budget=1_000_000,
allow_hosts=["api.example.com"]),
)
body = client.urlopen("https://api.example.com/data").read()
Or as a decorator, so payment-unaware code just works:
from x402_trinity import x402_telemetry
@x402_telemetry(private_key=KEY, policy=Policy(...))
def harvest():
return urllib.request.urlopen("https://sensor.local/v1/lidar").read()
The warm path is 1.1 µs — a long-lived controller is warm after its first payment.
Development
npm install
npm run build # dist/*.js + *.min.js + *.d.ts
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.
x402 Trinity MCP 질문
x402 Trinity MCP를 Claude Code에 추가하려면 어떻게 하나요?
터미널에서 claude mcp add --env 'X402_PRIVATE_KEY=<YOUR_X402_PRIVATE_KEY>' --env 'X402_MAX_PER_REQUEST=<X402_MAX_PER_REQUEST>' --env 'X402_TOTAL_BUDGET=<X402_TOTAL_BUDGET>' x402-trinity -- npx -y x402-trinity를 실행합니다. 모든 프로젝트에서 사용할 수 있게 하려면 --scope user를 추가합니다.
x402 Trinity MCP를 Cursor에 추가하려면 어떻게 하나요?
~/.cursor/mcp.json를 열고 mcpServers 아래에 서버를 추가합니다. 위 설치 섹션에 표시된 Cursor 구성을 사용합니다.
에이전트가 리소스 비용을 어떻게 결제하나요?
서버가 402 Payment Required 챌린지를 읽고, 사용자 정의 리밋과 대조한 뒤, 트랜잭션에 서명하고 요청을 재시도하여 처리합니다.
에이전트가 가스비를 지불해야 하나요?
아니요, 퍼실리테이터가 EIP-3009에 따라 전송을 제출하므로 에이전트는 USDC만 있으면 됩니다.
에이전트의 지출 금액을 제한할 수 있나요?
네, 요청당 최대 금액과 전체 생애 예산을 포함한 필수 스펜딩 캡을 설정해야 합니다.