@totalreclaw/mcp-server 3.5.1-rc.1 → 3.5.1-rc.3

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
@@ -205,7 +205,13 @@ explicitly, not silently unsupported:
205
205
  - **No OS-keychain unwrap.** MCP only reads the plaintext ("headless / no
206
206
  keychain") bundle storage form. A `version: 2` file with
207
207
  `"keychain_wrapped": true` (the desktop-keychain storage form Hermes
208
- writes) is a loud, actionable error, not a silent skip.
208
+ writes), or Hermes' older `__keychain__:v1:` marker file, is not read. The
209
+ server starts unconfigured and every tool call returns `not_configured`
210
+ with `reason: "keychain_wrapped"` and an explanation (before 3.5.1 the
211
+ server exited at startup, so the host showed no tools). `totalreclaw_pair`
212
+ refuses to overwrite the file. The same applies to an unknown `version`
213
+ (`reason: "unknown_version"`). A `version: 2` bundle that fails validation
214
+ is still fatal at startup.
209
215
  - **No `TOTALRECLAW_CREDENTIALS_PROVIDER` / external-secret-manager
210
216
  transport.** MCP always reads `credentials.json` from disk (or
211
217
  `TOTALRECLAW_CREDENTIALS_PATH`) — it has no `file` / `external` provider
@@ -78,11 +78,26 @@ export interface DispatchDeps {
78
78
  authHintResponse: () => ToolResponse;
79
79
  /** Invalidate the memory-context resource cache + notify subscribers. */
80
80
  onMutate: () => void;
81
+ /**
82
+ * Set when startup found a credentials file it could not use (see
83
+ * `UnusableCredentials`). Unconfigured-mode responses then explain that
84
+ * instead of the generic setup guidance.
85
+ */
86
+ getUnusableCredentials?: () => UnusableCredentials | undefined;
81
87
  }
82
88
  /** Response for the removed `totalreclaw_setup` tool (phrase-safety, 3.2.1). */
83
89
  export declare function setupRemovedResponse(): ToolResponse;
90
+ /**
91
+ * Why the server is unconfigured even though a credentials file exists: a
92
+ * file written by another TotalReclaw client in a form this server can't
93
+ * read (see `UnsupportedCredentialsError` in `subgraph/credentials.ts`).
94
+ */
95
+ export interface UnusableCredentials {
96
+ reason: 'keychain_wrapped' | 'unknown_version';
97
+ message: string;
98
+ }
84
99
  /** Response when a tool is called before the server is configured. */
85
- export declare function notConfiguredResponse(): ToolResponse;
100
+ export declare function notConfiguredResponse(unusable?: UnusableCredentials): ToolResponse;
86
101
  /** Response for a tool name with no handler in the active mode. */
87
102
  export declare function unknownToolResponse(name: string): ToolResponse;
88
103
  /** Response for an uncaught handler error that is neither quota nor auth. */
@@ -1 +1 @@
1
- {"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../src/dispatch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oCAAoC,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAqBrD,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,cAAc,CAAC;AAE9D;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAsBrB,IAAI,EAAE,CAAC;AAEZ,8EAA8E;AAC9E,MAAM,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;AAEnE,kEAAkE;AAClE,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;AAEjE;;;;;;;;GAQG;AACH,MAAM,WAAW,UAAU;IACzB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,0DAA0D;AAC1D,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAQtD,CAAC;AAEF,kDAAkD;AAClD,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAKlD,CAAC;AAEF,8EAA8E;AAC9E,MAAM,WAAW,YAAY;IAC3B,mEAAmE;IACnE,OAAO,EAAE,MAAM,UAAU,CAAC;IAC1B,sDAAsD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F,wBAAgB,oBAAoB,IAAI,YAAY,CAiBnD;AAED;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,kBAAkB,GAAG,iBAAiB,CAAC;IAC/C,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,sEAAsE;AACtE,wBAAgB,qBAAqB,CAAC,QAAQ,CAAC,EAAE,mBAAmB,GAAG,YAAY,CA8BlF;AAED,mEAAmE;AACnE,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAK9D;AAED,6EAA6E;AAC7E,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,CAQjE;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,YAAY,GACjB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,YAAY,CAAC,CA+CxD"}
package/dist/dispatch.js CHANGED
@@ -98,7 +98,21 @@ function setupRemovedResponse() {
98
98
  };
