z-zero-mcp-server 1.9.0 → 1.10.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.
- package/README.md +56 -15
- package/dist/base_backend.js +50 -0
- package/dist/index.js +385 -155
- package/dist/ucp_bridge.d.ts +166 -0
- package/dist/ucp_bridge.js +886 -0
- package/package.json +4 -1
- package/dist/mock_backend.d.ts +0 -32
- package/dist/mock_backend.js +0 -150
package/dist/index.js
CHANGED
|
@@ -61,6 +61,7 @@ const getTokenPurposeRemote = activeBackend.getTokenPurposeRemote;
|
|
|
61
61
|
console.error(`[Z-ZERO MCP] 🚀 Base + USDC (non-custodial, gasless)`);
|
|
62
62
|
// ────────────────────────────────────────────────────────────────────────────
|
|
63
63
|
const playwright_bridge_js_1 = require("./playwright_bridge.js");
|
|
64
|
+
const ucp_bridge_js_1 = require("./ucp_bridge.js");
|
|
64
65
|
const web3_detector_js_1 = require("./lib/web3-detector.js");
|
|
65
66
|
const extract_total_price_js_1 = require("./lib/extract-total-price.js");
|
|
66
67
|
const playwright_1 = require("playwright");
|
|
@@ -133,9 +134,29 @@ function authRequiredResult(detail) {
|
|
|
133
134
|
};
|
|
134
135
|
}
|
|
135
136
|
// ============================================================
|
|
137
|
+
// QUY ƯỚC ANNOTATIONS (xem docs/mcp_hardening_plan_22_08_26.md §W1)
|
|
138
|
+
// openWorldHint = true → TẠI THỜI ĐIỂM GỌI tool chạm ra ngoài control plane
|
|
139
|
+
// Z-ZERO: merchant, issuer (Airwallex), hoặc public chain (Base).
|
|
140
|
+
// openWorldHint = false → chỉ đọc/ghi DB & API của Z-ZERO, hoặc thuần local — KỂ CẢ khi
|
|
141
|
+
// dữ liệu có nguồn gốc issuer nhưng đã reconcile sẵn vào DB
|
|
142
|
+
// (vì vậy verify_receipt = false).
|
|
143
|
+
// destructiveHint → theo spec MCP là 'destructive vs additive', KHÔNG phải
|
|
144
|
+
// 'nguy hiểm' và KHÔNG phải 'không đảo ngược được'.
|
|
145
|
+
// idempotentHint → chỉ khai khi readOnlyHint === false.
|
|
146
|
+
// Annotations là HINT, không phải hàng rào bảo mật. Chống double-charge là việc của
|
|
147
|
+
// idempotency_key ở backend, không phải của idempotentHint.
|
|
148
|
+
// ============================================================
|
|
136
149
|
// TOOL 1: List available cards (safe - no sensitive data)
|
|
137
150
|
// ============================================================
|
|
138
|
-
server.
|
|
151
|
+
server.registerTool("list_cards", {
|
|
152
|
+
title: "List Cards",
|
|
153
|
+
description: "List all available virtual card aliases and their balances. No sensitive data is returned.",
|
|
154
|
+
inputSchema: {},
|
|
155
|
+
annotations: {
|
|
156
|
+
readOnlyHint: true,
|
|
157
|
+
openWorldHint: false,
|
|
158
|
+
},
|
|
159
|
+
}, async () => {
|
|
139
160
|
const data = await listCardsRemote();
|
|
140
161
|
if (data?.error === "AUTH_REQUIRED")
|
|
141
162
|
return authRequiredResult(data.message);
|
|
@@ -171,10 +192,18 @@ server.tool("list_cards", "List all available virtual card aliases and their bal
|
|
|
171
192
|
// ============================================================
|
|
172
193
|
// TOOL 2: Check card balance (safe)
|
|
173
194
|
// ============================================================
|
|
174
|
-
server.
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
195
|
+
server.registerTool("check_balance", {
|
|
196
|
+
title: "Check Balance",
|
|
197
|
+
description: "Check spendable USD balance for a card alias. For active token limits, use list_cards instead.",
|
|
198
|
+
inputSchema: {
|
|
199
|
+
card_alias: zod_1.z
|
|
200
|
+
.string()
|
|
201
|
+
.describe("The alias of the card to check, e.g. 'Card_01'"),
|
|
202
|
+
},
|
|
203
|
+
annotations: {
|
|
204
|
+
readOnlyHint: true,
|
|
205
|
+
openWorldHint: true,
|
|
206
|
+
},
|
|
178
207
|
}, async ({ card_alias }) => {
|
|
179
208
|
const data = await getBalanceRemote(card_alias);
|
|
180
209
|
if (data?.error === "AUTH_REQUIRED")
|
|
@@ -206,7 +235,15 @@ server.tool("check_balance", "Check spendable USD balance for a card alias. For
|
|
|
206
235
|
// ============================================================
|
|
207
236
|
// TOOL 2.5: Get deposit addresses (Phase 14 feature)
|
|
208
237
|
// ============================================================
|
|
209
|
-
server.
|
|
238
|
+
server.registerTool("get_deposit_addresses", {
|
|
239
|
+
title: "Get Deposit Address",
|
|
240
|
+
description: "Get your Base deposit address to top up your wallet with USDC (or any supported stablecoin on Base).",
|
|
241
|
+
inputSchema: {},
|
|
242
|
+
annotations: {
|
|
243
|
+
readOnlyHint: true,
|
|
244
|
+
openWorldHint: true,
|
|
245
|
+
},
|
|
246
|
+
}, async () => {
|
|
210
247
|
const data = await getDepositAddressesRemote();
|
|
211
248
|
if (data?.error === "AUTH_REQUIRED")
|
|
212
249
|
return authRequiredResult(data.message);
|
|
@@ -244,52 +281,62 @@ server.tool("get_deposit_addresses", "Get your Base deposit address to top up yo
|
|
|
244
281
|
// ============================================================
|
|
245
282
|
// TOOL 3: Request a temporary payment token (issues secure JIT card)
|
|
246
283
|
// ============================================================
|
|
247
|
-
server.
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
.
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
unit_price: zod_1.z.number().optional().describe("Unit price if visible"),
|
|
265
|
-
url: zod_1.z.string().optional().describe("Product URL if known"),
|
|
266
|
-
}))
|
|
267
|
-
.max(50)
|
|
268
|
-
.optional()
|
|
269
|
-
.describe("RECOMMENDED: the items you are buying, as the USER agreed to them. This becomes a signed intent bound to the card — proof of what was authorized."),
|
|
270
|
-
ship_to: zod_1.z
|
|
271
|
-
.string()
|
|
272
|
-
.optional()
|
|
273
|
-
.describe("Shipping destination as a single string (only a hash is stored, never the raw address)."),
|
|
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
|
|
284
|
+
server.registerTool("request_payment_token", {
|
|
285
|
+
title: "Issue JIT Card (spends $0.10 fee)",
|
|
286
|
+
description: "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. " +
|
|
287
|
+
"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.",
|
|
288
|
+
inputSchema: {
|
|
289
|
+
card_alias: zod_1.z
|
|
290
|
+
.string()
|
|
291
|
+
.describe("Which card to charge, e.g. 'Card_01'"),
|
|
292
|
+
amount: zod_1.z
|
|
293
|
+
.number()
|
|
294
|
+
.min(1, "Minimum amount is $1.00")
|
|
295
|
+
.max(100, "Maximum amount is $100.00")
|
|
296
|
+
.describe("Amount in USD to authorize (min: $1, max: $100)"),
|
|
297
|
+
merchant: zod_1.z
|
|
298
|
+
.string()
|
|
299
|
+
.describe("Name or URL of the merchant/service being purchased"),
|
|
300
|
+
cart: zod_1.z
|
|
280
301
|
.array(zod_1.z.object({
|
|
281
|
-
|
|
282
|
-
|
|
302
|
+
title: zod_1.z.string().describe("Item name as shown on the checkout page"),
|
|
303
|
+
qty: zod_1.z.number().describe("Quantity"),
|
|
304
|
+
unit_price: zod_1.z.number().optional().describe("Unit price if visible"),
|
|
305
|
+
url: zod_1.z.string().optional().describe("Product URL if known"),
|
|
283
306
|
}))
|
|
284
|
-
.
|
|
285
|
-
.
|
|
286
|
-
|
|
287
|
-
.
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
307
|
+
.max(50)
|
|
308
|
+
.optional()
|
|
309
|
+
.describe("RECOMMENDED: the items you are buying, as the USER agreed to them. This becomes a signed intent bound to the card — proof of what was authorized."),
|
|
310
|
+
ship_to: zod_1.z
|
|
311
|
+
.string()
|
|
312
|
+
.optional()
|
|
313
|
+
.describe("Shipping destination as a single string (only a hash is stored, never the raw address)."),
|
|
314
|
+
criteria: zod_1.z
|
|
315
|
+
.object({
|
|
316
|
+
source: zod_1.z
|
|
317
|
+
.enum(["user_link", "user_described", "agent_chose"])
|
|
318
|
+
.describe("Where the choice of THIS product came from. 'user_link' = they gave you the link, so the product is their pick, not yours."),
|
|
319
|
+
items: zod_1.z
|
|
320
|
+
.array(zod_1.z.object({
|
|
321
|
+
key: zod_1.z.string().describe("Short name for the attribute, e.g. item_type, max_price, colour, size, ship_time."),
|
|
322
|
+
stated: zod_1.z.string().describe("What the owner said about it, in their terms."),
|
|
323
|
+
}))
|
|
324
|
+
.min(1)
|
|
325
|
+
.max(12),
|
|
326
|
+
})
|
|
327
|
+
.optional()
|
|
328
|
+
.describe("RECOMMENDED. The things this purchase will be judged against later — write ONLY what the owner actually stated. " +
|
|
329
|
+
"Attributes like price, colour, size, product type or delivery time are examples of the KIND of thing that belongs here, " +
|
|
330
|
+
"not a checklist to fill: an owner who said \"a hat, $10\" gave you exactly two, and inventing three more would mark a good " +
|
|
331
|
+
"purchase as wrong. If they changed their mind, record where they LANDED, not the journey. " +
|
|
332
|
+
"This list is locked and signed now, before the outcome is known, and you will be asked to score against it at payment time."),
|
|
333
|
+
},
|
|
334
|
+
annotations: {
|
|
335
|
+
readOnlyHint: false,
|
|
336
|
+
destructiveHint: true,
|
|
337
|
+
idempotentHint: false,
|
|
338
|
+
openWorldHint: true,
|
|
339
|
+
},
|
|
293
340
|
}, async ({ card_alias, amount, merchant, cart, ship_to, criteria }) => {
|
|
294
341
|
const intentInput = (cart && cart.length) || ship_to || criteria
|
|
295
342
|
? {
|
|
@@ -365,10 +412,18 @@ server.tool("request_payment_token", "Request a single-use JIT virtual card ($1
|
|
|
365
412
|
// Agent MUST call this before execute_payment if unsure about a checkout page.
|
|
366
413
|
// Returns domain-specific selectors and pre-steps from Z-ZERO cloud DB.
|
|
367
414
|
// ============================================================
|
|
368
|
-
server.
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
415
|
+
server.registerTool("get_merchant_hints", {
|
|
416
|
+
title: "Merchant Checkout Hints",
|
|
417
|
+
description: "Get merchant navigation flow for a domain or platform key (e.g. '_platform_etsy'). Returns pre_steps (how to navigate checkout) and platform notes. Call BEFORE starting checkout to understand the multi-step flow.",
|
|
418
|
+
inputSchema: {
|
|
419
|
+
domain: zod_1.z
|
|
420
|
+
.string()
|
|
421
|
+
.describe("The main domain of the checkout page, e.g. 'amazon.com' or 'shopify.com'. Strip 'www.' prefix."),
|
|
422
|
+
},
|
|
423
|
+
annotations: {
|
|
424
|
+
readOnlyHint: true,
|
|
425
|
+
openWorldHint: false,
|
|
426
|
+
},
|
|
372
427
|
}, async ({ domain }) => {
|
|
373
428
|
const ZZERO_API = (0, api_base_js_1.resolveApiBaseUrl)();
|
|
374
429
|
const INTERNAL_SECRET = process.env.Z_ZERO_INTERNAL_SECRET || "";
|
|
@@ -399,49 +454,160 @@ server.tool("get_merchant_hints", "Get merchant navigation flow for a domain or
|
|
|
399
454
|
}
|
|
400
455
|
});
|
|
401
456
|
// ============================================================
|
|
457
|
+
// TOOL 3c: UCP probe — the "Official Rail" scout (creates drafts, no money moves)
|
|
458
|
+
// Shopify now ships UCP natively on every store and its robots
|
|
459
|
+
// policy bans browser-automation checkout. This tool checks the
|
|
460
|
+
// UCP lane and returns a REAL merchant quote without any browser
|
|
461
|
+
// and without touching money.
|
|
462
|
+
// ============================================================
|
|
463
|
+
server.registerTool("ucp_probe_checkout", {
|
|
464
|
+
title: "Probe UCP Checkout (creates draft)",
|
|
465
|
+
description: "UCP discovery + quote — creates an UNPAID draft checkout; no money moves; NOT a payment rail yet. Checks whether a merchant speaks UCP (Shopify-native agent commerce), lists its declared payment handlers, and — when variant_gid or query is given — creates a DRAFT checkout and returns the merchant's real quote: total_minor (wire units, 8900 = $89.00), total_major, currency, status, blockers, continue_url. NO payment happens; drafts expire server-side. Completing a UCP checkout needs Shopify Token-tier agent auth, which Z-Zero does not hold yet — to PAY, hand the buyer continue_url or use the standard execute_payment flow where permitted. Call this first on Shopify stores: their robots.txt bans scripted checkout, so the UCP lane is the sanctioned path.",
|
|
466
|
+
inputSchema: {
|
|
467
|
+
shop_url: zod_1.z.string().url().describe("Store URL, e.g. https://meanblvd.com"),
|
|
468
|
+
variant_gid: zod_1.z.string().optional()
|
|
469
|
+
.describe("Exact Shopify variant GID to quote, e.g. gid://shopify/ProductVariant/123"),
|
|
470
|
+
query: zod_1.z.string().optional()
|
|
471
|
+
.describe("Product search query when variant_gid is unknown — first in-stock hit is quoted."),
|
|
472
|
+
quantity: zod_1.z.number().int().min(1).max(10).default(1),
|
|
473
|
+
ship_to: zod_1.z.object({
|
|
474
|
+
first_name: zod_1.z.string().optional(),
|
|
475
|
+
last_name: zod_1.z.string().optional(),
|
|
476
|
+
street_address: zod_1.z.string(),
|
|
477
|
+
address_locality: zod_1.z.string().describe("City"),
|
|
478
|
+
address_region: zod_1.z.string().optional().describe("State/province code, required for US/CA"),
|
|
479
|
+
address_country: zod_1.z.string().describe("ISO 3166-1 alpha-2, e.g. US"),
|
|
480
|
+
postal_code: zod_1.z.string(),
|
|
481
|
+
phone_number: zod_1.z.string().optional(),
|
|
482
|
+
}).optional().describe("Shipping address — supply it to get the REAL total with market pricing + shipping."),
|
|
483
|
+
buyer_email: zod_1.z.string().email().optional(),
|
|
484
|
+
},
|
|
485
|
+
annotations: {
|
|
486
|
+
readOnlyHint: false,
|
|
487
|
+
destructiveHint: false,
|
|
488
|
+
idempotentHint: false,
|
|
489
|
+
openWorldHint: true,
|
|
490
|
+
},
|
|
491
|
+
}, async ({ shop_url, variant_gid, query, quantity, ship_to, buyer_email }) => {
|
|
492
|
+
const reply = (data, isError = false) => ({
|
|
493
|
+
content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
|
|
494
|
+
...(isError ? { isError: true } : {}),
|
|
495
|
+
});
|
|
496
|
+
try {
|
|
497
|
+
(0, url_guard_js_1.assertSafeCheckoutUrl)(shop_url);
|
|
498
|
+
const disc = await (0, ucp_bridge_js_1.ucpDiscover)(shop_url);
|
|
499
|
+
if (!disc) {
|
|
500
|
+
return reply({
|
|
501
|
+
ucp_available: false,
|
|
502
|
+
message: "Merchant does not expose /.well-known/ucp — use the standard get_merchant_hints + execute_payment flow instead.",
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
const base = {
|
|
506
|
+
ucp_available: true,
|
|
507
|
+
ucp_version: disc.version,
|
|
508
|
+
mcp_endpoint: disc.mcpEndpoint,
|
|
509
|
+
payment_handlers: disc.handlers.map((h) => h.handler_name),
|
|
510
|
+
card_lane: disc.cardHandler
|
|
511
|
+
? { handler_id: disc.cardHandler.id, config: disc.cardHandler.config }
|
|
512
|
+
: null,
|
|
513
|
+
note: disc.cardHandler
|
|
514
|
+
? "dev.shopify.card is declared: this store ACCEPTS card instruments over UCP. Quote/cart/checkout work anonymously; complete_checkout requires Shopify Token-tier auth, which this server does not hold — so today the UCP lane gives you discovery + draft + continue_url, not completion."
|
|
515
|
+
: "No card handler declared — card payment not possible on the UCP lane here.",
|
|
516
|
+
};
|
|
517
|
+
if (!variant_gid && !query)
|
|
518
|
+
return reply(base);
|
|
519
|
+
const client = new ucp_bridge_js_1.UcpMcpClient(disc.mcpEndpoint);
|
|
520
|
+
let itemIds = [];
|
|
521
|
+
if (variant_gid) {
|
|
522
|
+
itemIds = [variant_gid];
|
|
523
|
+
}
|
|
524
|
+
else {
|
|
525
|
+
const search = await client.callTool("search_catalog", { meta: {}, catalog: { query, limit: 5 } });
|
|
526
|
+
const blob = JSON.stringify(search);
|
|
527
|
+
itemIds = [...new Set((blob.match(/gid:\\?\/\\?\/shopify\/ProductVariant\/\d+/g) ?? []).map((s) => s.replace(/\\\//g, "/")))].slice(0, 4);
|
|
528
|
+
if (itemIds.length === 0)
|
|
529
|
+
return reply({ ...base, quote: null, message: "No variants found for that query." });
|
|
530
|
+
}
|
|
531
|
+
const email = buyer_email ?? "agent@z-zero.xyz";
|
|
532
|
+
let lastQuote = null;
|
|
533
|
+
for (const itemId of itemIds) {
|
|
534
|
+
const q = await (0, ucp_bridge_js_1.ucpCreateCheckout)(client, [{ item_id: itemId, quantity }], { email }, ship_to);
|
|
535
|
+
const rawCheckout = q.raw?.checkout ?? q.raw ?? {};
|
|
536
|
+
lastQuote = {
|
|
537
|
+
variant: itemId,
|
|
538
|
+
title: rawCheckout?.line_items?.[0]?.item?.title ?? null,
|
|
539
|
+
checkout_id: q.checkout_id || null,
|
|
540
|
+
status: q.status,
|
|
541
|
+
total_minor: q.total_minor,
|
|
542
|
+
total_major: q.total_major,
|
|
543
|
+
currency: q.currency,
|
|
544
|
+
messages: q.messages,
|
|
545
|
+
continue_url: q.continue_url,
|
|
546
|
+
};
|
|
547
|
+
const soldOut = !q.checkout_id || q.messages.some((m) => /out_of_stock|item_unavailable/i.test(m));
|
|
548
|
+
if (!soldOut)
|
|
549
|
+
break;
|
|
550
|
+
}
|
|
551
|
+
return reply({ ...base, quote: lastQuote });
|
|
552
|
+
}
|
|
553
|
+
catch (err) {
|
|
554
|
+
return reply({ ucp_available: null, error: err?.message ?? String(err) }, true);
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
// ============================================================
|
|
402
558
|
// TOOL 4b: Execute payment (The "Invisible Hand")
|
|
403
559
|
// ============================================================
|
|
404
|
-
server.
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
.string()
|
|
410
|
-
.url()
|
|
411
|
-
.describe("The full URL of the checkout/payment page"),
|
|
412
|
-
actual_amount: zod_1.z
|
|
413
|
-
.number()
|
|
414
|
-
.optional()
|
|
415
|
-
.describe("STRONGLY RECOMMENDED. The final total shown on the checkout page (incl. shipping + tax). Enables the overcharge block and the underspend refund — omit only if it is genuinely unreadable."),
|
|
416
|
-
hints: zod_1.z
|
|
417
|
-
.object({
|
|
418
|
-
pre_steps: zod_1.z.array(zod_1.z.string()).optional(),
|
|
419
|
-
card_selector: zod_1.z.string().optional(),
|
|
420
|
-
exp_selector: zod_1.z.string().optional(),
|
|
421
|
-
exp_month_selector: zod_1.z.string().optional(),
|
|
422
|
-
exp_year_selector: zod_1.z.string().optional(),
|
|
423
|
-
cvv_selector: zod_1.z.string().optional(),
|
|
424
|
-
name_selector: zod_1.z.string().optional(),
|
|
425
|
-
submit_selector: zod_1.z.string().optional(),
|
|
426
|
-
})
|
|
427
|
-
.optional()
|
|
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."),
|
|
429
|
-
recheck: zod_1.z
|
|
430
|
-
.object({
|
|
431
|
-
page_shows: zod_1.z
|
|
560
|
+
server.registerTool("execute_payment", {
|
|
561
|
+
title: "Execute Payment (charges the card)",
|
|
562
|
+
description: "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.",
|
|
563
|
+
inputSchema: {
|
|
564
|
+
token: zod_1.z
|
|
432
565
|
.string()
|
|
433
|
-
.
|
|
434
|
-
|
|
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
|
|
566
|
+
.describe("The temporary payment token from request_payment_token"),
|
|
567
|
+
checkout_url: zod_1.z
|
|
439
568
|
.string()
|
|
569
|
+
.url()
|
|
570
|
+
.describe("The full URL of the checkout/payment page"),
|
|
571
|
+
actual_amount: zod_1.z
|
|
572
|
+
.number()
|
|
573
|
+
.optional()
|
|
574
|
+
.describe("STRONGLY RECOMMENDED. The final total shown on the checkout page (incl. shipping + tax). Enables the overcharge block and the underspend refund — omit only if it is genuinely unreadable."),
|
|
575
|
+
hints: zod_1.z
|
|
576
|
+
.object({
|
|
577
|
+
pre_steps: zod_1.z.array(zod_1.z.string()).optional(),
|
|
578
|
+
card_selector: zod_1.z.string().optional(),
|
|
579
|
+
exp_selector: zod_1.z.string().optional(),
|
|
580
|
+
exp_month_selector: zod_1.z.string().optional(),
|
|
581
|
+
exp_year_selector: zod_1.z.string().optional(),
|
|
582
|
+
cvv_selector: zod_1.z.string().optional(),
|
|
583
|
+
name_selector: zod_1.z.string().optional(),
|
|
584
|
+
submit_selector: zod_1.z.string().optional(),
|
|
585
|
+
})
|
|
440
586
|
.optional()
|
|
441
|
-
.describe("
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
587
|
+
.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."),
|
|
588
|
+
recheck: zod_1.z
|
|
589
|
+
.object({
|
|
590
|
+
page_shows: zod_1.z
|
|
591
|
+
.string()
|
|
592
|
+
.min(1)
|
|
593
|
+
.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'."),
|
|
594
|
+
decision: zod_1.z
|
|
595
|
+
.enum(["go", "pause"])
|
|
596
|
+
.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."),
|
|
597
|
+
why: zod_1.z
|
|
598
|
+
.string()
|
|
599
|
+
.optional()
|
|
600
|
+
.describe("Required when you pause: what did not line up."),
|
|
601
|
+
})
|
|
602
|
+
.optional()
|
|
603
|
+
.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."),
|
|
604
|
+
},
|
|
605
|
+
annotations: {
|
|
606
|
+
readOnlyHint: false,
|
|
607
|
+
destructiveHint: true,
|
|
608
|
+
idempotentHint: false,
|
|
609
|
+
openWorldHint: true,
|
|
610
|
+
},
|
|
445
611
|
}, async ({ token, checkout_url, actual_amount, hints, recheck }) => {
|
|
446
612
|
// ── Purpose check: the last look before there is no way back ─────────
|
|
447
613
|
// Called with no `recheck`, this tool does not pay. It hands back the
|
|
@@ -671,13 +837,23 @@ server.tool("execute_payment", "Execute a payment with a one-time token. TWO CAL
|
|
|
671
837
|
// ============================================================
|
|
672
838
|
// TOOL 5: Cancel payment token (returns funds to wallet)
|
|
673
839
|
// ============================================================
|
|
674
|
-
server.
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
840
|
+
server.registerTool("cancel_payment_token", {
|
|
841
|
+
title: "Cancel Token — Safe Refund",
|
|
842
|
+
description: "Cancel unused token and refund instantly. Use when user cancels the purchase or to free up a card slot.",
|
|
843
|
+
inputSchema: {
|
|
844
|
+
token: zod_1.z
|
|
845
|
+
.string()
|
|
846
|
+
.describe("The payment token to cancel"),
|
|
847
|
+
reason: zod_1.z
|
|
848
|
+
.string()
|
|
849
|
+
.describe("Reason for cancellation, e.g. 'Price mismatch: checkout shows $20 but token is $15'"),
|
|
850
|
+
},
|
|
851
|
+
annotations: {
|
|
852
|
+
readOnlyHint: false,
|
|
853
|
+
destructiveHint: true,
|
|
854
|
+
idempotentHint: true,
|
|
855
|
+
openWorldHint: true,
|
|
856
|
+
},
|
|
681
857
|
}, async ({ token, reason }) => {
|
|
682
858
|
const result = await cancelTokenRemote(token);
|
|
683
859
|
if (result?.error === "AUTH_REQUIRED")
|
|
@@ -710,21 +886,29 @@ server.tool("cancel_payment_token", "Cancel unused token and refund instantly. U
|
|
|
710
886
|
// ============================================================
|
|
711
887
|
// TOOL 6: Request human approval (Human-in-the-loop)
|
|
712
888
|
// ============================================================
|
|
713
|
-
server.
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
.
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
.
|
|
889
|
+
server.registerTool("request_human_approval", {
|
|
890
|
+
title: "Show Approval Instructions",
|
|
891
|
+
description: "Pause and ask the user for approval before risky actions (price mismatch, large amount, unusual request).",
|
|
892
|
+
inputSchema: {
|
|
893
|
+
situation: zod_1.z
|
|
894
|
+
.string()
|
|
895
|
+
.describe("Clear description of what the bot found, e.g. 'Checkout shows $20 total (includes $3 tax) but current token is only $15'"),
|
|
896
|
+
current_token: zod_1.z
|
|
897
|
+
.string()
|
|
898
|
+
.optional()
|
|
899
|
+
.describe("Current active token ID if any"),
|
|
900
|
+
recommended_action: zod_1.z
|
|
901
|
+
.string()
|
|
902
|
+
.describe("What the bot recommends doing, e.g. 'Cancel current $15 token and issue a new $20 token'"),
|
|
903
|
+
alternative_action: zod_1.z
|
|
904
|
+
.string()
|
|
905
|
+
.optional()
|
|
906
|
+
.describe("Alternative option if available"),
|
|
907
|
+
},
|
|
908
|
+
annotations: {
|
|
909
|
+
readOnlyHint: true,
|
|
910
|
+
openWorldHint: false,
|
|
911
|
+
},
|
|
728
912
|
}, async ({ situation, current_token, recommended_action, alternative_action }) => {
|
|
729
913
|
// This tool surfaces the situation to the human operator via the MCP interface.
|
|
730
914
|
// The LLM host (Claude/AutoGPT) will pause and show this to the user.
|
|
@@ -753,10 +937,20 @@ server.tool("request_human_approval", "Pause and ask the user for approval befor
|
|
|
753
937
|
// ============================================================
|
|
754
938
|
// TOOL 6.5: Set API Key (Hot-Swap Passport Key — NO restart needed)
|
|
755
939
|
// ============================================================
|
|
756
|
-
server.
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
940
|
+
server.registerTool("set_api_key", {
|
|
941
|
+
title: "Change Passport Key (switches identity)",
|
|
942
|
+
description: "Activate a new Passport Key instantly, no restart needed. Only call when user explicitly provides a key.",
|
|
943
|
+
inputSchema: {
|
|
944
|
+
api_key: zod_1.z
|
|
945
|
+
.string()
|
|
946
|
+
.describe("The new Passport Key to activate. Must start with 'zk_live_' or 'zk_test_'. Get from: https://z-zero.xyz/dashboard/agents"),
|
|
947
|
+
},
|
|
948
|
+
annotations: {
|
|
949
|
+
readOnlyHint: false,
|
|
950
|
+
destructiveHint: true,
|
|
951
|
+
idempotentHint: false,
|
|
952
|
+
openWorldHint: false,
|
|
953
|
+
},
|
|
760
954
|
}, async ({ api_key }) => {
|
|
761
955
|
// Step 1: Format validation
|
|
762
956
|
const trimmed = api_key.trim();
|
|
@@ -859,7 +1053,15 @@ server.tool("set_api_key", "Activate a new Passport Key instantly, no restart ne
|
|
|
859
1053
|
// ============================================================
|
|
860
1054
|
// TOOL 6.6: Show current API Key status (for debugging)
|
|
861
1055
|
// ============================================================
|
|
862
|
-
server.
|
|
1056
|
+
server.registerTool("show_api_key_status", {
|
|
1057
|
+
title: "Passport Key Status",
|
|
1058
|
+
description: "Check if Passport Key is configured. Shows prefix only, for debugging.",
|
|
1059
|
+
inputSchema: {},
|
|
1060
|
+
annotations: {
|
|
1061
|
+
readOnlyHint: true,
|
|
1062
|
+
openWorldHint: false,
|
|
1063
|
+
},
|
|
1064
|
+
}, async () => {
|
|
863
1065
|
const key = (0, key_store_js_1.getPassportKey)();
|
|
864
1066
|
const hasKey = key.length > 0;
|
|
865
1067
|
return {
|
|
@@ -875,14 +1077,24 @@ server.tool("show_api_key_status", "Check if Passport Key is configured. Shows p
|
|
|
875
1077
|
}],
|
|
876
1078
|
};
|
|
877
1079
|
});
|
|
878
|
-
server.
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
1080
|
+
server.registerTool("auto_pay_checkout", {
|
|
1081
|
+
title: "Auto-Pay Checkout (charges the card)",
|
|
1082
|
+
description: "⚠️ MANDATORY: Read mcp://resources/sop first. Only use on PAYMENT pages where final total is visible. Auto-detects Web3 or Fiat and completes payment. For physical goods (Shopify, Etsy), get_merchant_hints first.",
|
|
1083
|
+
inputSchema: {
|
|
1084
|
+
checkout_url: zod_1.z
|
|
1085
|
+
.string()
|
|
1086
|
+
.url()
|
|
1087
|
+
.describe("Full URL of the checkout/payment page to analyze and pay."),
|
|
1088
|
+
card_alias: zod_1.z
|
|
1089
|
+
.string()
|
|
1090
|
+
.describe("Card alias to charge for JIT Fiat fallback, e.g. 'Card_01'."),
|
|
1091
|
+
},
|
|
1092
|
+
annotations: {
|
|
1093
|
+
readOnlyHint: false,
|
|
1094
|
+
destructiveHint: true,
|
|
1095
|
+
idempotentHint: false,
|
|
1096
|
+
openWorldHint: true,
|
|
1097
|
+
},
|
|
886
1098
|
}, async ({ checkout_url, card_alias }) => {
|
|
887
1099
|
const ZZERO_API = (0, api_base_js_1.resolveApiBaseUrl)();
|
|
888
1100
|
const API_KEY = (0, key_store_js_1.getPassportKey)(); // ✅ FIX: use hot-swap key store, not process.env
|
|
@@ -1105,26 +1317,36 @@ server.tool("auto_pay_checkout", "⚠️ MANDATORY: Read mcp://resources/sop fir
|
|
|
1105
1317
|
// Triggers: stuck mid pre_steps, bot blocked, selector not found, etc.
|
|
1106
1318
|
// Does NOT apply to: user cancelled, insufficient balance, price mismatch.
|
|
1107
1319
|
// ============================================================
|
|
1108
|
-
server.
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1320
|
+
server.registerTool("report_checkout_fail", {
|
|
1321
|
+
title: "Report Checkout Failure",
|
|
1322
|
+
description: "Report a checkout you could not complete. Pick the failure_class that best matches what you saw — this feeds Z-ZERO's self-healing loop (labeled failures become better merchant hints for the next run). If nothing fits, use 'unknown' and describe what happened in error_message.",
|
|
1323
|
+
inputSchema: {
|
|
1324
|
+
url: zod_1.z
|
|
1325
|
+
.string()
|
|
1326
|
+
.url()
|
|
1327
|
+
.describe("The checkout/payment page URL where the purchase failed."),
|
|
1328
|
+
failure_class: zod_1.z
|
|
1329
|
+
.enum(failure_taxonomy_js_1.FAILURE_CLASSES)
|
|
1330
|
+
.describe("Fixed failure class: 'card_declined_issuer' (card rejected by bank), 'card_declined_bin_block' (merchant refuses prepaid/virtual cards), 'avs_mismatch' (billing address rejected), '3ds_required' (extra verification/SCA screen appeared), 'bot_detected' (CAPTCHA/Cloudflare/'unusual activity'), 'form_changed' (expected field or button not found), 'price_changed' (total differs from expected), 'out_of_stock', 'shipping_unsupported' (cannot ship to address), 'login_required' (checkout demands an account), 'timeout', 'outcome_unconfirmed' (submitted but no confirmation seen), or 'unknown'."),
|
|
1331
|
+
step: zod_1.z
|
|
1332
|
+
.enum(failure_taxonomy_js_1.CHECKOUT_STEPS)
|
|
1333
|
+
.optional()
|
|
1334
|
+
.describe("Where it failed: 'navigate' (page load), 'pre_steps' (shipping/navigation steps), 'fill_form' (card fields), 'submit' (Pay button), 'confirm' (after submitting)."),
|
|
1335
|
+
error_message: zod_1.z
|
|
1336
|
+
.string()
|
|
1337
|
+
.optional()
|
|
1338
|
+
.describe("Brief description of what you saw, e.g. 'Card number field is inside a new iframe' or 'Page redirected to CAPTCHA'. NEVER include card numbers."),
|
|
1339
|
+
remediation_tried: zod_1.z
|
|
1340
|
+
.string()
|
|
1341
|
+
.optional()
|
|
1342
|
+
.describe("What you already tried before giving up, e.g. 'retried with submit_selector from hints'."),
|
|
1343
|
+
},
|
|
1344
|
+
annotations: {
|
|
1345
|
+
readOnlyHint: false,
|
|
1346
|
+
destructiveHint: false,
|
|
1347
|
+
idempotentHint: false,
|
|
1348
|
+
openWorldHint: false,
|
|
1349
|
+
},
|
|
1128
1350
|
}, async ({ url, failure_class, step, error_message, remediation_tried }) => {
|
|
1129
1351
|
emitCheckoutEvent({
|
|
1130
1352
|
url,
|
|
@@ -1149,13 +1371,21 @@ server.tool("report_checkout_fail", "Report a checkout you could not complete. P
|
|
|
1149
1371
|
// Lets the agent PROVE a purchase happened instead of claiming it.
|
|
1150
1372
|
// Public endpoint — anyone with the receipt_id can verify.
|
|
1151
1373
|
// ============================================================
|
|
1152
|
-
server.
|
|
1153
|
-
"
|
|
1154
|
-
"
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
.
|
|
1158
|
-
|
|
1374
|
+
server.registerTool("verify_receipt", {
|
|
1375
|
+
title: "Verify Receipt",
|
|
1376
|
+
description: "Check where an order ENDED UP, and prove it. Returns TWO separate axes: " +
|
|
1377
|
+
"`order_status` — 'completed' (bought, issuer not reported yet) · 'settled' (issuer confirmed) · 'reversed' (auth voided before clearing — the order does NOT stand) · 'partially_refunded' / 'refunded' (merchant returned money AFTER settlement — the order still happened) — " +
|
|
1378
|
+
"and `funds_status` — 'no_payout_due' · 'payout_pending' (money owed back but not yet confirmed on-chain) · 'returned' (confirmed on-chain). " +
|
|
1379
|
+
"Read BOTH before speaking: 'reversed' or 'refunded' with funds 'payout_pending' means the buyer has NOT got the money back yet — never say they have. If you told the user a purchase was done and a later check returns 'reversed', tell them unprompted.",
|
|
1380
|
+
inputSchema: {
|
|
1381
|
+
receipt_id: zod_1.z
|
|
1382
|
+
.string()
|
|
1383
|
+
.describe("The receipt_id returned by execute_payment / auto_pay_checkout (signed_receipt.receipt_id)."),
|
|
1384
|
+
},
|
|
1385
|
+
annotations: {
|
|
1386
|
+
readOnlyHint: true,
|
|
1387
|
+
openWorldHint: false,
|
|
1388
|
+
},
|
|
1159
1389
|
}, async ({ receipt_id }) => {
|
|
1160
1390
|
const ZZERO_API = (0, api_base_js_1.resolveApiBaseUrl)();
|
|
1161
1391
|
try {
|
|
@@ -1372,6 +1602,6 @@ async function main() {
|
|
|
1372
1602
|
await server.connect(transport);
|
|
1373
1603
|
console.error(`🔐 Z-Zero MCP Server v${version_js_2.CURRENT_MCP_VERSION} running (Base + USDC, gasless via Coinbase Paymaster)...`);
|
|
1374
1604
|
console.error("Status: Secure & Connected to Z-ZERO Gateway");
|
|
1375
|
-
console.error("Tools: list_cards, check_balance, get_deposit_addresses, request_payment_token, get_merchant_hints, execute_payment, auto_pay_checkout, cancel_payment_token, request_human_approval, report_checkout_fail, verify_receipt, set_api_key, show_api_key_status");
|
|
1605
|
+
console.error("Tools: list_cards, check_balance, get_deposit_addresses, request_payment_token, get_merchant_hints, execute_payment, auto_pay_checkout, cancel_payment_token, request_human_approval, report_checkout_fail, ucp_probe_checkout, verify_receipt, set_api_key, show_api_key_status");
|
|
1376
1606
|
}
|
|
1377
1607
|
main().catch(console.error);
|