undo402
v0.1.4
Published
Pay x402 APIs from an agent, covered by undo402 refunds on Robinhood Chain. SDK and MCP server.
Maintainers
Readme
undo402 for agents
Pay x402 APIs on Robinhood Chain from an agent, with refunds when a paid call fails. Two ways to use it:
- SDK: a
fetch()that answers402 Payment Requiredby itself, within spending limits. - MCP server: tools for Claude, Cursor and other MCP clients to find covered APIs, call them and track refunds.
Payments are USDG on Robinhood Chain (chain 4663), x402 V2 scheme exact with EIP-3009. Your key stays on your machine; it only signs payment authorizations. Requires Node.js 20 or newer.
SDK
import { createClient, usd } from "undo402";
const client = createClient({
account: process.env.AGENT_KEY as `0x${string}`, // a 0x private key or a viem account
maxPerCall: usd(0.05), // never pay more than this for one call
maxTotal: usd(5), // stop after this much in total
allowedPrefixes: ["https://undo402.xyz/s/"], // only pay covered calls
});
const { response, paid, receipt } = await client.fetch("https://undo402.xyz/s/rhc-token-check?address=0x…");
console.log(response.status, await response.json());
console.log(`paid ${paid} units, track: ${receipt.url}`);receipt.id is the X-BOND-RECEIPT of the call. If the seller fails after you paid, the refund shows up on receipt.url and lands in the paying wallet.
Limits are counted when a payment is signed. A call over a limit throws PaymentRefused with a code (over_call_limit, over_total_limit, url_not_allowed, no_acceptable_option, unreadable_402) and nothing is signed.
MCP server (local, can pay)
{
"mcpServers": {
"undo402": {
"command": "npx",
"args": ["-y", "-p", "undo402", "undo402-mcp"],
"env": {
"UNDO402_PRIVATE_KEY": "0x…",
"UNDO402_MAX_PER_CALL_USD": "0.05",
"UNDO402_MAX_TOTAL_USD": "1"
}
}
}
}| Variable | | Default |
| --- | --- | --- |
| UNDO402_GATEWAY | gateway origin | https://undo402.xyz |
| UNDO402_PRIVATE_KEY | paying wallet; without it the server can look things up but not pay | none |
| UNDO402_MAX_PER_CALL_USD | per-call limit | 0.05 |
| UNDO402_MAX_TOTAL_USD | limit for the session | 1 |
| UNDO402_ALLOW_ANY_URL | 1 to pay URLs outside the gateway (not covered) | off |
Tools: find_apis, call_api, track_payment, wallet_status.
Use a wallet that holds only what the agent may spend.
MCP server (remote, read-only)
No install: point an MCP client that supports Streamable HTTP at https://undo402.xyz/mcp. Tools: find_apis, get_api, track_payment, system_status. It never pays.
