@ainecto/cli 0.12.1 → 0.12.2

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/bin/mcp.js CHANGED
@@ -214,7 +214,7 @@ function legacyRoleInput(flag, envVars = process.env) {
214
214
  }
215
215
 
216
216
  // src/core/version.ts
217
- var CLI_VERSION = true ? "0.12.1" : UNBUNDLED_VERSION;
217
+ var CLI_VERSION = true ? "0.12.2" : UNBUNDLED_VERSION;
218
218
  var PACKAGE_NAME = "@ainecto/mcp";
219
219
  var CLI_USER_AGENT = `${PACKAGE_NAME} ${CLI_VERSION}`;
220
220
 
@@ -288,7 +288,7 @@ var McpRpcClient = class {
288
288
  const details = rateLimitDetails(void 0, response.error.data);
289
289
  throw new RateLimitedError(rateLimitMessage(`MCP ${method}`, details), details);
290
290
  }
291
- throw new McpRpcError(response.error.message, "MCP_ERROR", response.error);
291
+ throw new McpRpcError(describeRpcError(response.error), "MCP_ERROR", response.error);
292
292
  }
293
293
  return response.result;
294
294
  }
@@ -309,6 +309,10 @@ var McpRpcClient = class {
309
309
  return rateLimitedResponse(text, response.headers.get("retry-after"));
310
310
  }
311
311
  if (!response.ok) {
312
+ const envelope = rpcErrorEnvelope(text);
313
+ if (envelope) {
314
+ return envelope;
315
+ }
312
316
  const serverError = parseServerError(text);
313
317
  throw new McpRpcError(
314
318
  `MCP HTTP request failed with HTTP ${response.status}${serverError ? ` \u2014 ${describeServerError(serverError)}` : "."}`,
@@ -352,23 +356,39 @@ var McpRpcClient = class {
352
356
  }
353
357
  };
354
358
  function rateLimitedResponse(text, retryAfter) {
355
- let parsed;
356
- try {
357
- parsed = JSON.parse(text);
358
- } catch {
359
- parsed = void 0;
360
- }
361
- if (isJsonRpcResponse(parsed) && "error" in parsed) {
362
- const data = isRecord3(parsed.error.data) ? parsed.error.data : {};
359
+ const envelope = rpcErrorEnvelope(text);
360
+ if (envelope) {
361
+ const data = isRecord3(envelope.error.data) ? envelope.error.data : {};
363
362
  const seconds = parseRetryAfter(retryAfter);
364
363
  if (data.retryAfterSeconds === void 0 && seconds !== void 0) {
365
- parsed.error.data = { ...data, retryAfterSeconds: seconds };
364
+ envelope.error.data = { ...data, retryAfterSeconds: seconds };
366
365
  }
367
- return parsed;
366
+ return envelope;
368
367
  }
369
- const details = rateLimitDetails(retryAfter, parsed);
368
+ const details = rateLimitDetails(retryAfter, parseJsonOrUndefined(text));
370
369
  throw new RateLimitedError(rateLimitMessage("MCP HTTP request", details), details);
371
370
  }
371
+ function rpcErrorEnvelope(text) {
372
+ const parsed = parseJsonOrUndefined(text);
373
+ return isJsonRpcResponse(parsed) && "error" in parsed && isRecord3(parsed.error) ? parsed : void 0;
374
+ }
375
+ function parseJsonOrUndefined(text) {
376
+ try {
377
+ return JSON.parse(text);
378
+ } catch {
379
+ return void 0;
380
+ }
381
+ }
382
+ function describeRpcError(error) {
383
+ const data = isRecord3(error.data) ? error.data : {};
384
+ const messages = isRecord3(data.messages) ? data.messages : {};
385
+ const sentence = [error.message, data.message, messages.en, messages.ko].find((value) => typeof value === "string" && value.trim() !== "");
386
+ const code = typeof data.code === "string" && data.code.trim() ? data.code.trim() : void 0;
387
+ if (!code) {
388
+ return sentence ?? `JSON-RPC error ${error.code}`;
389
+ }
390
+ return describeServerError({ error: code, description: sentence });
391
+ }
372
392
  function agentHeaderValue(clientName) {
373
393
  return printableHeaderValue(clientName);
374
394
  }