@ai-ecoverse/mcpcat 0.17.3 → 0.17.5

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.
@@ -8453,22 +8453,20 @@ function mcpNameForMethod(method, params) {
8453
8453
  function makeAbort(timeoutMs, externalSignal) {
8454
8454
  const controller = new AbortController();
8455
8455
  const timer = setTimeout(() => controller.abort(), timeoutMs);
8456
- if (externalSignal) {
8457
- if (externalSignal.aborted) {
8456
+ const onAbort = () => {
8457
+ clearTimeout(timer);
8458
+ controller.abort();
8459
+ };
8460
+ if (externalSignal?.aborted) onAbort();
8461
+ else externalSignal?.addEventListener("abort", onAbort, { once: true });
8462
+ return {
8463
+ controller,
8464
+ stopTimer: () => clearTimeout(timer),
8465
+ detach: () => {
8458
8466
  clearTimeout(timer);
8459
- controller.abort();
8460
- } else {
8461
- externalSignal.addEventListener(
8462
- "abort",
8463
- () => {
8464
- clearTimeout(timer);
8465
- controller.abort();
8466
- },
8467
- { once: true }
8468
- );
8467
+ externalSignal?.removeEventListener("abort", onAbort);
8469
8468
  }
8470
- }
8471
- return { controller, timer };
8469
+ };
8472
8470
  }
8473
8471
  function logHeaders(verbose, dir, entries) {
8474
8472
  for (const [k, v] of entries) {
@@ -8586,7 +8584,7 @@ async function createStatelessConnection(options) {
8586
8584
  verbose.request(method, body);
8587
8585
  logHeaders(verbose, ">", Object.entries(headers));
8588
8586
  }
8589
- const { controller, timer } = makeAbort(timeoutMs, externalSignal);
8587
+ const { controller, stopTimer, detach } = makeAbort(timeoutMs, externalSignal);
8590
8588
  try {
8591
8589
  const res = await fetchImpl(url, {
8592
8590
  method: "POST",
@@ -8598,14 +8596,15 @@ async function createStatelessConnection(options) {
8598
8596
  verbose.http("<", `HTTP/1.1 ${res.status} ${res.statusText}`);
8599
8597
  logHeaders(verbose, "<", res.headers.entries());
8600
8598
  }
8601
- return { res, token };
8599
+ return { res, token, detach };
8602
8600
  } catch (err) {
8601
+ detach();
8603
8602
  if (controller.signal.aborted && !externalSignal?.aborted) {
8604
8603
  throw new McpTimeoutError2(method, timeoutMs);
8605
8604
  }
8606
8605
  throw err;
8607
8606
  } finally {
8608
- clearTimeout(timer);
8607
+ stopTimer();
8609
8608
  }
8610
8609
  }
8611
8610
  async function parseResponse(res, id) {
@@ -8654,19 +8653,22 @@ async function createStatelessConnection(options) {
8654
8653
  params: { ...cleanParams, _meta: meta }
8655
8654
  });
8656
8655
  for (let attempt = 0; attempt < 2; attempt++) {
8657
- const { res, token } = await doFetch(method, params, body);
8658
- if (res.status >= 400) {
8659
- try {
8660
- await handleErrorStatus(res, method);
8661
- } catch (err) {
8662
- if (err instanceof AuthRetryableError && attempt === 0) {
8663
- await handleAuthError(err, token);
8664
- continue;
8656
+ const { res, token, detach } = await doFetch(method, params, body);
8657
+ let retry;
8658
+ try {
8659
+ if (res.status >= 400) {
8660
+ try {
8661
+ await handleErrorStatus(res, method);
8662
+ } catch (err) {
8663
+ if (!(err instanceof AuthRetryableError && attempt === 0)) throw err;
8664
+ retry = err;
8665
8665
  }
8666
- throw err;
8667
8666
  }
8667
+ if (!retry) return await parseResponse(res, id);
8668
+ } finally {
8669
+ detach();
8668
8670
  }
8669
- return parseResponse(res, id);
8671
+ await handleAuthError(retry, token);
8670
8672
  }
8671
8673
  throw new McpAuthError(401, url);
8672
8674
  }
@@ -8858,6 +8860,19 @@ function createStdioJsonRpc(proc, platform2, options) {
8858
8860
  writer.releaseLock();
8859
8861
  }
8860
8862
  }
8863
+ function raceDeadline(linePromise, method, remaining) {
8864
+ let timer;
8865
+ let onAbort;
8866
+ const stop = new Promise((_, reject) => {
8867
+ timer = setTimeout(() => reject(new McpTimeoutError2(method, timeoutMs)), remaining);
8868
+ onAbort = () => reject(new McpTimeoutError2(method, timeoutMs));
8869
+ externalSignal?.addEventListener("abort", onAbort, { once: true });
8870
+ });
8871
+ return Promise.race([linePromise, stop]).finally(() => {
8872
+ clearTimeout(timer);
8873
+ if (onAbort) externalSignal?.removeEventListener("abort", onAbort);
8874
+ });
8875
+ }
8861
8876
  async function request(method, params) {
8862
8877
  const id = nextId2++;
8863
8878
  const meta = {
@@ -8881,11 +8896,7 @@ function createStdioJsonRpc(proc, platform2, options) {
8881
8896
  while (Date.now() < deadline) {
8882
8897
  const remaining = deadline - Date.now();
8883
8898
  if (externalSignal?.aborted) throw new McpTimeoutError2(method, timeoutMs);
8884
- const linePromise = readLine2();
8885
- const timeoutPromise = new Promise(
8886
- (_, reject) => setTimeout(() => reject(new McpTimeoutError2(method, timeoutMs)), remaining)
8887
- );
8888
- const line = await Promise.race([linePromise, timeoutPromise]);
8899
+ const line = await raceDeadline(readLine2(), method, remaining);
8889
8900
  const parsed = JSON.parse(line);
8890
8901
  if (verbose?.enabled) verbose.response(line);
8891
8902
  if (parsed.id === id) {
@@ -9118,6 +9129,9 @@ var CONTROL_RE = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f]/g;
9118
9129
  function sanitizeTerminal(text) {
9119
9130
  return text.replace(CONTROL_RE, (c) => `\\x${c.charCodeAt(0).toString(16).padStart(2, "0")}`);
9120
9131
  }
9132
+ function sanitizeJson(json) {
9133
+ return json.replace(CONTROL_RE, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
9134
+ }
9121
9135
 
9122
9136
  // src/client/elicit.ts
9123
9137
  function readLine(platform2) {
@@ -11018,8 +11032,8 @@ async function runFromDiscovery(platform2, args2) {
11018
11032
  }
11019
11033
  const result = parseEvents(text);
11020
11034
  if ("error" in result) {
11021
- await platform2.write(2, `mcpcat add --from-discovery: ${result.error}
11022
- `);
11035
+ await platform2.write(2, sanitizeTerminal(`mcpcat add --from-discovery: ${result.error}
11036
+ `));
11023
11037
  return result.code;
11024
11038
  }
11025
11039
  resetIdCounter();
@@ -11079,8 +11093,8 @@ async function runAddCandidate(platform2, name, candidateId2, configFile) {
11079
11093
  const { replaced } = await addServer(platform2.fs, path, name, config);
11080
11094
  for (const t of candidate.trust) {
11081
11095
  if (t.type.includes("mismatch")) {
11082
- await platform2.write(2, `mcpcat add: warning: ${t.type}: ${t.detail}
11083
- `);
11096
+ await platform2.write(2, sanitizeTerminal(`mcpcat add: warning: ${t.type}: ${t.detail}
11097
+ `));
11084
11098
  }
11085
11099
  }
11086
11100
  await platform2.write(1, `${replaced ? "replaced" : "added"} ${name} in ${path}
@@ -14221,7 +14235,7 @@ async function jerkLogin(platform2, target, resolved, args2) {
14221
14235
  return 0;
14222
14236
  }
14223
14237
  if (errText.trim()) {
14224
- await platform2.write(2, errText);
14238
+ await platform2.write(2, sanitizeTerminal(errText));
14225
14239
  }
14226
14240
  if (result.status === JERK_EXIT_SIGN_IN) return 4;
14227
14241
  return result.status;
@@ -16532,14 +16546,14 @@ async function handleInputRequired(platform2, conn, err, respondData, json) {
16532
16546
  const parsed2 = JSON.parse(err.requestJson);
16533
16547
  const inputReq = parseInputRequest(parsed2.result ?? parsed2);
16534
16548
  if (!inputReq) {
16535
- await platform2.write(2, `${err.requestJson}
16549
+ await platform2.write(2, `${sanitizeJson(err.requestJson)}
16536
16550
  `);
16537
16551
  return EXIT_INPUT_REQUIRED;
16538
16552
  }
16539
16553
  const isTty = platform2.kind === "host" && platform2.isatty(0) && platform2.isatty(2);
16540
16554
  const elicitResult = await handleElicitation(platform2, inputReq, isTty, respondData);
16541
16555
  if ("exitCode" in elicitResult) {
16542
- await platform2.write(2, `${err.requestJson}
16556
+ await platform2.write(2, `${sanitizeJson(err.requestJson)}
16543
16557
  `);
16544
16558
  return EXIT_INPUT_REQUIRED;
16545
16559
  }
@@ -17011,5 +17025,5 @@ try {
17011
17025
  });
17012
17026
  } catch {
17013
17027
  }
17014
- var code = await run(platform, "0.17.3", args);
17028
+ var code = await run(platform, "0.17.5", args);
17015
17029
  process.exit(code);
@@ -8074,22 +8074,20 @@ function mcpNameForMethod(method, params) {
8074
8074
  function makeAbort(timeoutMs, externalSignal) {
8075
8075
  const controller = new AbortController();
8076
8076
  const timer = setTimeout(() => controller.abort(), timeoutMs);
8077
- if (externalSignal) {
8078
- if (externalSignal.aborted) {
8077
+ const onAbort = () => {
8078
+ clearTimeout(timer);
8079
+ controller.abort();
8080
+ };
8081
+ if (externalSignal?.aborted) onAbort();
8082
+ else externalSignal?.addEventListener("abort", onAbort, { once: true });
8083
+ return {
8084
+ controller,
8085
+ stopTimer: () => clearTimeout(timer),
8086
+ detach: () => {
8079
8087
  clearTimeout(timer);
8080
- controller.abort();
8081
- } else {
8082
- externalSignal.addEventListener(
8083
- "abort",
8084
- () => {
8085
- clearTimeout(timer);
8086
- controller.abort();
8087
- },
8088
- { once: true }
8089
- );
8088
+ externalSignal?.removeEventListener("abort", onAbort);
8090
8089
  }
8091
- }
8092
- return { controller, timer };
8090
+ };
8093
8091
  }
8094
8092
  function logHeaders(verbose, dir, entries) {
8095
8093
  for (const [k, v] of entries) {
@@ -8207,7 +8205,7 @@ async function createStatelessConnection(options) {
8207
8205
  verbose.request(method, body);
8208
8206
  logHeaders(verbose, ">", Object.entries(headers));
8209
8207
  }
8210
- const { controller, timer } = makeAbort(timeoutMs, externalSignal);
8208
+ const { controller, stopTimer, detach } = makeAbort(timeoutMs, externalSignal);
8211
8209
  try {
8212
8210
  const res = await fetchImpl(url, {
8213
8211
  method: "POST",
@@ -8219,14 +8217,15 @@ async function createStatelessConnection(options) {
8219
8217
  verbose.http("<", `HTTP/1.1 ${res.status} ${res.statusText}`);
8220
8218
  logHeaders(verbose, "<", res.headers.entries());
8221
8219
  }
8222
- return { res, token };
8220
+ return { res, token, detach };
8223
8221
  } catch (err) {
8222
+ detach();
8224
8223
  if (controller.signal.aborted && !externalSignal?.aborted) {
8225
8224
  throw new McpTimeoutError2(method, timeoutMs);
8226
8225
  }
8227
8226
  throw err;
8228
8227
  } finally {
8229
- clearTimeout(timer);
8228
+ stopTimer();
8230
8229
  }
8231
8230
  }
8232
8231
  async function parseResponse(res, id) {
@@ -8275,19 +8274,22 @@ async function createStatelessConnection(options) {
8275
8274
  params: { ...cleanParams, _meta: meta }
8276
8275
  });
8277
8276
  for (let attempt = 0; attempt < 2; attempt++) {
8278
- const { res, token } = await doFetch(method, params, body);
8279
- if (res.status >= 400) {
8280
- try {
8281
- await handleErrorStatus(res, method);
8282
- } catch (err) {
8283
- if (err instanceof AuthRetryableError && attempt === 0) {
8284
- await handleAuthError(err, token);
8285
- continue;
8277
+ const { res, token, detach } = await doFetch(method, params, body);
8278
+ let retry;
8279
+ try {
8280
+ if (res.status >= 400) {
8281
+ try {
8282
+ await handleErrorStatus(res, method);
8283
+ } catch (err) {
8284
+ if (!(err instanceof AuthRetryableError && attempt === 0)) throw err;
8285
+ retry = err;
8286
8286
  }
8287
- throw err;
8288
8287
  }
8288
+ if (!retry) return await parseResponse(res, id);
8289
+ } finally {
8290
+ detach();
8289
8291
  }
8290
- return parseResponse(res, id);
8292
+ await handleAuthError(retry, token);
8291
8293
  }
8292
8294
  throw new McpAuthError(401, url);
8293
8295
  }
@@ -8479,6 +8481,19 @@ function createStdioJsonRpc(proc, platform2, options) {
8479
8481
  writer.releaseLock();
8480
8482
  }
8481
8483
  }
8484
+ function raceDeadline(linePromise, method, remaining) {
8485
+ let timer;
8486
+ let onAbort;
8487
+ const stop = new Promise((_, reject) => {
8488
+ timer = setTimeout(() => reject(new McpTimeoutError2(method, timeoutMs)), remaining);
8489
+ onAbort = () => reject(new McpTimeoutError2(method, timeoutMs));
8490
+ externalSignal?.addEventListener("abort", onAbort, { once: true });
8491
+ });
8492
+ return Promise.race([linePromise, stop]).finally(() => {
8493
+ clearTimeout(timer);
8494
+ if (onAbort) externalSignal?.removeEventListener("abort", onAbort);
8495
+ });
8496
+ }
8482
8497
  async function request(method, params) {
8483
8498
  const id = nextId2++;
8484
8499
  const meta = {
@@ -8502,11 +8517,7 @@ function createStdioJsonRpc(proc, platform2, options) {
8502
8517
  while (Date.now() < deadline) {
8503
8518
  const remaining = deadline - Date.now();
8504
8519
  if (externalSignal?.aborted) throw new McpTimeoutError2(method, timeoutMs);
8505
- const linePromise = readLine2();
8506
- const timeoutPromise = new Promise(
8507
- (_, reject) => setTimeout(() => reject(new McpTimeoutError2(method, timeoutMs)), remaining)
8508
- );
8509
- const line = await Promise.race([linePromise, timeoutPromise]);
8520
+ const line = await raceDeadline(readLine2(), method, remaining);
8510
8521
  const parsed = JSON.parse(line);
8511
8522
  if (verbose?.enabled) verbose.response(line);
8512
8523
  if (parsed.id === id) {
@@ -8739,6 +8750,9 @@ var CONTROL_RE = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f]/g;
8739
8750
  function sanitizeTerminal(text) {
8740
8751
  return text.replace(CONTROL_RE, (c) => `\\x${c.charCodeAt(0).toString(16).padStart(2, "0")}`);
8741
8752
  }
8753
+ function sanitizeJson(json) {
8754
+ return json.replace(CONTROL_RE, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
8755
+ }
8742
8756
 
8743
8757
  // src/client/elicit.ts
8744
8758
  function readLine(platform2) {
@@ -10639,8 +10653,8 @@ async function runFromDiscovery(platform2, args) {
10639
10653
  }
10640
10654
  const result = parseEvents(text);
10641
10655
  if ("error" in result) {
10642
- await platform2.write(2, `mcpcat add --from-discovery: ${result.error}
10643
- `);
10656
+ await platform2.write(2, sanitizeTerminal(`mcpcat add --from-discovery: ${result.error}
10657
+ `));
10644
10658
  return result.code;
10645
10659
  }
10646
10660
  resetIdCounter();
@@ -10700,8 +10714,8 @@ async function runAddCandidate(platform2, name, candidateId2, configFile) {
10700
10714
  const { replaced } = await addServer(platform2.fs, path, name, config);
10701
10715
  for (const t of candidate.trust) {
10702
10716
  if (t.type.includes("mismatch")) {
10703
- await platform2.write(2, `mcpcat add: warning: ${t.type}: ${t.detail}
10704
- `);
10717
+ await platform2.write(2, sanitizeTerminal(`mcpcat add: warning: ${t.type}: ${t.detail}
10718
+ `));
10705
10719
  }
10706
10720
  }
10707
10721
  await platform2.write(1, `${replaced ? "replaced" : "added"} ${name} in ${path}
@@ -13842,7 +13856,7 @@ async function jerkLogin(platform2, target, resolved, args) {
13842
13856
  return 0;
13843
13857
  }
13844
13858
  if (errText.trim()) {
13845
- await platform2.write(2, errText);
13859
+ await platform2.write(2, sanitizeTerminal(errText));
13846
13860
  }
13847
13861
  if (result.status === JERK_EXIT_SIGN_IN) return 4;
13848
13862
  return result.status;
@@ -16153,14 +16167,14 @@ async function handleInputRequired(platform2, conn, err, respondData, json) {
16153
16167
  const parsed2 = JSON.parse(err.requestJson);
16154
16168
  const inputReq = parseInputRequest(parsed2.result ?? parsed2);
16155
16169
  if (!inputReq) {
16156
- await platform2.write(2, `${err.requestJson}
16170
+ await platform2.write(2, `${sanitizeJson(err.requestJson)}
16157
16171
  `);
16158
16172
  return EXIT_INPUT_REQUIRED;
16159
16173
  }
16160
16174
  const isTty = platform2.kind === "host" && platform2.isatty(0) && platform2.isatty(2);
16161
16175
  const elicitResult = await handleElicitation(platform2, inputReq, isTty, respondData);
16162
16176
  if ("exitCode" in elicitResult) {
16163
- await platform2.write(2, `${err.requestJson}
16177
+ await platform2.write(2, `${sanitizeJson(err.requestJson)}
16164
16178
  `);
16165
16179
  return EXIT_INPUT_REQUIRED;
16166
16180
  }
@@ -16733,7 +16747,7 @@ async function main(ctx) {
16733
16747
  packageDir: "/node_modules/@ai-ecoverse/mcpcat"
16734
16748
  });
16735
16749
  const args = ctx.argv.slice(1);
16736
- return run(platform2, "0.17.3", args);
16750
+ return run(platform2, "0.17.5", args);
16737
16751
  }
16738
16752
  export {
16739
16753
  main as default
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-ecoverse/mcpcat",
3
- "version": "0.17.3",
3
+ "version": "0.17.5",
4
4
  "description": "A curl for the Model Context Protocol",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -61,15 +61,15 @@
61
61
  "trust:dry": "npx fledgling sync --dry-run -y --skip-publish"
62
62
  },
63
63
  "devDependencies": {
64
- "@ai-ecoverse/slicc-bios": "1.33.1",
65
- "@ai-ecoverse/slicc-kernel": "1.135.7",
64
+ "@ai-ecoverse/slicc-bios": "1.35.0",
65
+ "@ai-ecoverse/slicc-kernel": "1.141.2",
66
66
  "@ai-ecoverse/slicc-shared-web": "1.29.2",
67
67
  "@biomejs/biome": "2.5.15",
68
68
  "@earendil-works/pi-codemode": "1.2.0",
69
69
  "@earendil-works/pi-mcp": "1.2.0",
70
70
  "@types/node": "26.6.5",
71
71
  "esbuild": "0.28.2",
72
- "kernel-cert-new": "npm:@ai-ecoverse/slicc-kernel@1.135.7",
72
+ "kernel-cert-new": "npm:@ai-ecoverse/slicc-kernel@1.141.2",
73
73
  "lefthook": "2.2.2",
74
74
  "monocart-coverage-reports": "2.13.2",
75
75
  "proper-lockfile": "4.1.2",