@quackai/q402-mcp 0.5.1 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +3 -1
  2. package/dist/index.js +215 -4
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -103,7 +103,7 @@ Then run `codex` and ask the same kind of question. The first call may take a fe
103
103
 
104
104
  ### Any other MCP client
105
105
 
106
- The server has no client-specific code. If your client speaks stdio MCP, point it at `npx -y @quackai/q402-mcp` and the five tools listed below will appear.
106
+ The server has no client-specific code. If your client speaks stdio MCP, point it at `npx -y @quackai/q402-mcp` and the seven tools listed below will appear.
107
107
 
108
108
  ---
109
109
 
@@ -120,6 +120,8 @@ The server has no client-specific code. If your client speaks stdio MCP, point i
120
120
  | `q402_pay` | API key + private key + flag | Send a gasless payment to a single recipient. **Sandbox by default** — see [Sandbox vs live mode](#sandbox-vs-live-mode). |
121
121
  | `q402_batch_pay` | API key + private key + flag | Send a gasless payment to **multiple** recipients in one call on a single chain × token. Trial keys: 5 rows max. Paid keys: 20 rows max. **Auto-routing:** same rule as `q402_pay` (BNB + Trial key set ⇒ Trial, else Multichain). **Ambiguity gate:** 6+ recipient BNB batches with Trial set return `status="ambiguous"` instead of executing — the agent asks the user to pick `keyScope="trial"` (first 5), `"multichain"` (all paid), or two calls (5 free + remainder paid). **Supported chains: avax, bnb, eth, mantle, injective, monad, scroll** (default EIP-7702 mode). xlayer + stable are NOT batchable — use `q402_pay` in a loop for those. Same sandbox gating as `q402_pay`. **Rate-limit note:** the inner `/api/relay` budget (30/min per key) is consumed per row, so a paid 20-row batch leaves ~10 inner slots for the next minute. |
122
122
  | `q402_receipt` | none | Look up a Trust Receipt by `rct_…` id and locally verify its ECDSA signature against the relayer EOA. Returns the public settlement record + a `verified` boolean. *receiptId-only today; tx-hash lookup reserved for a future release.* |
123
+ | `q402_wallet_status` | private key | Per-chain EIP-7702 delegation status for the EOA derived from `Q402_PRIVATE_KEY`, across all 9 Q402 chains. Read-only — no on-chain action, no quota consumption. Use to answer "why is my wallet showing Smart account?" and to pick chains for `q402_clear_delegation`. |
124
+ | `q402_clear_delegation` | API key + private key | Clear the EIP-7702 delegation on a single chain for the configured wallet. Local signing with `Q402_PRIVATE_KEY` (key never leaves the user's machine); Q402 broadcasts the type-0x04 TX from a sponsor wallet so the user pays $0 gas. After clearing, `eth_getCode` returns `0x` — the next `q402_pay` on that chain auto-recreates a fresh delegation. Useful when the wallet needs to receive native gas tokens (BNB/ETH/etc.) directly without revert, or to remove the wallet UI's "Smart account" indicator. |
123
125
 
124
126
  `q402_pay` and `q402_batch_pay` follow a "confirm in chat first" contract: the tool description instructs the model to never call it without explicit user approval of the recipient address(es), amount(s), chain, and token. For batch calls the user must approve the **full batch**, not the individual rows.
125
127
 
package/dist/index.js CHANGED
@@ -775,7 +775,7 @@ function describeSandboxReason(resolvedKey) {
775
775
  }
776
776
  var PAY_TOOL = {
777
777
  name: "q402_pay",
778
- description: "Send a gasless USDC, USDT, or RLUSD payment via Q402. Auto-routing: chain='bnb' + Q402_TRIAL_API_KEY set \u2192 Trial (free sponsored); anything else \u2192 Multichain (paid 9-chain). Same rule for q402_batch_pay. Set keyScope='trial' or 'multichain' to force one explicitly. Trial keys reject any non-BNB chain server-side with TRIAL_BNB_ONLY. Multichain keys cover avax, bnb, eth, xlayer, stable, mantle, injective, monad, scroll \u2014 USDC/USDT on most chains, RLUSD on Ethereum only, Injective USDT-only. SANDBOX BY DEFAULT \u2014 no funds move unless the resolved key is a live key (q402_live_*), Q402_PRIVATE_KEY is set, and Q402_ENABLE_REAL_PAYMENTS=1. The recipient receives the full amount; the sender pays $0 in gas. ALWAYS get explicit user confirmation of the exact recipient address, amount, chain, and token in conversation immediately before calling this tool.",
778
+ description: "Send a gasless USDC, USDT, or RLUSD payment via Q402. Auto-routing: chain='bnb' + Q402_TRIAL_API_KEY set \u2192 Trial (free sponsored); anything else \u2192 Multichain (paid 9-chain). Same rule for q402_batch_pay. Set keyScope='trial' or 'multichain' to force one explicitly. Trial keys reject any non-BNB chain server-side with TRIAL_BNB_ONLY. Multichain keys cover avax, bnb, eth, xlayer, stable, mantle, injective, monad, scroll \u2014 USDC/USDT on most chains, RLUSD on Ethereum only, Injective USDT-only. SANDBOX BY DEFAULT \u2014 no funds move unless the resolved key is a live key (q402_live_*), Q402_PRIVATE_KEY is set, and Q402_ENABLE_REAL_PAYMENTS=1. The recipient receives the full amount; the sender pays $0 in gas. Note: the first q402_pay on a chain creates a persistent EIP-7702 delegation on the sender's EOA (set-code TX, Pectra). Subsequent payments on the same chain reuse it (gas-efficient). To remove the delegation later, call q402_clear_delegation. ALWAYS get explicit user confirmation of the exact recipient address, amount, chain, and token in conversation immediately before calling this tool.",
779
779
  inputSchema: {
780
780
  type: "object",
781
781
  properties: {
@@ -960,7 +960,7 @@ function describeSandboxReason2(resolvedKey) {
960
960
  }
961
961
  var BATCH_PAY_TOOL = {
962
962
  name: "q402_batch_pay",
963
- description: `Send gasless payments to MULTIPLE recipients on a single chain \xD7 token in one call. Auto-routing follows the same rule as q402_pay: chain='bnb' + Q402_TRIAL_API_KEY set \u2192 Trial; else Multichain. Trial keys: max ${RECIPIENT_LIMIT_TRIAL} recipients per call, BNB Chain + USDC/USDT only. Multichain keys: max ${RECIPIENT_LIMIT_PAID} recipients per call across 7 EIP-7702 default chains (avax, bnb, eth, mantle, injective, monad, scroll). xlayer + stable are NOT batchable \u2014 use q402_pay in a loop. AMBIGUITY GATE: when auto would land on Trial AND recipients.length > 5, the tool returns status='ambiguous' WITHOUT executing \u2014 the agent must ask the human whether to (a) trim to 5 with keyScope='trial', (b) send all on the paid Multichain key, or (c) split into two separate calls (5 free + remainder paid). Re-invoke with explicit keyScope after the choice. SANDBOX BY DEFAULT \u2014 real on-chain TX only when the resolved key is live (q402_live_*), Q402_PRIVATE_KEY is set, and Q402_ENABLE_REAL_PAYMENTS=1. Every recipient receives the full amount; the sender pays $0 in gas for the entire batch. ALWAYS get explicit user confirmation of the complete recipient + amount list, chain, and token in conversation immediately before calling this tool \u2014 the user must approve the full batch, not the individual rows.`,
963
+ description: `Send gasless payments to MULTIPLE recipients on a single chain \xD7 token in one call. Auto-routing follows the same rule as q402_pay: chain='bnb' + Q402_TRIAL_API_KEY set \u2192 Trial; else Multichain. Trial keys: max ${RECIPIENT_LIMIT_TRIAL} recipients per call, BNB Chain + USDC/USDT only. Multichain keys: max ${RECIPIENT_LIMIT_PAID} recipients per call across 7 EIP-7702 default chains (avax, bnb, eth, mantle, injective, monad, scroll). xlayer + stable are NOT batchable \u2014 use q402_pay in a loop. AMBIGUITY GATE: when auto would land on Trial AND recipients.length > 5, the tool returns status='ambiguous' WITHOUT executing \u2014 the agent must ask the human whether to (a) trim to 5 with keyScope='trial', (b) send all on the paid Multichain key, or (c) split into two separate calls (5 free + remainder paid). Re-invoke with explicit keyScope after the choice. SANDBOX BY DEFAULT \u2014 real on-chain TX only when the resolved key is live (q402_live_*), Q402_PRIVATE_KEY is set, and Q402_ENABLE_REAL_PAYMENTS=1. Every recipient receives the full amount; the sender pays $0 in gas for the entire batch. Note: same EIP-7702 delegation behaviour as q402_pay \u2014 the first call on a chain creates a persistent set-code delegation on the sender's EOA, reused by subsequent calls. Use q402_clear_delegation to remove. ALWAYS get explicit user confirmation of the complete recipient + amount list, chain, and token in conversation immediately before calling this tool \u2014 the user must approve the full batch, not the individual rows.`,
964
964
  inputSchema: {
965
965
  type: "object",
966
966
  properties: {
@@ -1249,9 +1249,204 @@ var RECEIPT_TOOL = {
1249
1249
  }
1250
1250
  };
1251
1251
 
1252
+ // src/tools/wallet-status.ts
1253
+ import { z as z6 } from "zod";
1254
+ import { Wallet as Wallet2 } from "ethers";
1255
+ var WalletStatusInputSchema = z6.object({});
1256
+ async function runWalletStatus() {
1257
+ if (!CONFIG.privateKey) {
1258
+ return {
1259
+ error: "MISSING_PRIVATE_KEY",
1260
+ hint: "Set Q402_PRIVATE_KEY in the MCP environment so this tool can derive the EOA to inspect."
1261
+ };
1262
+ }
1263
+ let address;
1264
+ try {
1265
+ address = new Wallet2(CONFIG.privateKey).address;
1266
+ } catch {
1267
+ return {
1268
+ error: "INVALID_PRIVATE_KEY",
1269
+ hint: "Q402_PRIVATE_KEY is set but does not parse as a valid 32-byte hex private key."
1270
+ };
1271
+ }
1272
+ const url = `${CONFIG.relayBaseUrl.replace(/\/$/, "")}/wallet/delegation-status?address=${address}`;
1273
+ let body;
1274
+ try {
1275
+ const res = await fetch(url);
1276
+ body = await res.json();
1277
+ if (!res.ok) {
1278
+ return {
1279
+ address,
1280
+ error: typeof body === "object" && body && "error" in body ? String(body.error) : `HTTP ${res.status}`
1281
+ };
1282
+ }
1283
+ } catch (e) {
1284
+ return {
1285
+ address,
1286
+ error: e instanceof Error ? e.message : String(e)
1287
+ };
1288
+ }
1289
+ const parsed = body;
1290
+ return {
1291
+ address: parsed.address,
1292
+ chains: parsed.chains,
1293
+ summary: parsed.summary
1294
+ };
1295
+ }
1296
+ var WALLET_STATUS_TOOL = {
1297
+ name: "q402_wallet_status",
1298
+ description: "Report the EIP-7702 delegation status of your Q402 wallet (the EOA derived from Q402_PRIVATE_KEY) across all 9 Q402-supported chains. Returns per-chain { delegated, impl } and a one-line summary. Read-only \u2014 no signing, no on-chain TX, no quota consumption. Use this before q402_clear_delegation to figure out which chains need a cleanup, or when answering 'why is my wallet showing Smart account?' Requires Q402_PRIVATE_KEY in env (same as q402_pay).",
1299
+ inputSchema: {
1300
+ type: "object",
1301
+ properties: {},
1302
+ additionalProperties: false
1303
+ }
1304
+ };
1305
+
1306
+ // src/tools/clear-delegation.ts
1307
+ import { z as z7 } from "zod";
1308
+ import { Wallet as Wallet3, JsonRpcProvider as JsonRpcProvider2 } from "ethers";
1309
+ var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
1310
+ var DEFAULT_RPC2 = {
1311
+ 1: "https://ethereum.publicnode.com",
1312
+ 56: "https://bsc-dataseed1.binance.org/",
1313
+ 143: "https://rpc.monad.xyz",
1314
+ 196: "https://rpc.xlayer.tech",
1315
+ 988: "https://rpc.stable.xyz",
1316
+ 1776: "https://sentry.evm-rpc.injective.network/",
1317
+ 5e3: "https://rpc.mantle.xyz",
1318
+ 43114: "https://api.avax.network/ext/bc/C/rpc",
1319
+ 534352: "https://rpc.scroll.io"
1320
+ };
1321
+ var ClearDelegationInputSchema = z7.object({
1322
+ chain: z7.enum(["avax", "bnb", "eth", "xlayer", "stable", "mantle", "injective", "monad", "scroll"]).describe("Which Q402 chain to clear the delegation on.")
1323
+ });
1324
+ async function runClearDelegation(input) {
1325
+ if (!CONFIG.privateKey) {
1326
+ return {
1327
+ ok: false,
1328
+ error: "MISSING_PRIVATE_KEY",
1329
+ hint: "Set Q402_PRIVATE_KEY in the MCP environment \u2014 same key q402_pay uses. The MCP tool signs locally and never sends the key to Q402."
1330
+ };
1331
+ }
1332
+ const cfg = CHAIN_CONFIG[input.chain];
1333
+ if (!cfg) {
1334
+ return { ok: false, error: "INVALID_CHAIN", hint: `Unknown chain: ${input.chain}` };
1335
+ }
1336
+ let wallet;
1337
+ try {
1338
+ const provider = new JsonRpcProvider2(DEFAULT_RPC2[cfg.chainId]);
1339
+ wallet = new Wallet3(CONFIG.privateKey, provider);
1340
+ } catch {
1341
+ return {
1342
+ ok: false,
1343
+ error: "INVALID_PRIVATE_KEY",
1344
+ hint: "Q402_PRIVATE_KEY is set but does not parse as a valid 32-byte hex private key."
1345
+ };
1346
+ }
1347
+ const address = wallet.address;
1348
+ let nonce;
1349
+ try {
1350
+ nonce = await wallet.provider.getTransactionCount(address);
1351
+ } catch (e) {
1352
+ return {
1353
+ ok: false,
1354
+ address,
1355
+ error: "RPC_FAILED",
1356
+ hint: `Could not read transaction count for ${address} on ${input.chain}: ${e instanceof Error ? e.message : String(e)}`
1357
+ };
1358
+ }
1359
+ let auth;
1360
+ try {
1361
+ auth = await wallet.authorize({
1362
+ chainId: cfg.chainId,
1363
+ address: ZERO_ADDRESS,
1364
+ nonce
1365
+ });
1366
+ } catch (e) {
1367
+ return {
1368
+ ok: false,
1369
+ address,
1370
+ error: "SIGN_FAILED",
1371
+ hint: `Local signing failed: ${e instanceof Error ? e.message : String(e)}`
1372
+ };
1373
+ }
1374
+ const url = `${CONFIG.relayBaseUrl.replace(/\/$/, "")}/wallet/clear-delegation`;
1375
+ const body = {
1376
+ chain: input.chain,
1377
+ address,
1378
+ authorization: {
1379
+ chainId: Number(auth.chainId),
1380
+ address: auth.address,
1381
+ nonce: Number(auth.nonce),
1382
+ yParity: auth.signature.yParity,
1383
+ r: auth.signature.r,
1384
+ s: auth.signature.s
1385
+ }
1386
+ };
1387
+ let res;
1388
+ let json;
1389
+ try {
1390
+ res = await fetch(url, {
1391
+ method: "POST",
1392
+ headers: { "Content-Type": "application/json" },
1393
+ body: JSON.stringify(body)
1394
+ });
1395
+ json = await res.json();
1396
+ } catch (e) {
1397
+ return {
1398
+ ok: false,
1399
+ address,
1400
+ error: "RELAY_UNREACHABLE",
1401
+ hint: `Could not reach Q402 relay at ${url}: ${e instanceof Error ? e.message : String(e)}`
1402
+ };
1403
+ }
1404
+ const payload = json;
1405
+ if (!res.ok || payload.cleared !== true) {
1406
+ return {
1407
+ ok: false,
1408
+ chain: input.chain,
1409
+ address,
1410
+ txHash: payload.txHash,
1411
+ blockNumber: payload.blockNumber,
1412
+ gasUsed: payload.gasUsed,
1413
+ cleared: payload.cleared ?? false,
1414
+ explorerUrl: payload.explorerUrl,
1415
+ error: payload.error ?? `HTTP ${res.status}`,
1416
+ hint: payload.reason ?? "The sponsored TX did not clear the delegation. If a txHash is present, the broadcast confirmed but the EOA's code is still non-empty (commonly a stale nonce) \u2014 refresh and retry."
1417
+ };
1418
+ }
1419
+ return {
1420
+ ok: true,
1421
+ chain: input.chain,
1422
+ address,
1423
+ txHash: payload.txHash,
1424
+ blockNumber: payload.blockNumber,
1425
+ gasUsed: payload.gasUsed,
1426
+ cleared: true,
1427
+ explorerUrl: payload.explorerUrl
1428
+ };
1429
+ }
1430
+ var CLEAR_DELEGATION_TOOL = {
1431
+ name: "q402_clear_delegation",
1432
+ description: "Clear the EIP-7702 delegation on a Q402 chain for the configured wallet. After your first q402_pay on a chain, Q402 delegates your EOA to a vetted implementation contract (Pectra set-code transaction) so subsequent payments are gasless without redoing the authorization each time. The delegation persists until explicitly cleared. Call this when: (a) the user wants to receive native gas tokens (BNB/ ETH/etc.) directly to their EOA without revert, (b) the wallet UI is showing a 'Smart account' indicator the user wants to remove, or (c) the user explicitly asks to 'clean up' or 'reset' the delegation. Do NOT call this immediately before another q402_pay on the same chain \u2014 the next payment would just re-create the delegation, wasting one TX. Pair with q402_wallet_status first to see which chains actually have an active delegation. Signing happens locally with Q402_PRIVATE_KEY; the signed authorization is POSTed to Q402 which broadcasts the type-0x04 TX from a sponsor wallet \u2014 the user pays zero gas. Requires Q402_PRIVATE_KEY in env.",
1433
+ inputSchema: {
1434
+ type: "object",
1435
+ properties: {
1436
+ chain: {
1437
+ type: "string",
1438
+ enum: CHAIN_KEYS,
1439
+ description: "Which Q402 chain to clear the delegation on."
1440
+ }
1441
+ },
1442
+ required: ["chain"],
1443
+ additionalProperties: false
1444
+ }
1445
+ };
1446
+
1252
1447
  // src/index.ts
1253
1448
  var PACKAGE_NAME = "@quackai/q402-mcp";
1254
- var PACKAGE_VERSION = "0.5.1";
1449
+ var PACKAGE_VERSION = "0.5.3";
1255
1450
  function jsonText(value) {
1256
1451
  return { type: "text", text: JSON.stringify(value, null, 2) };
1257
1452
  }
@@ -1261,7 +1456,15 @@ async function main() {
1261
1456
  { capabilities: { tools: {} } }
1262
1457
  );
1263
1458
  server.setRequestHandler(ListToolsRequestSchema, async () => ({
1264
- tools: [QUOTE_TOOL, BALANCE_TOOL, PAY_TOOL, BATCH_PAY_TOOL, RECEIPT_TOOL]
1459
+ tools: [
1460
+ QUOTE_TOOL,
1461
+ BALANCE_TOOL,
1462
+ PAY_TOOL,
1463
+ BATCH_PAY_TOOL,
1464
+ RECEIPT_TOOL,
1465
+ WALLET_STATUS_TOOL,
1466
+ CLEAR_DELEGATION_TOOL
1467
+ ]
1265
1468
  }));
1266
1469
  server.setRequestHandler(CallToolRequestSchema, async (req) => {
1267
1470
  const { name, arguments: args } = req.params;
@@ -1287,6 +1490,14 @@ async function main() {
1287
1490
  const parsed = ReceiptInputSchema.parse(args ?? {});
1288
1491
  return { content: [jsonText(await runReceipt(parsed))] };
1289
1492
  }
1493
+ case "q402_wallet_status": {
1494
+ WalletStatusInputSchema.parse(args ?? {});
1495
+ return { content: [jsonText(await runWalletStatus())] };
1496
+ }
1497
+ case "q402_clear_delegation": {
1498
+ const parsed = ClearDelegationInputSchema.parse(args ?? {});
1499
+ return { content: [jsonText(await runClearDelegation(parsed))] };
1500
+ }
1290
1501
  default:
1291
1502
  return {
1292
1503
  isError: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quackai/q402-mcp",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "description": "MCP server for Q402 — gasless USDC, USDT, and RLUSD payments across 9 EVM chains, callable from Claude (Desktop / Code), OpenAI Codex CLI, and any other Model Context Protocol client.",
5
5
  "mcpName": "io.github.bitgett/q402-mcp",
6
6
  "keywords": [