z-zero-mcp-server 1.3.5 → 1.5.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/dist/index.js CHANGED
@@ -62,7 +62,7 @@ const playwright_bridge_js_1 = require("./playwright_bridge.js");
62
62
  const web3_detector_js_1 = require("./lib/web3-detector.js");
63
63
  const extract_total_price_js_1 = require("./lib/extract-total-price.js");
64
64
  const playwright_1 = require("playwright");
65
- const key_store_js_1 = require("./lib/key-store.js"); // ✅ Hot-Swap support
65
+ const key_store_js_1 = require("./lib/key-store.js"); // ✅ Hot-Swap + rotate-on-connect
66
66
  const url_guard_js_1 = require("./lib/url-guard.js");
67
67
  /** Masked, non-reconstructable hint for a secret key (for debug output only). */
68
68
  function maskKey(key) {
@@ -291,7 +291,11 @@ server.tool("get_merchant_hints", "Get merchant navigation flow for a domain or
291
291
  try {
292
292
  const resp = await fetch(`${ZZERO_API}/api/checkout-hints?domain=${encodeURIComponent(domain)}&fields=merchant`, {
293
293
  headers: {
294
- "x-internal-secret": INTERNAL_SECRET,
294
+ // Primary auth: Passport Key (same key as list_cards — hints are
295
+ // identity+rate-limit gated, not secret). Internal secret kept
296
+ // as fallback for self-hosted deployments that still use it.
297
+ "Authorization": `Bearer ${(0, key_store_js_1.getPassportKey)()}`,
298
+ ...(INTERNAL_SECRET ? { "x-internal-secret": INTERNAL_SECRET } : {}),
295
299
  "x-mcp-version": version_js_2.CURRENT_MCP_VERSION,
296
300
  },
297
301
  });
@@ -599,15 +603,54 @@ server.tool("set_api_key", "Activate a new Passport Key instantly, no restart ne
599
603
  isError: true,
600
604
  };
601
605
  }
606
+ // Step 4: ROTATE-ON-CONNECT (v1.5.0). The key the user just pasted has
607
+ // been through the LLM conversation → treat it as burned. Swap it for a
608
+ // fresh key that NEVER enters the chat: server → this process → disk.
609
+ // Side effect by design: connecting a second machine with a copied key
610
+ // rotates it and disconnects the first one ("one key = one agent").
611
+ let rotated = false;
612
+ try {
613
+ const rotateResp = await fetch(`${ZZERO_API}/api/keys/rotate`, {
614
+ method: "POST",
615
+ headers: {
616
+ "Authorization": `Bearer ${trimmed}`,
617
+ "x-mcp-version": version_js_2.CURRENT_MCP_VERSION,
618
+ },
619
+ signal: AbortSignal.timeout(8000),
620
+ });
621
+ if (rotateResp.ok) {
622
+ const rotateData = await rotateResp.json();
623
+ const newKey = typeof rotateData?.new_key === "string" ? rotateData.new_key : "";
624
+ if (newKey.startsWith("zk_live_") || newKey.startsWith("zk_test_")) {
625
+ // Persist FIRST, then activate — if the disk write fails we
626
+ // keep using the (already-rotated) key in RAM and warn.
627
+ const persisted = (0, key_store_js_1.persistPassportKey)(newKey);
628
+ (0, key_store_js_1.setPassportKey)(newKey);
629
+ rotated = true;
630
+ if (!persisted) {
631
+ console.error("[SET-KEY] ⚠️ Rotated key active in RAM but NOT persisted — re-connect with a fresh key from the dashboard after restart.");
632
+ }
633
+ }
634
+ }
635
+ // Non-OK (404 = server not yet deployed, 429, 5xx) → keep pasted key, no rotation. Backward compatible.
636
+ }
637
+ catch {
638
+ // Network error → keep pasted key. Backward compatible.
639
+ }
602
640
  return {
603
641
  content: [{
604
642
  type: "text",
605
643
  text: JSON.stringify({
606
644
  status: "SUCCESS",
607
- message: `✅ ${result.message}`,
645
+ message: rotated
646
+ ? "✅ Connected. For security, the key you pasted was immediately replaced with a fresh one stored locally (~/.z-zero/credentials) — the pasted key is now dead everywhere, including this conversation."
647
+ : `✅ ${result.message}`,
608
648
  // Masked hint only — never echo a usable portion of the secret to the chat/model context.
609
- active_key_hint: maskKey(trimmed),
610
- note: "All subsequent API calls will use this key. Previous key removed from this session (soft revoke).",
649
+ active_key_hint: maskKey((0, key_store_js_1.getPassportKey)()),
650
+ rotated_on_connect: rotated,
651
+ note: rotated
652
+ ? "One key = one agent: connecting another agent/machine with this account's key will disconnect this one."
653
+ : "All subsequent API calls will use this key. Previous key removed from this session (soft revoke).",
611
654
  }, null, 2),
612
655
  }],
613
656
  };
@@ -825,7 +868,8 @@ server.tool("report_checkout_fail", "Report a checkout URL that you could not co
825
868
  method: "POST",
826
869
  headers: {
827
870
  "Content-Type": "application/json",
828
- "x-internal-secret": INTERNAL_SECRET,
871
+ "Authorization": `Bearer ${(0, key_store_js_1.getPassportKey)()}`,
872
+ ...(INTERNAL_SECRET ? { "x-internal-secret": INTERNAL_SECRET } : {}),
829
873
  "x-mcp-version": version_js_2.CURRENT_MCP_VERSION,
830
874
  },
831
875
  body: JSON.stringify({ url, error_type, error_message, mcp_version: version_js_2.CURRENT_MCP_VERSION }),
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Persist the key to ~/.z-zero/credentials with owner-only permissions.
3
+ * Returns true on success. Failure is non-fatal (key still lives in memory).
4
+ */
5
+ export declare function persistPassportKey(key: string): boolean;
1
6
  /** Read the current active Passport Key. */
2
7
  export declare function getPassportKey(): string;
3
8
  /**
@@ -4,12 +4,55 @@
4
4
  // All API backends (custodial + WDK) import getPassportKey() from here
5
5
  // so a single set_api_key MCP tool updates the key for ALL backends at once.
6
6
  //
7
+ // v1.5.0: keys are also persisted to ~/.z-zero/credentials (chmod 600).
8
+ // Load priority: credentials file > Z_ZERO_API_KEY env. The file exists
9
+ // because rotate-on-connect swaps the pasted key for a fresh one that must
10
+ // survive restarts WITHOUT ever entering the LLM conversation or the
11
+ // claude_desktop_config.json.
12
+ //
7
13
  // Thread-safety: Node.js is single-threaded. Module-level `let` is safe.
8
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.persistPassportKey = persistPassportKey;
9
16
  exports.getPassportKey = getPassportKey;
10
17
  exports.setPassportKey = setPassportKey;
11
18
  exports.hasPassportKey = hasPassportKey;
12
- let _passportKey = process.env.Z_ZERO_API_KEY || "";
19
+ const fs_1 = require("fs");
20
+ const path_1 = require("path");
21
+ const os_1 = require("os");
22
+ const CRED_DIR = (0, path_1.join)((0, os_1.homedir)(), ".z-zero");
23
+ const CRED_FILE = (0, path_1.join)(CRED_DIR, "credentials");
24
+ /** Read the persisted key from ~/.z-zero/credentials (null if absent/invalid). */
25
+ function loadPersistedKey() {
26
+ try {
27
+ const raw = (0, fs_1.readFileSync)(CRED_FILE, "utf8");
28
+ const parsed = JSON.parse(raw);
29
+ const key = typeof parsed?.passport_key === "string" ? parsed.passport_key.trim() : "";
30
+ if (key.startsWith("zk_live_") || key.startsWith("zk_test_"))
31
+ return key;
32
+ return null;
33
+ }
34
+ catch {
35
+ return null; // no file yet, or unreadable — fall back to env
36
+ }
37
+ }
38
+ /**
39
+ * Persist the key to ~/.z-zero/credentials with owner-only permissions.
40
+ * Returns true on success. Failure is non-fatal (key still lives in memory).
41
+ */
42
+ function persistPassportKey(key) {
43
+ try {
44
+ (0, fs_1.mkdirSync)(CRED_DIR, { recursive: true, mode: 0o700 });
45
+ (0, fs_1.writeFileSync)(CRED_FILE, JSON.stringify({ passport_key: key }) + "\n", { mode: 0o600 });
46
+ (0, fs_1.chmodSync)(CRED_FILE, 0o600); // enforce even if file pre-existed with looser mode
47
+ return true;
48
+ }
49
+ catch (err) {
50
+ console.error(`[KEY-STORE] ⚠️ Could not persist key to ${CRED_FILE}: ${err?.message || err}`);
51
+ return false;
52
+ }
53
+ }
54
+ // Load priority: persisted (post-rotation) key wins over the bootstrap env key.
55
+ let _passportKey = loadPersistedKey() || process.env.Z_ZERO_API_KEY || "";
13
56
  /** Read the current active Passport Key. */
14
57
  function getPassportKey() {
15
58
  return _passportKey;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "z-zero-mcp-server",
3
- "version": "1.3.5",
3
+ "version": "1.5.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": {