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/README.md
CHANGED
|
@@ -17,7 +17,7 @@ npx z-zero-mcp-server
|
|
|
17
17
|
- ⛽ **Gasless USDC on Base** — auto-detects crypto checkout (EIP-681) and settles as a gasless USDC transfer sponsored by Coinbase Paymaster. The agent holds only USDC — no ETH, no gas UX.
|
|
18
18
|
- 💳 **JIT single-use virtual cards** — amount-locked, 1-hour TTL, burned after a single use. Fiat fallback for the rest of the web.
|
|
19
19
|
- 🧠 **Smart Routing + checkout intelligence** — `get_merchant_hints` serves platform-specific checkout playbooks (Shopify, Etsy, WooCommerce…).
|
|
20
|
-
- ✍️ **
|
|
20
|
+
- ✍️ **Linked purpose + outcome** — the server signs the criteria the agent records at issuance. Before checkout, `execute_payment` hands those criteria back and requires a second call with `go` or `pause`; a confirmed purchase seals the answer into the signed receipt. The record is inspectable without pretending the platform judged whether the agent told the truth.
|
|
21
21
|
- 🔄 **Structured failure labels** — failed checkouts are labeled with a fixed 14-class `failure_class` (automatically, not only when an agent remembers to report) and stored as evidence for the merchant knowledge base. Facts are promoted into shared hints only after a later outcome or review verifies them.
|
|
22
22
|
|
|
23
23
|
---
|
|
@@ -49,14 +49,20 @@ npx z-zero-mcp-server
|
|
|
49
49
|
│ │ │ │
|
|
50
50
|
│ │ (fills shipping form, reaches payment page) │
|
|
51
51
|
│ │ │ │
|
|
52
|
-
│ │ request_payment_token(amount,
|
|
52
|
+
│ │ request_payment_token(amount, cart, criteria)│
|
|
53
53
|
│ ├─────────────────────▶│ │
|
|
54
54
|
│ │◀── temp_auth token ──┤ (1-hour TTL) │
|
|
55
55
|
│ │ │ │
|
|
56
56
|
│ │ execute_payment(token, checkout_url) │
|
|
57
57
|
│ ├─────────────────────▶│ │
|
|
58
|
-
│
|
|
59
|
-
│ │
|
|
58
|
+
│ │◀── purpose_check ────┤ (nothing charged) │
|
|
59
|
+
│ │ compare locked criteria with final page │
|
|
60
|
+
│ │ │ │
|
|
61
|
+
│ │ execute_payment(..., recheck: go | pause) │
|
|
62
|
+
│ ├─────────────────────▶│ │
|
|
63
|
+
│ │ pause → no card is filled │
|
|
64
|
+
│ │ go → Playwright fills + submits, │
|
|
65
|
+
│ │ then burns token if confirmed 🔥 │
|
|
60
66
|
│ │◀──── ✅ success ─────┤ │
|
|
61
67
|
│ "Done! Your item │ │ │
|
|
62
68
|
│ is ordered." │ │ │
|
|
@@ -143,12 +149,12 @@ Older self-hosted backends without the rotate endpoint keep working — the past
|
|
|
143
149
|
| `set_api_key` | Activate a new Passport Key instantly, no restart needed |
|
|
144
150
|
| `show_api_key_status` | Check if a Passport Key is currently loaded (prefix only) |
|
|
145
151
|
|
|
146
|
-
### Group 2 — Manual
|
|
152
|
+
### Group 2 — Manual Card Payment (Active)
|
|
147
153
|
|
|
148
154
|
| Tool | Description |
|
|
149
155
|
|------|-------------|
|
|
150
|
-
| `request_payment_token` | Issue a JIT single-use virtual-card token for a specific amount (1hr TTL). Pass `cart`
|
|
151
|
-
| `execute_payment` |
|
|
156
|
+
| `request_payment_token` | Issue a JIT single-use virtual-card token for a specific amount (1hr TTL). Pass `cart`, `criteria`, and `ship_to` to create the signed issuance record |
|
|
157
|
+
| `execute_payment` | **Two calls required:** first without `recheck` returns the locked criteria and charges nothing; second supplies `recheck: { page_shows, decision: go\|pause }`. `pause` does not fill the card; confirmed `go` returns a signed receipt |
|
|
152
158
|
| `cancel_payment_token` | Cancel an unused token and refund to wallet |
|
|
153
159
|
| `request_human_approval` | Pause and request human confirmation before proceeding |
|
|
154
160
|
|
|
@@ -165,9 +171,9 @@ Older self-hosted backends without the rotate endpoint keep working — the past
|
|
|
165
171
|
|
|
166
172
|
---
|
|
167
173
|
|
|
168
|
-
## Agent primitives (v1.
|
|
174
|
+
## Agent primitives (v1.9.0)
|
|
169
175
|
|
|
170
|
-
|
|
176
|
+
Four linked records and controls an agent can use here that it cannot get from a normal virtual card alone.
|
|
171
177
|
|
|
172
178
|
### 1. Signed intent — the card knows what it is for
|
|
173
179
|
|
|
@@ -179,19 +185,54 @@ request_payment_token({
|
|
|
179
185
|
amount: 44.00,
|
|
180
186
|
merchant: "etsy.com",
|
|
181
187
|
cart: [{ title: "Ceramic mug — matte white", qty: 2, unit_price: 18.50 }],
|
|
182
|
-
ship_to: "12 Nguyen Hue, District 1, Ho Chi Minh City, VN"
|
|
188
|
+
ship_to: "12 Nguyen Hue, District 1, Ho Chi Minh City, VN",
|
|
189
|
+
criteria: {
|
|
190
|
+
source: "user_described",
|
|
191
|
+
items: [
|
|
192
|
+
{ key: "item", stated: "two matte-white ceramic mugs" },
|
|
193
|
+
{ key: "max_total", stated: "no more than $44 delivered" }
|
|
194
|
+
]
|
|
195
|
+
}
|
|
183
196
|
})
|
|
184
197
|
```
|
|
185
198
|
|
|
186
|
-
Z-ZERO signs that statement (EIP-191)
|
|
187
|
-
|
|
188
|
-
|
|
199
|
+
Z-ZERO signs that statement (EIP-191) during issuance. It is a tamper-evident
|
|
200
|
+
record of the criteria the agent supplied as the owner's instruction — not an
|
|
201
|
+
independent proof that the human personally approved every line. The shipping
|
|
202
|
+
address is stored as a hash, never raw.
|
|
189
203
|
|
|
190
204
|
**Before you request a token, compare the checkout page with what the user actually
|
|
191
205
|
asked for** — same items, same quantity, same variant, same destination. A mismatch
|
|
192
206
|
you catch there costs nothing. After the token, it costs a card.
|
|
193
207
|
|
|
194
|
-
### 2.
|
|
208
|
+
### 2. Purpose check — read first, then declare `go` or `pause`
|
|
209
|
+
|
|
210
|
+
`execute_payment` is deliberately a two-call tool:
|
|
211
|
+
|
|
212
|
+
```jsonc
|
|
213
|
+
// Call 1 — omit recheck. No browser, PAN, or charge.
|
|
214
|
+
execute_payment({ token, checkout_url, actual_amount: 44.00 })
|
|
215
|
+
// → { status: "purpose_check", nothing_charged: true, owner_asked_for: ... }
|
|
216
|
+
|
|
217
|
+
// Call 2 — describe the final page and make an explicit decision.
|
|
218
|
+
execute_payment({
|
|
219
|
+
token,
|
|
220
|
+
checkout_url,
|
|
221
|
+
actual_amount: 44.00,
|
|
222
|
+
recheck: {
|
|
223
|
+
page_shows: "2 matte-white mugs, delivered total $44.00",
|
|
224
|
+
decision: "go"
|
|
225
|
+
}
|
|
226
|
+
})
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Use `decision: "pause"` when anything differs. The card is not filled and the
|
|
230
|
+
token remains active and refundable. On `go`, the checkout runs; if the merchant
|
|
231
|
+
confirms the order, the declaration is sealed into the signed receipt with the
|
|
232
|
+
outcome. The platform records what the agent declared; it does not independently
|
|
233
|
+
inspect the page or certify that the declaration was true.
|
|
234
|
+
|
|
235
|
+
### 3. Signed receipt — prove the purchase, don't claim it
|
|
195
236
|
|
|
196
237
|
On a confirmed payment you get back:
|
|
197
238
|
|
|
@@ -219,7 +260,7 @@ receipt therefore carries `provenance` per field: `zzero_issued` (the limit we s
|
|
|
219
260
|
evidence), `agent_reported` (unverified), `human_verified`. Until the capture webhook
|
|
220
261
|
lands, this is a **signed execution receipt**, not settlement proof, and it says so.
|
|
221
262
|
|
|
222
|
-
###
|
|
263
|
+
### 4. Structured failure classes — every failure teaches the network
|
|
223
264
|
|
|
224
265
|
`report_checkout_fail` takes a fixed enum, not free text:
|
|
225
266
|
|
package/dist/base_backend.js
CHANGED
|
@@ -211,16 +211,62 @@ async function getDepositAddressesRemote() {
|
|
|
211
211
|
// ──────────────────────────────────────────────────────────────────────────────
|
|
212
212
|
// Issue Token: On-chain USDC (Base) payment → JIT card
|
|
213
213
|
// ──────────────────────────────────────────────────────────────────────────────
|
|
214
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
215
|
+
// W3a — idempotency for card issuance (docs/mcp_hardening_plan_22_08_26.md).
|
|
216
|
+
//
|
|
217
|
+
// A retry is a NEW tool call, so a key minted inside the call would be minted
|
|
218
|
+
// again and the backend would issue a second card. The key must survive across
|
|
219
|
+
// calls — but only while the previous outcome is UNKNOWN (network error / 5xx:
|
|
220
|
+
// the server may have issued the card and the answer got lost). Any definitive
|
|
221
|
+
// answer (2xx success, 4xx rejection) clears the entry, so a genuine second
|
|
222
|
+
// purchase of the same item mints a fresh key and gets a fresh card.
|
|
223
|
+
//
|
|
224
|
+
// An UNKNOWN entry never expires on its own: time passing does not make the
|
|
225
|
+
// outcome definitive — only an answer from the backend does. A retry eleven
|
|
226
|
+
// minutes later must still carry the same key, or it issues a second card.
|
|
227
|
+
// Memory is not a concern worth a silent new key: entries only accumulate on
|
|
228
|
+
// unknown outcomes (rare) and are ~100 bytes each; we warn past a threshold.
|
|
229
|
+
//
|
|
230
|
+
// Limit (accepted for now): the fingerprint is the literal alias|amount|merchant.
|
|
231
|
+
// Case and whitespace are normalised, but an agent that retries with "Etsy"
|
|
232
|
+
// after first sending "etsy.com" looks like a new intent and gets a new key.
|
|
233
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
234
|
+
const PENDING_ISSUE_WARN_AT = 50;
|
|
235
|
+
const pendingIssueKeys = new Map();
|
|
236
|
+
function issueFingerprint(cardAlias, amount, merchant) {
|
|
237
|
+
return `${cardAlias.trim().toLowerCase()}|${amount}|${merchant.trim().toLowerCase()}`;
|
|
238
|
+
}
|
|
239
|
+
// UNKNOWN = the request may have reached the server and issued a card even
|
|
240
|
+
// though we never saw the answer, OR the server says that very attempt is still
|
|
241
|
+
// being processed (409 IDEMPOTENCY_IN_FLIGHT: "retry with the same key").
|
|
242
|
+
// Everything else is the server giving a definitive answer.
|
|
243
|
+
function issueOutcomeUnknown(data) {
|
|
244
|
+
return data?.error === "NETWORK_ERROR" ||
|
|
245
|
+
data?.error === "IDEMPOTENCY_IN_FLIGHT" ||
|
|
246
|
+
(typeof data?.status === "number" && data.status >= 500);
|
|
247
|
+
}
|
|
214
248
|
async function issueTokenRemote(cardAlias, amount, merchant, intent) {
|
|
215
249
|
// Base AA Flow (reversed from custodial):
|
|
216
250
|
// 1. Create Partner card first (reservation)
|
|
217
251
|
// 2. Send USDC on Base from the agent's wallet → system wallet (gasless via Coinbase Paymaster)
|
|
218
252
|
// 3. Dashboard verifies on-chain tx, activates token
|
|
219
253
|
// This is safe: if on-chain tx fails, Dashboard auto-cancels the card reservation.
|
|
254
|
+
// Reuse the pending key when the previous identical attempt has no known
|
|
255
|
+
// outcome — for as long as that stays true, however long it takes.
|
|
256
|
+
const fp = issueFingerprint(cardAlias, amount, merchant);
|
|
257
|
+
const pending = pendingIssueKeys.get(fp);
|
|
258
|
+
const idempotencyKey = pending?.key ?? crypto.randomUUID();
|
|
259
|
+
if (!pending) {
|
|
260
|
+
pendingIssueKeys.set(fp, { key: idempotencyKey, ts: Date.now() });
|
|
261
|
+
if (pendingIssueKeys.size > PENDING_ISSUE_WARN_AT) {
|
|
262
|
+
console.error(`[ISSUE] ⚠️ ${pendingIssueKeys.size} card issuances with unknown outcome are pending — the backend is not answering definitively. Check connectivity before issuing more.`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
220
265
|
const data = await apiRequest('/api/tokens/issue', 'POST', {
|
|
221
266
|
card_alias: cardAlias,
|
|
222
267
|
amount,
|
|
223
268
|
merchant,
|
|
269
|
+
idempotency_key: idempotencyKey,
|
|
224
270
|
device_fingerprint: `mcp-base-${process.platform}-${process.arch}`,
|
|
225
271
|
network_id: process.env.NETWORK_ID || "base-usdc",
|
|
226
272
|
session_id: `base-${Math.random().toString(36).substring(7)}`,
|
|
@@ -228,6 +274,10 @@ async function issueTokenRemote(cardAlias, amount, merchant, intent) {
|
|
|
228
274
|
// returns the signed object; older servers simply ignore this field.
|
|
229
275
|
...(intent ? { intent } : {}),
|
|
230
276
|
});
|
|
277
|
+
// Definitive answer (success OR rejection) → the next identical call is a
|
|
278
|
+
// new intent, not a retry. Unknown outcome keeps the key for the retry.
|
|
279
|
+
if (!issueOutcomeUnknown(data))
|
|
280
|
+
pendingIssueKeys.delete(fp);
|
|
231
281
|
if (!data)
|
|
232
282
|
return null;
|
|
233
283
|
if (data.error)
|