99
99
  }
100
100
  /** Response when a tool is called before the server is configured. */
101
- function notConfiguredResponse() {
101
+ function notConfiguredResponse(unusable) {
102
+ if (unusable) {
103
+ return {
104
+ content: [{
105
+ type: 'text',
106
+ text: JSON.stringify({
107
+ error: 'not_configured',
108
+ reason: unusable.reason,
109
+ message: `${unusable.message} Tell the user this plainly. Do not call totalreclaw_pair ` +
110
+ '(it would refuse), and do not move, rename or delete the credentials file.',
111
+ }),
112
+ }],
113
+ isError: true,
114
+ };
115
+ }
102
116
  return {
103
117
  content: [{
104
118
  type: 'text',
@@ -148,7 +162,7 @@ function createCallToolHandler(deps) {
148
162
  // 4. Unconfigured: everything else returns setup guidance.
149
163
  const mode = deps.getMode();
150
164
  if (mode === 'unconfigured')
151
- return notConfiguredResponse();
165
+ return notConfiguredResponse(deps.getUnusableCredentials?.());
152
166
  // 5. Configured dispatch, wrapped in the shared quota → auth → generic funnel.
153
167
  try {
154
168
  // Mode-independent tools (status / upgrade / account)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Ae,CAAC,CAAC,CAAC,mBAAW,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YAEjF,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;gBACtB,IAAI,CAAC;oBACH,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;oBACnC,IAAI,MAAM,CAAC,eAAe;wBAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;oBAC5C,OAAO,MAAM,CAAC;gBAChB,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,IAAI,IAAI,CAAC,oBAAoB,CAAC,KAAK,CAAC;wBAAE,OAAO,IAAI,CAAC,qBAAqB,EAAE,CAAC;oBAC1E,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;YAED,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;YACnC,IAAI,MAAM,CAAC,eAAe;gBAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC5C,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,IAAI,CAAC,oBAAoB,CAAC,KAAK,CAAC;gBAAE,OAAO,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAC1E,IAAI,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;gBAAE,OAAO,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC5D,OAAO,oBAAoB,CAAC,KAAK,CAAC,CAAC;QACrC,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAkLA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAwLA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,CAAC"}
package/dist/index.js CHANGED
@@ -162,6 +162,13 @@ function resolveMnemonic() {
162
162
  return undefined;
163
163
  }
164
164
  let currentMode = 'unconfigured';
165
+ /**
166
+ * Set at startup when credentials.json exists but this server can't use it
167
+ * (OS-keychain-wrapped, or an unknown `version`). The server then runs
168
+ * unconfigured and says why on every tool call; `totalreclaw_pair` refuses
169
+ * to overwrite the file either way.
170
+ */
171
+ let unusableCredentials;
165
172
  // Store-time near-duplicate detection is always ON in v1.
166
173
  // The TOTALRECLAW_STORE_DEDUP env var was removed.
167
174
  const STORE_DEDUP_ENABLED = true;
@@ -229,8 +236,36 @@ function stateWriteOverrides(state) {
229
236
  walletAddress: state.smartAccountAddress,
230
237
  chainId: state.chainId,
231
238
  dataEdgeAddress: state.dataEdgeAddress,
239
+ chainResolved: state.chainResolved,
232
240
  });
233
241
  }
242
+ /** Billing lookup for a state, with retries; shared by init and the lazy write path. */
243
+ function lookupChainConfig(state, label, retry = chain_config_js_1.WRITE_BILLING_RETRY) {
244
+ return (0, chain_config_js_1.fetchChainConfigWithRetry)({
245
+ serverUrl: state.serverUrl,
246
+ smartAccountAddress: state.smartAccountAddress,
247
+ authKeyHex: Buffer.from(state.authKey).toString('hex'),
248
+ headers: buildRelayHeaders(),
249
+ fallbackChainId: state.chainId,
250
+ onResolved: (billing, resolved) => {
251
+ console.error(`TotalReclaw: ${label}tier=${billing.tier ?? 'unknown'}, chain=${resolved.chainId}` +
252
+ (resolved.dataEdgeAddress ? `, dataEdge=${resolved.dataEdgeAddress}` : '') + '.');
253
+ },
254
+ onBillingUnavailable: (reason) => {
255
+ console.error(`TotalReclaw: ${label}billing lookup failed (${reason}).`);
256
+ },
257
+ }, retry);
258
+ }
259
+ /**
260
+ * The write config for a managed-service write (#439 chain/DataEdge + #581
261
+ * signing source). #689: resolves chain + DataEdge first if startup could
262
+ * not, and throws `DataEdgeUnresolvedError` (write not sent) if it still
263
+ * can't. Every on-chain write site goes through here.
264
+ */
265
+ async function writeConfigFor(state) {
266
+ await (0, chain_config_js_1.ensureWriteChainResolved)(state, () => lookupChainConfig(state, 'write-time '), process.env.TOTALRECLAW_DATA_EDGE_ADDRESS, state.serverUrl);
267
+ return (0, store_js_1.getSubgraphConfig)(stateWriteOverrides(state));
268
+ }
234
269
  let subgraphState = null;
235
270
  /**
236
271
  * Detect server mode based on environment configuration.
@@ -268,7 +303,6 @@ async function initSubgraphState(mnemonic) {
268
303
  // First derive on Base Sepolia (free tier default), then query billing to detect
269
304
  // Pro tier and switch to Gnosis if needed.
270
305
  const entryPointAddr = (process.env.TOTALRECLAW_ENTRYPOINT_ADDRESS || account_abstraction_1.entryPoint07Address);
271
- const authKeyHex = Buffer.from(authKey).toString('hex');
272
306
  const ownerAccount = (0, accounts_1.mnemonicToAccount)(mnemonic);
273
307
  // Smart Account address is deterministic via CREATE2 — use Base Sepolia for derivation
274
308
  // (same address regardless of chain).
@@ -293,38 +327,10 @@ async function initSubgraphState(mnemonic) {
293
327
  // relay's values verbatim means a future chain move needs zero client release.
294
328
  // (The client `TOTALRECLAW_CHAIN_ID` override was removed in v1.)
295
329
  //
296
- // #581 P2-13: this is now `fetchChainConfig` (subgraph/chain-config.ts) —
297
- // the SAME function `initSubgraphStateFromBundle` below calls, so there is
298
- // no code path that can independently "forget" to make this call.
330
+ // #581 P2-13: the billing lookup is shared with `initSubgraphStateFromBundle`
331
+ // (`fetchChainConfig`, here via `lookupChainConfig`'s retry wrapper), so no
332
+ // code path can independently "forget" to make this call.
299
333
  //
300
- // Mnemonic mode keeps the pre-existing #439 behaviour on a failed billing
301
- // lookup: fall back to the Gnosis default / no DataEdge override (the
302
- // store then falls to env / its own PROD default) rather than blocking
303
- // startup. #618 adversarial-review fixup: that silent fallback used to
304
- // have NO log line at all when the billing call failed outright — add
305
- // one, naming the prod default explicitly, so a mnemonic-mode write that
306
- // silently lands on production (e.g. a staging run with an unreachable
307
- // relay and no TOTALRECLAW_DATA_EDGE_ADDRESS override) leaves a trace in
308
- // stderr instead of looking identical to a normal write.
309
- const { chainId, dataEdgeAddress, billingResolved } = await (0, chain_config_js_1.fetchChainConfig)({
310
- serverUrl: SERVER_URL,
311
- smartAccountAddress,
312
- authKeyHex,
313
- headers: buildRelayHeaders(),
314
- fallbackChainId: 100, // Gnosis default when billing is unreachable
315
- onResolved: (billing, resolved) => {
316
- console.error(`TotalReclaw: tier=${billing.tier ?? 'unknown'}, chain=${resolved.chainId}` +
317
- (resolved.dataEdgeAddress ? `, dataEdge=${resolved.dataEdgeAddress}` : '') + '.');
318
- },
319
- onBillingUnavailable: (reason) => {
320
- console.error(`TotalReclaw: billing lookup failed (${reason}).`);
321
- },
322
- });
323
- if (!billingResolved && !process.env.TOTALRECLAW_DATA_EDGE_ADDRESS) {
324
- console.error(`TotalReclaw: proceeding without a confirmed DataEdge — writes will target the ` +
325
- `PRODUCTION default (${store_js_1.DEFAULT_DATA_EDGE_ADDRESS}) unless TOTALRECLAW_DATA_EDGE_ADDRESS ` +
326
- 'is set. Retry once the relay is reachable if this is not the intended environment.');
327
- }
328
334
  // Register auth key with relay (idempotent — relay returns 200 for existing users).
329
335
  // Without this, all relay queries return 401 when using env var mnemonic path
330
336
  // (the setup wizard handles registration, but the env var path previously skipped it).
@@ -342,10 +348,24 @@ async function initSubgraphState(mnemonic) {
342
348
  await (0, setup_js_1.registerWithServer)(SERVER_URL, authKeyHashForReg, saltHexForReg);
343
349
  }
344
350
  catch {
345
- // Best-effort — if relay is unreachable, billing check above may have also failed.
351
+ // Best-effort — if the relay is unreachable, the billing lookup below may fail too.
346
352
  // The server returns 200 for already-registered users, so this only fails on network errors.
347
353
  console.error('TotalReclaw: Registration with relay failed (best-effort, will retry on next start).');
348
354
  }
355
+ // #689: registration runs first (above) so a just-created account's billing
356
+ // lookup doesn't fail on "unknown wallet". The lookup is retried with
357
+ // backoff; if it still fails, the state stays UNRESOLVED and the first
358
+ // write re-runs it (writeConfigFor). There is NO fallback to the production
359
+ // default DataEdge any more: before #689 a staging server on a cold relay
360
+ // wrote to production for its whole lifetime.
361
+ const envDataEdge = process.env.TOTALRECLAW_DATA_EDGE_ADDRESS;
362
+ const { chainId, dataEdgeAddress, billingResolved } = await lookupChainConfig({ serverUrl: SERVER_URL, smartAccountAddress, authKey, chainId: 100 }, // Gnosis default until billing answers
363
+ '', chain_config_js_1.STARTUP_BILLING_RETRY);
364
+ if (!billingResolved && !envDataEdge) {
365
+ console.error('TotalReclaw: DataEdge not confirmed yet (billing lookup failed). Recall works; the first ' +
366
+ 'write will retry the lookup and is refused if it still fails. Writes never fall back to ' +
367
+ `the production default (${store_js_1.DEFAULT_DATA_EDGE_ADDRESS}).`);
368
+ }
349
369
  return {
350
370
  mode: 'subgraph',
351
371
  credentialKind: 'mnemonic',
@@ -359,6 +379,7 @@ async function initSubgraphState(mnemonic) {
359
379
  smartAccountAddress,
360
380
  chainId,
361
381
  dataEdgeAddress,
382
+ chainResolved: billingResolved || !!envDataEdge,
362
383
  };
363
384
  }
364
385
  /**
@@ -404,10 +425,9 @@ async function initSubgraphState(mnemonic) {
404
425
  * `TOTALRECLAW_DATA_EDGE_ADDRESS` override now throws rather than
405
426
  * proceeding — bundle mode has no other way to learn which DataEdge
406
427
  * belongs to this environment, so guessing "production" is never
407
- * acceptable. Mnemonic mode (`initSubgraphState` above) deliberately
408
- * keeps the pre-existing #439 fallback instead of throwing — a
409
- * scoped, reviewed decision (loud `console.error` naming the prod
410
- * default, no throw), not an oversight.
428
+ * acceptable. Mnemonic mode (`initSubgraphState` above) no longer falls
429
+ * back to the prod default either (#689): it starts unresolved and
430
+ * resolves on the first write, refusing the write if it can't.
411
431
  *
412
432
  * Only `signing.kind === "owner-eoa"` is supported (Phase 2's shipping
413
433
  * configuration). A `session-key` bundle is parsed and validated fine at
@@ -428,22 +448,10 @@ async function initSubgraphStateFromBundle(bundle) {
428
448
  // account.smart_account is already resolved — no RPC round-trip, no
429
449
  // mnemonic-derived owner. See the docstring above, point 2.
430
450
  const smartAccountAddress = bundle.account.smart_account.toLowerCase();
431
- const authKeyHex = vault.authKey.toString('hex');
432
- // See the docstring above, point 4 — the load-bearing fix.
433
- const { chainId, dataEdgeAddress, billingResolved } = await (0, chain_config_js_1.fetchChainConfig)({
434
- serverUrl: SERVER_URL,
435
- smartAccountAddress,
436
- authKeyHex,
437
- headers: buildRelayHeaders(),
438
- fallbackChainId: bundle.account.chain_id,
439
- onResolved: (billing, resolved) => {
440
- console.error(`TotalReclaw: bundle-mode, tier=${billing.tier ?? 'unknown'}, chain=${resolved.chainId}` +
441
- (resolved.dataEdgeAddress ? `, dataEdge=${resolved.dataEdgeAddress}` : '') + '.');
442
- },
443
- onBillingUnavailable: (reason) => {
444
- console.error(`TotalReclaw: bundle-mode billing lookup failed (${reason}).`);
445
- },
446
- });
451
+ // See the docstring above, point 4 — the load-bearing fix. #689: retried
452
+ // with backoff like mnemonic mode; bundle mode still fails closed below if
453
+ // every attempt fails (it has no other source for the DataEdge).
454
+ const { chainId, dataEdgeAddress, billingResolved } = await lookupChainConfig({ serverUrl: SERVER_URL, smartAccountAddress, authKey: vault.authKey, chainId: bundle.account.chain_id }, 'bundle-mode, ', chain_config_js_1.STARTUP_BILLING_RETRY);
447
455
  // FAIL CLOSED (#618 adversarial review — the sibling variant of the S1
448
456
  // bug, see the docstring above, point 4). A bundle carries no
449
457
  // `data_edge_address` of its own — the ONLY source is this billing call.
@@ -483,6 +491,8 @@ async function initSubgraphStateFromBundle(bundle) {
483
491
  smartAccountAddress,
484
492
  chainId,
485
493
  dataEdgeAddress,
494
+ // assertDataEdgeResolvable above guarantees billing succeeded or an env override is set.
495
+ chainResolved: true,
486
496
  };
487
497
  }
488
498
  const clientState = {
@@ -645,6 +655,8 @@ async function handleRememberSubgraph(state, args) {
645
655
  // For batch mode (multiple facts from auto-extraction), apply full skip/supersede logic.
646
656
  const isExplicitRemember = !!input?.fact;
647
657
  const results = [];
658
+ // #689: why the batch was not sent (e.g. DataEdge unresolved), returned to the caller, not just logged.
659
+ let batchError;
648
660
  let dedupSkipped = 0;
649
661
  let dedupSuperseded = 0;
650
662
  // Collect protobuf payloads for batch submission (tombstones + facts)
@@ -909,7 +921,7 @@ async function handleRememberSubgraph(state, args) {
909
921
  // Batch-submit all payloads (tombstones + facts) in a single UserOp
910
922
  if (pendingPayloads.length > 0) {
911
923
  try {
912
- const batchConfig = (0, store_js_1.getSubgraphConfig)(stateWriteOverrides(state));
924
+ const batchConfig = await writeConfigFor(state);
913
925
  const batchResult = await (0, store_js_1.submitFactBatchOnChain)(pendingPayloads, batchConfig);
914
926
  for (const meta of pendingFactMeta) {
915
927
  results.push({
@@ -923,8 +935,9 @@ async function handleRememberSubgraph(state, args) {
923
935
  }
924
936
  catch (error) {
925
937
  const message = error instanceof Error ? error.message : 'Unknown error';
938
+ batchError = message;
926
939
  for (const meta of pendingFactMeta) {
927
- results.push({ success: false, fact_id: meta.factId, tx_hash: undefined });
940
+ results.push({ success: false, fact_id: meta.factId, tx_hash: undefined, error: message });
928
941
  }
929
942
  console.error(`Batch submission failed: ${message}`);
930
943
  }
@@ -942,6 +955,7 @@ async function handleRememberSubgraph(state, args) {
942
955
  dedup_skipped: dedupSkipped,
943
956
  dedup_superseded: dedupSuperseded,
944
957
  mode: 'subgraph',
958
+ ...(batchError ? { error: batchError } : {}),
945
959
  }),
946
960
  }],
947
961
  };
@@ -1008,7 +1022,7 @@ async function handleDebriefSubgraph(state, args) {
1008
1022
  agentId: 'mcp-server',
1009
1023
  encryptedEmbedding: encryptedEmb,
1010
1024
  };
1011
- const batchConfig = (0, store_js_1.getSubgraphConfig)(stateWriteOverrides(state));
1025
+ const batchConfig = await writeConfigFor(state);
1012
1026
  const batchResult = await (0, store_js_1.submitFactBatchOnChain)([(0, store_js_1.encodeFactProtobuf)(factPayload)], batchConfig);
1013
1027
  console.error(`Crystal debrief stored (tx=${batchResult.txHash.slice(0, 10)}...)`);
1014
1028
  return {
@@ -1074,9 +1088,10 @@ async function handleDebriefSubgraph(state, args) {
1074
1088
  }
1075
1089
  }
1076
1090
  const results = [];
1091
+ let batchError;
1077
1092
  if (pendingPayloads.length > 0) {
1078
1093
  try {
1079
- const batchConfig = (0, store_js_1.getSubgraphConfig)(stateWriteOverrides(state));
1094
+ const batchConfig = await writeConfigFor(state);
1080
1095
  const batchResult = await (0, store_js_1.submitFactBatchOnChain)(pendingPayloads, batchConfig);
1081
1096
  for (const meta of pendingFactMeta) {
1082
1097
  results.push({ success: batchResult.success, fact_id: meta.factId, tx_hash: batchResult.txHash });
@@ -1084,15 +1099,16 @@ async function handleDebriefSubgraph(state, args) {
1084
1099
  console.error(`Debrief: submitted ${batchResult.batchSize} items (tx=${batchResult.txHash.slice(0, 10)}...)`);
1085
1100
  }
1086
1101
  catch (error) {
1102
+ batchError = error instanceof Error ? error.message : String(error);
1087
1103
  for (const meta of pendingFactMeta) {
1088
- results.push({ success: false, fact_id: meta.factId });
1104
+ results.push({ success: false, fact_id: meta.factId, error: batchError });
1089
1105
  }
1090
- console.error(`Debrief batch submission failed: ${error instanceof Error ? error.message : String(error)}`);
1106
+ console.error(`Debrief batch submission failed: ${batchError}`);
1091
1107
  }
1092
1108
  }
1093
1109
  const stored = results.filter((r) => r.success).length;
1094
1110
  return {
1095
- content: [{ type: 'text', text: JSON.stringify({ success: stored > 0, stored, total: validated.length, results }) }],
1111
+ content: [{ type: 'text', text: JSON.stringify({ success: stored > 0, stored, total: validated.length, results, ...(batchError ? { error: batchError } : {}) }) }],
1096
1112
  };
1097
1113
  }
1098
1114
  /**
@@ -1311,7 +1327,7 @@ async function handleForgetSubgraph(state, args) {
1311
1327
  agentId: 'mcp-server',
1312
1328
  };
1313
1329
  const protobuf = (0, store_js_1.encodeFactProtobuf)(tombstonePayload);
1314
- const config = (0, store_js_1.getSubgraphConfig)(stateWriteOverrides(state));
1330
+ const config = await writeConfigFor(state);
1315
1331
  const { txHash, success } = await (0, store_js_1.submitFactOnChain)(protobuf, config);
1316
1332
  // Read-after-write: poll the subgraph until the fact is no longer
1317
1333
  // active (forget flips isActive=false). On timeout we still report
@@ -1375,7 +1391,7 @@ function buildPinDepsFromState(state) {
1375
1391
  return Buffer.from(base64, 'base64').toString('hex');
1376
1392
  },
1377
1393
  submitBatch: async (payloads) => {
1378
- const config = (0, store_js_1.getSubgraphConfig)(stateWriteOverrides(state));
1394
+ const config = await writeConfigFor(state);
1379
1395
  const batchResult = await (0, store_js_1.submitFactBatchOnChain)(payloads, config);
1380
1396
  return { txHash: batchResult.txHash, success: batchResult.success };
1381
1397
  },
@@ -1623,7 +1639,10 @@ async function resolveBundle(mode) {
1623
1639
  const callToolHandler = (0, dispatch_js_1.createCallToolHandler)({
1624
1640
  getMode: () => currentMode,
1625
1641
  handleSupport: (args) => (0, index_js_1.handleSupport)({ walletAddress: subgraphState?.smartAccountAddress ?? null }, args),
1626
- handlePair: (args) => (0, index_js_1.handlePair)({}, args),
1642
+ handlePair: (args) => (0, index_js_1.handlePair)({}, args, {
1643
+ isConfigured: () => currentMode !== 'unconfigured',
1644
+ getUnusableCredentials: () => unusableCredentials,
1645
+ }),
1627
1646
  common: commonHandlers,
1628
1647
  resolveBundle,
1629
1648
  isQuotaExceededError,
@@ -1631,6 +1650,7 @@ const callToolHandler = (0, dispatch_js_1.createCallToolHandler)({
1631
1650
  isAuthError,
1632
1651
  authHintResponse,
1633
1652
  onMutate,
1653
+ getUnusableCredentials: () => unusableCredentials,
1634
1654
  });
1635
1655
  // ── Show-phrase CLI subcommand ────────────────────────────────────────────────
1636
1656
  async function showPhrase() {
@@ -1709,19 +1729,32 @@ async function main() {
1709
1729
  credential = (0, credentials_js_1.resolveManagedCredential)();
1710
1730
  }
1711
1731
  catch (err) {
1712
- // Loud, actionable, FATAL — never a silent downgrade. An unknown
1713
- // credentials.json `version`, a `keychain_wrapped` file this server
1714
- // can't unwrap, or a bundle that fails §4.7 validation are all
1715
- // evidence of a corrupted/tampered/misconfigured credential store,
1716
- // not transient conditions to paper over with a caught exception.
1717
- // Crashing the process with the error on stderr IS the correct loud
1718
- // posture for a long-running server — see derived-bundle-v1.md §3.2's
1719
- // "the one place a well-meaning try/except would create a security
1720
- // bug" warning, and mcp/tests/credentials.test.ts's coverage of every
1721
- // one of these throw paths.
1722
- const msg = err instanceof Error ? err.message : String(err);
1723
- console.error(`TotalReclaw MCP: fatal credential error: ${msg}`);
1724
- throw err;
1732
+ if (err instanceof credentials_js_1.UnsupportedCredentialsError) {
1733
+ // A real credential from another client (Hermes keychain storage)
1734
+ // or a newer client (unknown `version`) that this server can't
1735
+ // read. Not evidence of tampering, so start UNCONFIGURED instead of
1736
+ // crashing: a crash makes the host drop every tool and leaves the
1737
+ // reason in a log the user never sees. Still not a downgrade —
1738
+ // nothing in the file is used — and the reason is returned on every
1739
+ // tool call (dispatch.ts notConfiguredResponse). totalreclaw_pair
1740
+ // refuses to overwrite the file.
1741
+ unusableCredentials = { reason: err.reason, message: err.message };
1742
+ currentMode = 'unconfigured';
1743
+ console.error(`TotalReclaw MCP server started (unconfigured): ${err.message}`);
1744
+ }
1745
+ else {
1746
+ // Loud, actionable, FATAL — never a silent downgrade. A bundle that
1747
+ // fails §4.7 validation is evidence of a corrupted/tampered
1748
+ // credential store, not a transient condition to paper over with a
1749
+ // caught exception. Crashing the process with the error on stderr
1750
+ // IS the correct loud posture — see derived-bundle-v1.md §3.2's "the
1751
+ // one place a well-meaning try/except would create a security bug"
1752
+ // warning, and mcp/tests/credentials.test.ts's coverage of the
1753
+ // throw paths.
1754
+ const msg = err instanceof Error ? err.message : String(err);
1755
+ console.error(`TotalReclaw MCP: fatal credential error: ${msg}`);
1756
+ throw err;
1757
+ }
1725
1758
  }
1726
1759
  if (credential?.kind === 'bundle') {
1727
1760
  currentMode = 'subgraph';
@@ -1733,9 +1766,9 @@ async function main() {
1733
1766
  subgraphState = await initSubgraphState(credential.mnemonic);
1734
1767
  console.error(`TotalReclaw MCP server started (managed service, owner: ${subgraphState.smartAccountAddress})`);
1735
1768
  }
1736
- else {
1769
+ else if (!unusableCredentials) {
1737
1770
  currentMode = 'unconfigured';
1738
- console.error('TotalReclaw MCP server started (unconfigured — set TOTALRECLAW_RECOVERY_PHRASE in the MCP host config; see docs/guides/claude-code-setup.md)');
1771
+ console.error('TotalReclaw MCP server started (unconfigured — ask the assistant to run totalreclaw_pair to set up an account)');
1739
1772
  }
1740
1773
  }
1741
1774
  // ── Trajectory poller (mcp-server 3.3.0-rc.3) ─────────────────────────