z-zero-mcp-server 1.4.0 → 1.5.1

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 CHANGED
@@ -108,6 +108,21 @@ Get your Passport Key at: **[clawcard.store/dashboard/agents](https://www.clawca
108
108
 
109
109
  ---
110
110
 
111
+ ## Security: rotate-on-connect (v1.5.0+)
112
+
113
+ The key you copy from the dashboard (or paste into a chat) is only a **one-time bootstrap ticket**.
114
+ The moment your agent connects with it, the MCP server silently swaps it for a fresh key:
115
+
116
+ - The fresh key travels **server → MCP process → disk** and is stored in `~/.z-zero/credentials` (mode `0600`). It never appears in any LLM conversation, tool result, or config file.
117
+ - The pasted key is **dead within seconds** — a copy living in a chat transcript, clipboard, or screenshot can no longer be used by anyone.
118
+ - On startup the MCP loads the key from `~/.z-zero/credentials` first; the `Z_ZERO_API_KEY` env var is only a bootstrap fallback.
119
+
120
+ **One key = one machine.** All agents on the same machine (Claude Desktop, Claude Code, Cursor, …) share the same MCP install and the same credentials file — install once, every agent can pay. Connecting a *different* machine with a copied key rotates it, which instantly disconnects the original machine. That is deliberate: it blocks key sharing **and** doubles as an intrusion alarm — if your agent suddenly fails auth, someone else used your key; go to the dashboard and revoke.
121
+
122
+ Older self-hosted backends without the rotate endpoint keep working — the pasted key simply stays active as before.
123
+
124
+ ---
125
+
111
126
  ## Requirements
112
127
 
113
128
  - **Node.js v18+** — [nodejs.org](https://nodejs.org)
@@ -195,4 +210,4 @@ Cancel an unused token (refunds balance).
195
210
 
196
211
  ---
197
212
 
198
- *Security: Z-Zero never stores your Passport Key. It is passed via environment variables and card data exists only in volatile RAM during execution.*
213
+ *Security: the key you paste is never kept — it rotates the moment your agent first connects, and the fresh key lives only in a local owner-only file (`~/.z-zero/credentials`, mode 0600), never in any LLM conversation. Card data exists only in volatile RAM during execution.*
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) {
@@ -603,15 +603,54 @@ server.tool("set_api_key", "Activate a new Passport Key instantly, no restart ne
603
603
  isError: true,
604
604
  };
605
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
+ }
606
640
  return {
607
641
  content: [{
608
642
  type: "text",
609
643
  text: JSON.stringify({
610
644
  status: "SUCCESS",
611
- 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}`,
612
648
  // Masked hint only — never echo a usable portion of the secret to the chat/model context.
613
- active_key_hint: maskKey(trimmed),
614
- 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).",
615
654
  }, null, 2),
616
655
  }],
617
656
  };
@@ -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;
@@ -57,19 +57,17 @@ async function apiRequest(endpoint, method = 'GET', body = null) {
57
57
  }
58
58
  }
59
59
  async function internalApiRequest(endpoint, method, body) {
60
- // ✅ FIX 9: Validate INTERNAL_SECRET presence and minimum length
61
- if (!INTERNAL_SECRET || INTERNAL_SECRET.length < 16) {
62
- return { error: "CONFIG_ERROR", message: "INTERNAL_SECRET is missing or too short (min 16 chars)" };
63
- }
60
+ // Auth is the Bearer Passport Key — the server dropped the x-internal-secret
61
+ // gate on /resolve and /burn (redundant to per-user token ownership, Jul 2026).
62
+ // The old client-side CONFIG_ERROR check here broke execute_payment for every
63
+ // install configured per the current docs (key only). Secret is now attached
64
+ // only if present, as back-compat for self-hosted deployments that still gate on it.
64
65
  const url = `${API_BASE_URL.replace(/\/$/, '')}${endpoint}`;
65
66
  try {
66
- // Two independent factors on these PAN/burn endpoints:
67
- // - x-internal-secret: coarse platform gate (shared deploy secret)
68
- // - Authorization: Bearer <Passport Key>: per-user identity → server enforces token ownership
69
67
  const res = await fetch(url, {
70
68
  method,
71
69
  headers: {
72
- "x-internal-secret": INTERNAL_SECRET,
70
+ ...(INTERNAL_SECRET ? { "x-internal-secret": INTERNAL_SECRET } : {}),
73
71
  "Authorization": `Bearer ${(0, key_store_js_1.getPassportKey)()}`,
74
72
  "Content-Type": "application/json",
75
73
  "X-MCP-Version": version_js_1.CURRENT_MCP_VERSION,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "z-zero-mcp-server",
3
- "version": "1.4.0",
3
+ "version": "1.5.1",
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": {