z-zero-mcp-server 1.8.0 → 1.9.0

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.
@@ -19,7 +19,14 @@ export declare function postReceiptRemote(payload: {
19
19
  merchant_order_id?: string | null;
20
20
  amount_captured?: number;
21
21
  card_last4?: string;
22
+ /** The purpose record — signed into the receipt alongside the outcome. */
23
+ recheck?: {
24
+ page_shows: string;
25
+ decision: "go" | "pause";
26
+ why?: string;
27
+ };
22
28
  }): Promise<any | null>;
29
+ export declare function getTokenPurposeRemote(token: string): Promise<any>;
23
30
  export declare function resolveTokenRemote(token: string): Promise<CardData | null>;
24
31
  export declare function burnTokenRemote(token: string, receipt_id?: string): Promise<boolean>;
25
32
  export declare function cancelTokenRemote(token: string): Promise<any>;
@@ -12,6 +12,7 @@ exports.getBalanceRemote = getBalanceRemote;
12
12
  exports.getDepositAddressesRemote = getDepositAddressesRemote;
13
13
  exports.issueTokenRemote = issueTokenRemote;
14
14
  exports.postReceiptRemote = postReceiptRemote;
15
+ exports.getTokenPurposeRemote = getTokenPurposeRemote;
15
16
  exports.resolveTokenRemote = resolveTokenRemote;
16
17
  exports.burnTokenRemote = burnTokenRemote;
17
18
  exports.cancelTokenRemote = cancelTokenRemote;
