z-zero-mcp-server 1.10.0 → 1.10.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.
Files changed (2) hide show
  1. package/dist/index.js +60 -37
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -990,22 +990,41 @@ server.registerTool("set_api_key", {
990
990
  isError: true,
991
991
  };
992
992
  }
993
- // Step 3: Swap key in RAM (old key is soft-revoked — just forgotten)
994
- const result = (0, key_store_js_1.setPassportKey)(trimmed);
995
- if (!result.ok) {
996
- return {
997
- content: [{ type: "text", text: `❌ ${result.message}` }],
998
- isError: true,
999
- };
1000
- }
1001
- // Step 4: ROTATE-ON-CONNECT (v1.5.0). The key the user just pasted has
1002
- // been through the LLM conversation → treat it as burned. Swap it for a
1003
- // fresh key that NEVER enters the chat: server → this process → disk.
993
+ // Step 3: ROTATE-ON-CONNECT (v1.5.0), FAIL-CLOSED (v1.11, W2a).
994
+ // The key the user just pasted has been through the LLM conversation →
995
+ // treat it as burned. Ask the server to swap it for a fresh key that
996
+ // NEVER enters the chat: server → this process → disk.
997
+ //
998
+ // Nothing is activated until the server has answered. Before W2a the
999
+ // pasted key was put in RAM first and a failed/lost rotate still returned
1000
+ // SUCCESS — the process then ran on a key that had been in the chat while
1001
+ // claiming it had not. Now: rotate fails → the previous key stays active
1002
+ // and the caller gets the real error.
1003
+ //
1004
1004
  // Side effect by design: connecting a second machine with a copied key
1005
1005
  // rotates it and disconnects the first one ("one key = one agent").
