@tronsfey/ucli 0.5.1 → 0.5.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.
@@ -5248,9 +5248,9 @@ var require_lib = __commonJS({
5248
5248
  }
5249
5249
  });
5250
5250
 
5251
- // ../../node_modules/.pnpm/@tronsfey+mcp2cli@1.0.2_zod@4.3.6/node_modules/@tronsfey/mcp2cli/dist/cache.js
5251
+ // ../../node_modules/.pnpm/@tronsfey+mcp2cli@1.3.0_zod@4.3.6/node_modules/@tronsfey/mcp2cli/dist/cache.js
5252
5252
  var require_cache = __commonJS({
5253
- "../../node_modules/.pnpm/@tronsfey+mcp2cli@1.0.2_zod@4.3.6/node_modules/@tronsfey/mcp2cli/dist/cache.js"(exports) {
5253
+ "../../node_modules/.pnpm/@tronsfey+mcp2cli@1.3.0_zod@4.3.6/node_modules/@tronsfey/mcp2cli/dist/cache.js"(exports) {
5254
5254
  "use strict";
5255
5255
  var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
5256
5256
  if (k2 === void 0) k2 = k;
@@ -5301,8 +5301,25 @@ var require_cache = __commonJS({
5301
5301
  return path.join(os.homedir(), ".mcp2cli", "cache");
5302
5302
  }
5303
5303
  function getCacheKey(config) {
5304
- const key = config.type === "http" ? config.url : config.command;
5305
- return crypto.createHash("md5").update(key).digest("hex");
5304
+ const parts = [];
5305
+ if (config.type === "http") {
5306
+ parts.push(config.url);
5307
+ if (config.headers && Object.keys(config.headers).length > 0) {
5308
+ const sorted = Object.keys(config.headers).sort();
5309
+ for (const k of sorted) {
5310
+ parts.push(`${k}=${config.headers[k]}`);
5311
+ }
5312
+ }
5313
+ } else {
5314
+ parts.push(config.command);
5315
+ if (config.env && Object.keys(config.env).length > 0) {
5316
+ const sorted = Object.keys(config.env).sort();
5317
+ for (const k of sorted) {
5318
+ parts.push(`${k}=${config.env[k]}`);
5319
+ }
5320
+ }
5321
+ }
5322
+ return crypto.createHash("sha256").update(parts.join("\0")).digest("hex");
5306
5323
  }
5307
5324
  function getCachePath(config) {
5308
5325
  return path.join(getCacheDir(), `${getCacheKey(config)}.json`);
@@ -5337,9 +5354,24 @@ var require_cache = __commonJS({
5337
5354
  }
5338
5355
  });
5339
5356
 
5340
- // ../../node_modules/.pnpm/@tronsfey+mcp2cli@1.0.2_zod@4.3.6/node_modules/@tronsfey/mcp2cli/dist/runner/index.js
5357
+ // ../../node_modules/.pnpm/@tronsfey+mcp2cli@1.3.0_zod@4.3.6/node_modules/@tronsfey/mcp2cli/dist/types/index.js
5358
+ var require_types = __commonJS({
5359
+ "../../node_modules/.pnpm/@tronsfey+mcp2cli@1.3.0_zod@4.3.6/node_modules/@tronsfey/mcp2cli/dist/types/index.js"(exports) {
5360
+ "use strict";
5361
+ Object.defineProperty(exports, "__esModule", { value: true });
5362
+ exports.EXIT_TOOL_EXECUTION = exports.EXIT_INVALID_ARGS = exports.EXIT_TOOL_NOT_FOUND = exports.EXIT_CONNECTION = exports.EXIT_GENERAL = exports.EXIT_OK = void 0;
5363
+ exports.EXIT_OK = 0;
5364
+ exports.EXIT_GENERAL = 1;
5365
+ exports.EXIT_CONNECTION = 2;
5366
+ exports.EXIT_TOOL_NOT_FOUND = 3;
5367
+ exports.EXIT_INVALID_ARGS = 4;
5368
+ exports.EXIT_TOOL_EXECUTION = 5;
5369
+ }
5370
+ });
5371
+
5372
+ // ../../node_modules/.pnpm/@tronsfey+mcp2cli@1.3.0_zod@4.3.6/node_modules/@tronsfey/mcp2cli/dist/runner/index.js
5341
5373
  var require_runner = __commonJS({
5342
- "../../node_modules/.pnpm/@tronsfey+mcp2cli@1.0.2_zod@4.3.6/node_modules/@tronsfey/mcp2cli/dist/runner/index.js"(exports) {
5374
+ "../../node_modules/.pnpm/@tronsfey+mcp2cli@1.3.0_zod@4.3.6/node_modules/@tronsfey/mcp2cli/dist/runner/index.js"(exports) {
5343
5375
  var __importDefault = exports && exports.__importDefault || function(mod) {
5344
5376
  return mod && mod.__esModule ? mod : { "default": mod };
5345
5377
  };
@@ -5348,12 +5380,18 @@ var require_runner = __commonJS({
5348
5380
  exports.schemaToParams = schemaToParams;
5349
5381
  exports.getTools = getTools;
5350
5382
  exports.printToolList = printToolList;
5383
+ exports.describeTool = describeTool;
5384
+ exports.printToolListJson = printToolListJson;
5385
+ exports.describeToolJson = describeToolJson;
5386
+ exports.emitJsonError = emitJsonError;
5387
+ exports.parseInputJson = parseInputJson;
5351
5388
  exports.coerceValue = coerceValue;
5352
5389
  exports.runTool = runTool;
5353
5390
  var commander_1 = __require("commander");
5354
5391
  var chalk_1 = __importDefault(require_source());
5355
5392
  var jmespath_1 = __importDefault(require_jmespath());
5356
5393
  var cache_1 = require_cache();
5394
+ var index_1 = require_types();
5357
5395
  var DEFAULT_CACHE_TTL = 3600;
5358
5396
  function toKebabCase(name) {
5359
5397
  return name.replace(/_/g, "-").replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
@@ -5392,10 +5430,18 @@ var require_runner = __commonJS({
5392
5430
  }
5393
5431
  async function getTools(client, config, options) {
5394
5432
  const ttl = options.cacheTtl ?? DEFAULT_CACHE_TTL;
5433
+ const debug = !!options.debug;
5395
5434
  if (!options.noCache) {
5396
5435
  const cached = await (0, cache_1.getCachedTools)(config, ttl);
5397
- if (cached)
5436
+ if (cached) {
5437
+ if (debug) {
5438
+ console.error(chalk_1.default.gray(`[debug] Loaded ${cached.length} tool(s) from cache (TTL: ${ttl}s)`));
5439
+ }
5398
5440
  return cached;
5441
+ }
5442
+ }
5443
+ if (debug) {
5444
+ console.error(chalk_1.default.gray(`[debug] Fetching tool list from server\u2026`));
5399
5445
  }
5400
5446
  const allTools = [];
5401
5447
  let cursor;
@@ -5404,11 +5450,27 @@ var require_runner = __commonJS({
5404
5450
  allTools.push(...result.tools);
5405
5451
  cursor = result.nextCursor;
5406
5452
  } while (cursor);
5453
+ if (debug) {
5454
+ console.error(chalk_1.default.gray(`[debug] Fetched ${allTools.length} tool(s): ${allTools.map((t) => t.name).join(", ")}`));
5455
+ }
5407
5456
  if (!options.noCache) {
5408
5457
  await (0, cache_1.setCachedTools)(config, allTools, ttl);
5409
5458
  }
5410
5459
  return allTools;
5411
5460
  }
5461
+ function formatParamLine(p) {
5462
+ const flag = p.required ? chalk_1.default.yellow(`--${p.cliFlag}`) : `--${p.cliFlag}`;
5463
+ const typeBadge = chalk_1.default.magenta(`<${p.type}>`);
5464
+ const reqBadge = p.required ? chalk_1.default.red("[required]") : chalk_1.default.gray("[optional]");
5465
+ const parts = [` ${flag} ${typeBadge} ${reqBadge}`];
5466
+ if (p.description)
5467
+ parts[0] += ` ${p.description}`;
5468
+ if (p.defaultValue !== void 0)
5469
+ parts[0] += chalk_1.default.gray(` (default: ${JSON.stringify(p.defaultValue)})`);
5470
+ if (p.enumValues)
5471
+ parts[0] += chalk_1.default.gray(` (choices: ${p.enumValues.join(", ")})`);
5472
+ return parts[0];
5473
+ }
5412
5474
  function printToolList(tools) {
5413
5475
  if (tools.length === 0) {
5414
5476
  console.log(chalk_1.default.yellow("No tools available."));
@@ -5424,22 +5486,118 @@ Available tools (${tools.length}):
5424
5486
  }
5425
5487
  const params = schemaToParams(tool);
5426
5488
  if (params.length > 0) {
5427
- const paramStr = params.map((p) => p.required ? chalk_1.default.yellow(`--${p.cliFlag}`) : `--${p.cliFlag}`).join(" ");
5428
- console.log(` ${paramStr}`);
5489
+ console.log(` ${chalk_1.default.bold("Parameters:")}`);
5490
+ for (const p of params) {
5491
+ console.log(formatParamLine(p));
5492
+ }
5429
5493
  }
5430
5494
  console.log();
5431
5495
  }
5432
5496
  }
5497
+ function describeTool(tool) {
5498
+ console.log(chalk_1.default.bold(`
5499
+ Tool: ${chalk_1.default.cyan(tool.name)}
5500
+ `));
5501
+ if (tool.description) {
5502
+ console.log(` ${tool.description}
5503
+ `);
5504
+ }
5505
+ const params = schemaToParams(tool);
5506
+ if (params.length === 0) {
5507
+ console.log(chalk_1.default.gray(" No parameters.\n"));
5508
+ return;
5509
+ }
5510
+ console.log(chalk_1.default.bold(" Parameters:\n"));
5511
+ for (const p of params) {
5512
+ console.log(formatParamLine(p));
5513
+ }
5514
+ console.log();
5515
+ }
5516
+ function printToolListJson(tools) {
5517
+ const items = tools.map((tool) => {
5518
+ const params = schemaToParams(tool);
5519
+ return {
5520
+ name: tool.name,
5521
+ description: tool.description ?? "",
5522
+ parameters: params.map((p) => ({
5523
+ name: p.name,
5524
+ cliFlag: `--${p.cliFlag}`,
5525
+ type: p.type,
5526
+ required: p.required,
5527
+ description: p.description,
5528
+ ...p.defaultValue !== void 0 ? { default: p.defaultValue } : {},
5529
+ ...p.enumValues ? { enum: p.enumValues } : {},
5530
+ ...p.itemsType ? { itemsType: p.itemsType } : {}
5531
+ })),
5532
+ inputSchema: tool.inputSchema
5533
+ };
5534
+ });
5535
+ const envelope = {
5536
+ ok: true,
5537
+ result: { tools: items, count: items.length }
5538
+ };
5539
+ console.log(JSON.stringify(envelope));
5540
+ }
5541
+ function describeToolJson(tool) {
5542
+ const params = schemaToParams(tool);
5543
+ const envelope = {
5544
+ ok: true,
5545
+ result: {
5546
+ name: tool.name,
5547
+ description: tool.description ?? "",
5548
+ parameters: params.map((p) => ({
5549
+ name: p.name,
5550
+ cliFlag: `--${p.cliFlag}`,
5551
+ type: p.type,
5552
+ required: p.required,
5553
+ description: p.description,
5554
+ ...p.defaultValue !== void 0 ? { default: p.defaultValue } : {},
5555
+ ...p.enumValues ? { enum: p.enumValues } : {},
5556
+ ...p.itemsType ? { itemsType: p.itemsType } : {}
5557
+ })),
5558
+ inputSchema: tool.inputSchema
5559
+ }
5560
+ };
5561
+ console.log(JSON.stringify(envelope));
5562
+ }
5563
+ function emitJsonError(code, message, exitCode, suggestions) {
5564
+ const envelope = {
5565
+ ok: false,
5566
+ error: { code, message, exitCode, ...suggestions?.length ? { suggestions } : {} }
5567
+ };
5568
+ process.stderr.write(JSON.stringify(envelope) + "\n");
5569
+ }
5570
+ function parseInputJson(jsonStr) {
5571
+ let parsed;
5572
+ try {
5573
+ parsed = JSON.parse(jsonStr);
5574
+ } catch {
5575
+ throw new Error(`Invalid JSON in --input-json: ${jsonStr}`);
5576
+ }
5577
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
5578
+ throw new Error('--input-json must be a JSON object (e.g. {"key": "value"})');
5579
+ }
5580
+ return parsed;
5581
+ }
5433
5582
  function formatResult(result, options) {
5434
5583
  let data = result;
5435
5584
  if (options.jq) {
5436
5585
  try {
5437
5586
  data = jmespath_1.default.search(data, options.jq);
5438
5587
  } catch (err) {
5588
+ if (options.json) {
5589
+ emitJsonError("JMESPATH_ERROR", `JMESPath error in "${options.jq}": ${err.message}`, index_1.EXIT_INVALID_ARGS);
5590
+ process.exit(index_1.EXIT_INVALID_ARGS);
5591
+ }
5439
5592
  console.error(chalk_1.default.red(`JMESPath error in "${options.jq}": ${err.message}`));
5440
- process.exit(1);
5593
+ process.exit(index_1.EXIT_INVALID_ARGS);
5441
5594
  }
5442
5595
  }
5596
+ if (options.json) {
5597
+ const envelope = { ok: true, result: data };
5598
+ console.log(JSON.stringify(envelope));
5599
+ return;
5600
+ }
5443
5601
  if (options.raw) {
5444
5602
  console.log(JSON.stringify(data, null, 2));
5445
5603
  return;
@@ -5490,64 +5648,96 @@ Available tools (${tools.length}):
5490
5648
  return value;
5491
5649
  }
5492
5650
  async function runTool(client, tool, rawArgs, options) {
5493
- const params = schemaToParams(tool);
5494
- const sub = new commander_1.Command(tool.name);
5495
- if (tool.description)
5496
- sub.description(tool.description);
5497
- for (const param of params) {
5498
- let flagStr;
5499
- if (param.type === "boolean") {
5500
- flagStr = `--${param.cliFlag}`;
5501
- } else if (param.type === "array") {
5502
- flagStr = `--${param.cliFlag} <values...>`;
5503
- } else {
5504
- flagStr = `--${param.cliFlag} <value>`;
5651
+ let toolArgs;
5652
+ if (options.inputJson) {
5653
+ try {
5654
+ toolArgs = parseInputJson(options.inputJson);
5655
+ } catch (err) {
5656
+ if (options.json) {
5657
+ emitJsonError("INVALID_INPUT_JSON", err.message, index_1.EXIT_INVALID_ARGS);
5658
+ process.exit(index_1.EXIT_INVALID_ARGS);
5659
+ }
5660
+ console.error(chalk_1.default.red(`Error: ${err.message}`));
5661
+ process.exit(index_1.EXIT_INVALID_ARGS);
5505
5662
  }
5506
- const opt = new commander_1.Option(flagStr, param.description);
5507
- if (param.required)
5508
- opt.makeOptionMandatory(true);
5509
- if (param.defaultValue !== void 0)
5510
- opt.default(param.defaultValue);
5511
- if (param.enumValues)
5512
- opt.choices(param.enumValues);
5513
- sub.addOption(opt);
5514
- }
5515
- sub.allowUnknownOption(false);
5516
- sub.exitOverride();
5517
- sub.configureOutput({
5518
- writeErr: (str) => process.stderr.write(str)
5519
- });
5520
- try {
5521
- sub.parse(["node", tool.name, ...rawArgs]);
5522
- } catch (err) {
5523
- const e = err;
5524
- if (e.code === "commander.missingMandatoryOptionValue" || e.code === "commander.optionMissingArgument") {
5525
- process.stderr.write(`${e.message ?? "Missing required option"}
5663
+ } else {
5664
+ const params = schemaToParams(tool);
5665
+ const sub = new commander_1.Command(tool.name);
5666
+ if (tool.description)
5667
+ sub.description(tool.description);
5668
+ for (const param of params) {
5669
+ let flagStr;
5670
+ if (param.type === "boolean") {
5671
+ flagStr = `--${param.cliFlag}`;
5672
+ } else if (param.type === "array") {
5673
+ flagStr = `--${param.cliFlag} <values...>`;
5674
+ } else {
5675
+ flagStr = `--${param.cliFlag} <value>`;
5676
+ }
5677
+ const opt = new commander_1.Option(flagStr, param.description);
5678
+ if (param.required)
5679
+ opt.makeOptionMandatory(true);
5680
+ if (param.defaultValue !== void 0)
5681
+ opt.default(param.defaultValue);
5682
+ if (param.enumValues)
5683
+ opt.choices(param.enumValues);
5684
+ sub.addOption(opt);
5685
+ }
5686
+ sub.allowUnknownOption(false);
5687
+ sub.exitOverride();
5688
+ sub.configureOutput({
5689
+ writeErr: (str) => {
5690
+ process.stderr.write(str);
5691
+ }
5692
+ });
5693
+ try {
5694
+ sub.parse(["node", tool.name, ...rawArgs]);
5695
+ } catch (err) {
5696
+ const e = err;
5697
+ if (e.code === "commander.missingMandatoryOptionValue" || e.code === "commander.optionMissingArgument") {
5698
+ if (options.json) {
5699
+ emitJsonError("MISSING_OPTION", e.message ?? "Missing required option", index_1.EXIT_INVALID_ARGS);
5700
+ process.exit(index_1.EXIT_INVALID_ARGS);
5701
+ }
5702
+ process.stderr.write(`${e.message ?? "Missing required option"}
5526
5703
  `);
5527
- process.exit(1);
5704
+ process.exit(index_1.EXIT_INVALID_ARGS);
5705
+ }
5706
+ throw err;
5707
+ }
5708
+ const opts = sub.opts();
5709
+ toolArgs = {};
5710
+ try {
5711
+ for (const param of params) {
5712
+ const cliKey = param.cliFlag.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
5713
+ const rawVal = opts[cliKey];
5714
+ if (rawVal === void 0)
5715
+ continue;
5716
+ const itemType = param.itemsType ?? "string";
5717
+ const coerced = param.type === "array" && Array.isArray(rawVal) ? rawVal.map((v) => coerceValue(v, itemType)) : typeof rawVal === "string" ? coerceValue(rawVal, param.type) : rawVal;
5718
+ toolArgs[param.name] = coerced;
5719
+ }
5720
+ } catch (err) {
5721
+ if (options.json) {
5722
+ emitJsonError("INVALID_ARGS", err.message, index_1.EXIT_INVALID_ARGS);
5723
+ process.exit(index_1.EXIT_INVALID_ARGS);
5724
+ }
5725
+ console.error(chalk_1.default.red(`Error: ${err.message}`));
5726
+ process.exit(index_1.EXIT_INVALID_ARGS);
5528
5727
  }
5529
- throw err;
5530
5728
  }
5531
- const opts = sub.opts();
5532
- const toolArgs = {};
5533
5729
  try {
5534
- for (const param of params) {
5535
- const cliKey = param.cliFlag.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
5536
- const rawVal = opts[cliKey];
5537
- if (rawVal === void 0)
5538
- continue;
5539
- const itemType = param.itemsType ?? "string";
5540
- const coerced = param.type === "array" && Array.isArray(rawVal) ? rawVal.map((v) => coerceValue(v, itemType)) : typeof rawVal === "string" ? coerceValue(rawVal, param.type) : rawVal;
5541
- toolArgs[param.name] = coerced;
5542
- }
5730
+ const result = await client.callTool({ name: tool.name, arguments: toolArgs });
5731
+ formatResult(result, options);
5543
5732
  } catch (err) {
5544
- console.error(chalk_1.default.red(`Error: ${err.message}`));
5545
- process.exit(1);
5733
+ if (options.json) {
5734
+ emitJsonError("TOOL_EXECUTION_ERROR", err.message, index_1.EXIT_TOOL_EXECUTION);
5735
+ process.exit(index_1.EXIT_TOOL_EXECUTION);
5736
+ }
5737
+ throw err;
5546
5738
  }
5547
- const result = await client.callTool({ name: tool.name, arguments: toolArgs });
5548
- formatResult(result, options);
5549
5739
  }
5550
5740
  }
5551
5741
  });
5552
5742
  export default require_runner();
5553
- //# sourceMappingURL=runner-HH357SRR.js.map
5743
+ //# sourceMappingURL=runner-ROLDMGH3.js.map