@@ -259,6 +260,14 @@ async function postReceiptRemote(payload) {
259
260
  // ──────────────────────────────────────────────────────────────────────────────
260
261
  // Resolve Token: Same as custodial (returns PAN/CVV for Playwright injection)
261
262
  // ──────────────────────────────────────────────────────────────────────────────
263
+ // ──────────────────────────────────────────────────────────────────────────────
264
+ // Purpose: the criteria this card was issued against, straight from the server.
265
+ // Deliberately NOT part of resolve — resolve pulls a real PAN from the issuer,
266
+ // and asking "what was this for?" must never cost a card fetch.
267
+ // ──────────────────────────────────────────────────────────────────────────────
268
+ async function getTokenPurposeRemote(token) {
269
+ return await apiRequest('/api/tokens/purpose', 'POST', { token });
270
+ }
262
271
  async function resolveTokenRemote(token) {
263
272
  const data = await internalApiRequest('/api/tokens/resolve', 'POST', { token });
264
273
  if (!data || data.error)
package/dist/index.js CHANGED
@@ -57,6 +57,7 @@ const postReceiptRemote = activeBackend.postReceiptRemote;
57
57
  const getBalanceRemote = activeBackend.getBalanceRemote;
58
58
  const listCardsRemote = activeBackend.listCardsRemote;
59
59
  const getDepositAddressesRemote = activeBackend.getDepositAddressesRemote;
60
+ const getTokenPurposeRemote = activeBackend.getTokenPurposeRemote;
60
61
  console.error(`[Z-ZERO MCP] 🚀 Base + USDC (non-custodial, gasless)`);
61
62
  // ────────────────────────────────────────────────────────────────────────────
62
63
  const playwright_bridge_js_1 = require("./playwright_bridge.js");
@@ -244,7 +245,7 @@ server.tool("get_deposit_addresses", "Get your Base deposit address to top up yo
244
245
  // TOOL 3: Request a temporary payment token (issues secure JIT card)
245
246
  // ============================================================
246
247
  server.tool("request_payment_token", "Request a single-use JIT virtual card ($1–$100) locked to one amount + merchant. ⚠️ Read mcp://resources/sop first. Only call once the FINAL total is visible — for physical goods that is AFTER shipping is submitted (use get_merchant_hints to navigate there). For digital goods with the price already visible, prefer auto_pay_checkout instead. " +
247
- "BEFORE requesting: look at the checkout page one more time and compare it against what the user actually asked for — same items, same quantity, same variant, same destination? If anything differs, do NOT request a token; fix the cart or check with the user first. A mismatch you catch here costs nothing; after this point it costs a card. If you pass `cart`, the server signs your declared intent and binds the card to it — the user gets cryptographic proof of what this card was authorized for.", {
248
+ "BEFORE requesting: look at the checkout page one more time and compare it against what the user actually asked for — same items, same quantity, same variant, same destination? If anything differs, do NOT request a token; fix the cart or check with the user first. A mismatch you catch here costs nothing; after this point it costs a card. If you pass `cart`, the server signs your declared intent and binds the card to it — the user gets cryptographic proof of what this card was authorized for. Pass `criteria` too: the few things the owner actually cared about, which this purchase gets scored against at payment time.", {
248
249
  card_alias: zod_1.z
249
250
  .string()
250
251
  .describe("Which card to charge, e.g. 'Card_01'"),
@@ -270,14 +271,34 @@ server.tool("request_payment_token", "Request a single-use JIT virtual card ($1
270
271
  .string()
271
272
  .optional()
272
273
  .describe("Shipping destination as a single string (only a hash is stored, never the raw address)."),
273
- }, async ({ card_alias, amount, merchant, cart, ship_to }) => {
274
- const intentInput = (cart && cart.length) || ship_to
274
+ criteria: zod_1.z
275
+ .object({
276
+ source: zod_1.z
277
+ .enum(["user_link", "user_described", "agent_chose"])
278
+ .describe("Where the choice of THIS product came from. 'user_link' = they gave you the link, so the product is their pick, not yours."),
279
+ items: zod_1.z
280
+ .array(zod_1.z.object({
281
+ key: zod_1.z.string().describe("Short name for the attribute, e.g. item_type, max_price, colour, size, ship_time."),
282
+ stated: zod_1.z.string().describe("What the owner said about it, in their terms."),
283
+ }))
284
+ .min(1)
285
+ .max(12),
286
+ })
287
+ .optional()
288
+ .describe("RECOMMENDED. The things this purchase will be judged against later — write ONLY what the owner actually stated. " +
289
+ "Attributes like price, colour, size, product type or delivery time are examples of the KIND of thing that belongs here, " +
290
+ "not a checklist to fill: an owner who said \"a hat, $10\" gave you exactly two, and inventing three more would mark a good " +
291
+ "purchase as wrong. If they changed their mind, record where they LANDED, not the journey. " +
292
+ "This list is locked and signed now, before the outcome is known, and you will be asked to score against it at payment time."),
293
+ }, async ({ card_alias, amount, merchant, cart, ship_to, criteria }) => {
294
+ const intentInput = (cart && cart.length) || ship_to || criteria
275
295
  ? {
276
296
  cart,
277
297
  subtotal: cart?.every(i => typeof i.unit_price === "number")
278
298
  ? Math.round(cart.reduce((s, i) => s + i.unit_price * i.qty, 0) * 100) / 100
279
299
  : undefined,
280
300
  ship_to,
301
+ criteria,
281
302
  }
282
303
  : undefined;
283
304
  const token = await issueTokenRemote(card_alias, amount, merchant, intentInput);
@@ -380,7 +401,7 @@ server.tool("get_merchant_hints", "Get merchant navigation flow for a domain or
380
401
  // ============================================================
381
402
  // TOOL 4b: Execute payment (The "Invisible Hand")
382
403
  // ============================================================
383
- server.tool("execute_payment", "Execute a payment with a one-time token: Z-Zero opens a headless browser, injects the card (you NEVER see the PAN), clicks Pay, then watches for a REAL confirmation before reporting success. Returns a `status`: `confirmed` (order placed → token burned, receipt_id may hold a real order #), `declined` (merchant rejected → token kept for refund), `unconfirmed` (submitted but no confirmation seen → do NOT retry blindly, verify first), `not_submitted` (no Pay button → supply a submit_selector hint), or `no_fields`. ALWAYS pass actual_amount so overcharges are blocked and underspend refunded.", {
404
+ server.tool("execute_payment", "Execute a payment with a one-time token. TWO CALLS: call it first WITHOUT `recheck` — nothing is charged and it hands you what the owner actually asked for, locked when the card was issued; look at the page again, then call it a second time with `recheck` to pay or to pause. Then Z-Zero opens a headless browser, injects the card (you NEVER see the PAN), clicks Pay, and watches for a REAL confirmation before reporting success. Returns a `status`: `confirmed` (order placed → token burned, receipt_id may hold a real order #), `declined` (merchant rejected → token kept for refund), `unconfirmed` (submitted but no confirmation seen → do NOT retry blindly, verify first), `not_submitted` (no Pay button → supply a submit_selector hint), or `no_fields`. ALWAYS pass actual_amount so overcharges are blocked and underspend refunded.", {
384
405
  token: zod_1.z
385
406
  .string()
386
407
  .describe("The temporary payment token from request_payment_token"),
@@ -405,7 +426,86 @@ server.tool("execute_payment", "Execute a payment with a one-time token: Z-Zero
405
426
  })
406
427
  .optional()
407
428
  .describe("Optional hints from get_merchant_hints — selectors and pre-steps to guide Playwright. Use when default selectors fail or for complex multi-step checkouts."),
408
- }, async ({ token, checkout_url, actual_amount, hints }) => {
429
+ recheck: zod_1.z
430
+ .object({
431
+ page_shows: zod_1.z
432
+ .string()
433
+ .min(1)
434
+ .describe("What is ACTUALLY on the page in front of you right now — item, variant, quantity, final total. Describe it, do not summarise it as 'looks right'."),
435
+ decision: zod_1.z
436
+ .enum(["go", "pause"])
437
+ .describe("go = pay it. pause = something is off; nothing is charged, the card is not typed in, the money stays put and you tell your owner."),
438
+ why: zod_1.z
439
+ .string()
440
+ .optional()
441
+ .describe("Required when you pause: what did not line up."),
442
+ })
443
+ .optional()
444
+ .describe("Your answer to the purpose check. Omit it on the first call — this tool will hand you the owner's locked criteria to read, then you call again with this."),
445
+ }, async ({ token, checkout_url, actual_amount, hints, recheck }) => {
446
+ // ── Purpose check: the last look before there is no way back ─────────
447
+ // Called with no `recheck`, this tool does not pay. It hands back the
448
+ // criteria the owner stated, locked at issue, and asks for an answer.
449
+ // The question comes from the server on purpose: an agent that quotes it
450
+ // from its own memory can soften it until anything matches.
451
+ // No browser, no PAN, nothing spent — asking is free.
452
+ if (!recheck) {
453
+ const purpose = await getTokenPurposeRemote(token);
454
+ if (purpose?.error === "AUTH_REQUIRED")
455
+ return authRequiredResult(purpose.message);
456
+ // A dead token should say so HERE, not send the agent off to look at a
457
+ // page and come back for a second call that was always going to fail.
458
+ if (purpose?.error) {
459
+ return {
460
+ content: [{
461
+ type: "text",
462
+ text: JSON.stringify({
463
+ success: false,
464
+ status: "invalid_token",
465
+ nothing_charged: true,
466
+ message: purpose.message || "Token is invalid, expired, cancelled, or already used. Request a new one.",
467
+ }, null, 2),
468
+ }],
469
+ isError: true,
470
+ };
471
+ }
472
+ const criteria = purpose?.criteria ?? null;
473
+ return {
474
+ content: [{
475
+ type: "text",
476
+ text: JSON.stringify({
477
+ status: "purpose_check",
478
+ nothing_charged: true,
479
+ owner_asked_for: criteria ?? "(no criteria were recorded for this card)",
480
+ authorized_amount: purpose?.authorized_amount ?? null,
481
+ what_to_do: "Look at the checkout page one more time. Write down what is actually there — " +
482
+ "item, variant, quantity, final total — and put it next to what the owner asked for above. " +
483
+ "Then call execute_payment again with `recheck`. If they do not line up, pause: " +
484
+ "nothing is charged and the money stays where it is. Catching it here costs nothing; " +
485
+ "after this call it costs a card.",
486
+ }, null, 2),
487
+ }],
488
+ };
489
+ }
490
+ if (recheck.decision === "pause") {
491
+ // The agent's own verdict. We do not overrule it, and we do not
492
+ // spend on it: the card is never typed in, the token stays alive and
493
+ // refundable, and the human gets told.
494
+ return {
495
+ content: [{
496
+ type: "text",
497
+ text: JSON.stringify({
498
+ success: false,
499
+ status: "paused_by_agent",
500
+ nothing_charged: true,
501
+ token_status: "ACTIVE",
502
+ page_shows: recheck.page_shows,
503
+ why: recheck.why ?? null,
504
+ next: "Tell your owner what did not line up and wait. To release the hold instead, call cancel_payment_token.",
505
+ }, null, 2),
506
+ }],
507
+ };
508
+ }
409
509
  // Step 0: SSRF / scheme guard BEFORE we drive a browser to this URL and inject a real PAN/CVV.
410
510
  try {
411
511
  (0, url_guard_js_1.assertSafeCheckoutUrl)(checkout_url);
@@ -537,6 +637,9 @@ server.tool("execute_payment", "Execute a payment with a one-time token: Z-Zero
537
637
  merchant_order_id: result.receipt_id || null,
538
638
  amount_captured: actual_amount,
539
639
  card_last4: cardData.number ? cardData.number.replace(/\D/g, "").slice(-4) : undefined,
640
+ // The purpose record travels into the signed receipt: the owner's
641
+ // locked criteria and the agent's answer, sealed with the outcome.
642
+ recheck,
540
643
  }).catch(() => null);
541
644
  // Step 5: Return result (NEVER includes card numbers)
542
645
  return {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Throws if `rawUrl` is not a safe public checkout URL.
3
3
  * - must parse as a URL
4
- * - must be HTTPS (except localhost/127.0.0.1 in non-production, for local testing)
4
+ * - must be HTTPS (except a loopback host when local checkout is explicitly enabled)
5
5
  * - must not resolve to a private / loopback / link-local host (SSRF)
6
6
  */
7
7
  export declare function assertSafeCheckoutUrl(rawUrl: string): void;
@@ -20,7 +20,7 @@ const PRIVATE_HOST_PATTERNS = [
20
20
  /**
21
21
  * Throws if `rawUrl` is not a safe public checkout URL.
22
22
  * - must parse as a URL
23
- * - must be HTTPS (except localhost/127.0.0.1 in non-production, for local testing)
23
+ * - must be HTTPS (except a loopback host when local checkout is explicitly enabled)
24
24
  * - must not resolve to a private / loopback / link-local host (SSRF)
25
25
  */
26
26
  function assertSafeCheckoutUrl(rawUrl) {
@@ -32,10 +32,23 @@ function assertSafeCheckoutUrl(rawUrl) {
32
32
  throw new Error(`Invalid checkout_url: ${rawUrl}`);
33
33
  }
34
34
  const hostname = url.hostname;
35
- const isDev = process.env.NODE_ENV !== "production";
36
- const isLocalDev = isDev && (hostname === "localhost" || hostname === "127.0.0.1");
37
- if (isLocalDev)
38
- return;
35
+ // Loopback checkout targets are an EXPLICIT opt-in, never a side effect of
36
+ // NODE_ENV. This server runs on the end user's machine, where NODE_ENV is
37
+ // essentially never "production" — so keying the bypass off that flag left it
38
+ // permanently open in the one place it has to stay shut: this is the call that
39
+ // decides where a real PAN/CVV gets typed. Opting in also waives the HTTPS
40
+ // requirement, which is why it must be a deliberate act by the machine's owner.
41
+ if (hostname === "localhost" || hostname === "127.0.0.1") {
42
+ if (process.env.Z_ZERO_ALLOW_LOCAL_CHECKOUT === "1") {
43
+ console.error(`[URL-GUARD] ⚠️ Local checkout allowed for ${hostname} — ` +
44
+ `Z_ZERO_ALLOW_LOCAL_CHECKOUT=1 is set. Real card data will be typed into a local page. ` +
45
+ `Unset it outside of testing.`);
46
+ return;
47
+ }
48
+ throw new Error(`SSRF blocked host: ${hostname}. Checkout must be a public HTTPS page — ` +
49
+ `a local address would receive real card data. ` +
50
+ `For local testing only, set Z_ZERO_ALLOW_LOCAL_CHECKOUT=1.`);
51
+ }
39
52
  if (url.protocol !== "https:") {
40
53
  throw new Error("checkout_url must use HTTPS.");
41
54
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "z-zero-mcp-server",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
4
4
  "description": "Z-ZERO MCP Server — Secure JIT Virtual Card Payment tools for AI Agents (Claude, Cursor, AutoGPT) — Real Single-Use Virtual Cards, settled in USDC on Base",
5
5
  "main": "dist/index.js",
6
6
  "bin": {