1006
- let rotated = false;
1006
+ const previousHint = maskKey((0, key_store_js_1.getPassportKey)());
1007
+ // remote_status tells the agent what the SERVER side looks like:
1008
+ // UNKNOWN — the request may have reached the server; the pasted key may
1009
+ // already be dead and its replacement lost with the reply.
1010
+ // REJECTED — the server refused the pasted key; nothing happened.
1011
+ // ERROR — the server answered but could not rotate; nothing happened.
1012
+ const failClosed = (remote, why, next) => ({
1013
+ content: [{
1014
+ type: "text",
1015
+ text: JSON.stringify({
1016
+ status: "NOT_SWITCHED",
1017
+ remote_status: remote,
1018
+ message: `❌ Key rotation did not complete: ${why}`,
1019
+ active_key_hint: previousHint,
1020
+ note: `Your previous key is still active — nothing changed. ${next}`,
1021
+ }, null, 2),
1022
+ }],
1023
+ isError: true,
1024
+ });
1025
+ let rotateResp;
1007
1026
  try {
1008
- const rotateResp = await fetch(`${ZZERO_API}/api/keys/rotate`, {
1027
+ rotateResp = await fetch(`${ZZERO_API}/api/keys/rotate`, {
1009
1028
  method: "POST",
1010
1029
  headers: {
1011
1030
  "Authorization": `Bearer ${trimmed}`,
@@ -1013,39 +1032,43 @@ server.registerTool("set_api_key", {
1013
1032
  },
1014
1033
  signal: AbortSignal.timeout(8000),
1015
1034
  });
1016
- if (rotateResp.ok) {
1017
- const rotateData = await rotateResp.json();
1018
- const newKey = typeof rotateData?.new_key === "string" ? rotateData.new_key : "";
1019
- if (newKey.startsWith("zk_live_") || newKey.startsWith("zk_test_")) {
1020
- // Persist FIRST, then activate — if the disk write fails we
1021
- // keep using the (already-rotated) key in RAM and warn.
1022
- const persisted = (0, key_store_js_1.persistPassportKey)(newKey);
1023
- (0, key_store_js_1.setPassportKey)(newKey);
1024
- rotated = true;
1025
- if (!persisted) {
1026
- console.error("[SET-KEY] ⚠️ Rotated key active in RAM but NOT persisted — re-connect with a fresh key from the dashboard after restart.");
1027
- }
1028
- }
1029
- }
1030
- // Non-OK (404 = server not yet deployed, 429, 5xx) → keep pasted key, no rotation. Backward compatible.
1031
1035
  }
1032
- catch {
1033
- // Network error → keep pasted key. Backward compatible.
1036
+ catch (err) {
1037
+ // The request may or may not have reached the server. If it did, the
1038
+ // pasted key is already dead and the fresh one is lost with the reply.
1039
+ return failClosed("UNKNOWN", `could not reach the server (${err?.message || "timeout"}).`, "Retry set_api_key with the same key. If the server then rejects it, the rotation went through and its reply was lost — get a fresh key from https://z-zero.xyz/dashboard/agents.");
1040
+ }
1041
+ if (rotateResp.status === 401) {
1042
+ return failClosed("REJECTED", "the server rejected the pasted key (already rotated on another machine, or revoked).", "Get a fresh key from https://z-zero.xyz/dashboard/agents.");
1043
+ }
1044
+ if (!rotateResp.ok) {
1045
+ return failClosed("ERROR", `the server returned ${rotateResp.status}.`, rotateResp.status === 429 ? "Wait a minute, then retry set_api_key with the same key." : "Retry set_api_key with the same key in a moment.");
1046
+ }
1047
+ const rotateData = await rotateResp.json().catch(() => null);
1048
+ const newKey = typeof rotateData?.new_key === "string" ? rotateData.new_key : "";
1049
+ if (!newKey.startsWith("zk_live_") && !newKey.startsWith("zk_test_")) {
1050
+ return failClosed("ERROR", "the server answered without a usable key.", "Retry set_api_key with the same key in a moment.");
1051
+ }
1052
+ // Step 4: Persist FIRST, then activate. Only now does the identity change.
1053
+ const persisted = (0, key_store_js_1.persistPassportKey)(newKey);
1054
+ const activated = (0, key_store_js_1.setPassportKey)(newKey);
1055
+ if (!activated.ok) {
1056
+ return failClosed("ERROR", `the fresh key could not be activated (${activated.message}).`, "Get a fresh key from https://z-zero.xyz/dashboard/agents.");
1057
+ }
1058
+ if (!persisted) {
1059
+ console.error("[SET-KEY] ⚠️ Rotated key active in RAM but NOT persisted — re-connect with a fresh key from the dashboard after restart.");
1034
1060
  }
1035
1061
  return {
1036
1062
  content: [{
1037
1063
  type: "text",
1038
1064
  text: JSON.stringify({
1039
1065
  status: "SUCCESS",
1040
- message: rotated
1041
- ? "✅ 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."
1042
- : `✅ ${result.message}`,
1066
+ message: "✅ 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.",
1043
1067
  // Masked hint only — never echo a usable portion of the secret to the chat/model context.
1044
1068
  active_key_hint: maskKey((0, key_store_js_1.getPassportKey)()),
1045
- rotated_on_connect: rotated,
1046
- note: rotated
1047
- ? "One key = one agent: connecting another agent/machine with this account's key will disconnect this one."
1048
- : "All subsequent API calls will use this key. Previous key removed from this session (soft revoke).",
1069
+ rotated_on_connect: true,
1070
+ ...(persisted ? {} : { persist_warning: "The fresh key is active in memory but could not be written to ~/.z-zero/credentials — after a restart, get a fresh key from the dashboard." }),
1071
+ note: "One key = one agent: connecting another agent/machine with this account's key will disconnect this one.",
1049
1072
  }, null, 2),
1050
1073
  }],
1051
1074
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "z-zero-mcp-server",
3
- "version": "1.10.0",
3
+ "version": "1.10.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": {