@tronsfey/ucli 0.5.0 → 0.5.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.
@@ -5248,9 +5248,9 @@ var require_lib = __commonJS({
5248
5248
  }
5249
5249
  });
5250
5250
 
5251
- // ../../node_modules/.pnpm/@tronsfey+mcp2cli@1.0.1_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.1_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`);
@@ -5315,7 +5332,10 @@ var require_cache = __commonJS({
5315
5332
  if (age < ttl) {
5316
5333
  return entry.tools;
5317
5334
  }
5318
- } catch {
5335
+ } catch (err) {
5336
+ if (err.code !== "ENOENT") {
5337
+ console.warn(`Warning: could not read tool cache: ${err.message}`);
5338
+ }
5319
5339
  }
5320
5340
  return null;
5321
5341
  }
@@ -5334,9 +5354,24 @@ var require_cache = __commonJS({
5334
5354
  }
5335
5355
  });
5336
5356
 
5337
- // ../../node_modules/.pnpm/@tronsfey+mcp2cli@1.0.1_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
5338
5373
  var require_runner = __commonJS({
5339
- "../../node_modules/.pnpm/@tronsfey+mcp2cli@1.0.1_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) {
5340
5375
  var __importDefault = exports && exports.__importDefault || function(mod) {
5341
5376
  return mod && mod.__esModule ? mod : { "default": mod };
5342
5377
  };
@@ -5345,11 +5380,18 @@ var require_runner = __commonJS({
5345
5380
  exports.schemaToParams = schemaToParams;
5346
5381
  exports.getTools = getTools;
5347
5382
  exports.printToolList = printToolList;
5383
+ exports.describeTool = describeTool;
5384
+ exports.printToolListJson = printToolListJson;
5385
+ exports.describeToolJson = describeToolJson;
5386
+ exports.emitJsonError = emitJsonError;
5387
+ exports.parseInputJson = parseInputJson;
5388
+ exports.coerceValue = coerceValue;
5348
5389
  exports.runTool = runTool;
5349
5390
  var commander_1 = __require("commander");
5350
5391
  var chalk_1 = __importDefault(require_source());
5351
5392
  var jmespath_1 = __importDefault(require_jmespath());
5352
5393
  var cache_1 = require_cache();
5394
+ var index_1 = require_types();
5353
5395
  var DEFAULT_CACHE_TTL = 3600;
5354
5396
  function toKebabCase(name) {
5355
5397
  return name.replace(/_/g, "-").replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
@@ -5371,7 +5413,7 @@ var require_runner = __commonJS({
5371
5413
  const required = new Set(schema.required ?? []);
5372
5414
  return Object.entries(properties).map(([name, prop]) => {
5373
5415
  const type = resolveType(prop);
5374
- return {
5416
+ const param = {
5375
5417
  name,
5376
5418
  cliFlag: toKebabCase(name),
5377
5419
  type,
@@ -5380,14 +5422,26 @@ var require_runner = __commonJS({
5380
5422
  defaultValue: prop.default,
5381
5423
  enumValues: prop.enum
5382
5424
  };
5425
+ if (type === "array" && prop.items) {
5426
+ param.itemsType = resolveType(prop.items);
5427
+ }
5428
+ return param;
5383
5429
  });
5384
5430
  }
5385
5431
  async function getTools(client, config, options) {
5386
5432
  const ttl = options.cacheTtl ?? DEFAULT_CACHE_TTL;
5433
+ const debug = !!options.debug;
5387
5434
  if (!options.noCache) {
5388
5435
  const cached = await (0, cache_1.getCachedTools)(config, ttl);
5389
- 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
+ }
5390
5440
  return cached;
5441
+ }
5442
+ }
5443
+ if (debug) {
5444
+ console.error(chalk_1.default.gray(`[debug] Fetching tool list from server\u2026`));
5391
5445
  }
5392
5446
  const allTools = [];
5393
5447
  let cursor;
@@ -5396,11 +5450,27 @@ var require_runner = __commonJS({
5396
5450
  allTools.push(...result.tools);
5397
5451
  cursor = result.nextCursor;
5398
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
+ }
5399
5456
  if (!options.noCache) {
5400
5457
  await (0, cache_1.setCachedTools)(config, allTools, ttl);
5401
5458
  }
5402
5459
  return allTools;
5403
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
+ }
5404
5474
  function printToolList(tools) {
5405
5475
  if (tools.length === 0) {
5406
5476
  console.log(chalk_1.default.yellow("No tools available."));
@@ -5416,22 +5486,118 @@ Available tools (${tools.length}):
5416
5486
  }
5417
5487
  const params = schemaToParams(tool);
5418
5488
  if (params.length > 0) {
5419
- const paramStr = params.map((p) => p.required ? chalk_1.default.yellow(`--${p.cliFlag}`) : `--${p.cliFlag}`).join(" ");
5420
- console.log(` ${paramStr}`);
5489
+ console.log(` ${chalk_1.default.bold("Parameters:")}`);
5490
+ for (const p of params) {
5491
+ console.log(formatParamLine(p));
5492
+ }
5421
5493
  }
5422
5494
  console.log();
5423
5495
  }
5424
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
+ }
5425
5582
  function formatResult(result, options) {
5426
5583
  let data = result;
5427
5584
  if (options.jq) {
5428
5585
  try {
5429
5586
  data = jmespath_1.default.search(data, options.jq);
5430
5587
  } catch (err) {
5431
- console.error(chalk_1.default.red(`JMESPath error: ${err.message}`));
5432
- process.exit(1);
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
+ }
5592
+ console.error(chalk_1.default.red(`JMESPath error in "${options.jq}": ${err.message}`));
5593
+ process.exit(index_1.EXIT_INVALID_ARGS);
5433
5594
  }
5434
5595
  }
5596
+ if (options.json) {
5597
+ const envelope = { ok: true, result: data };
5598
+ console.log(JSON.stringify(envelope));
5599
+ return;
5600
+ }
5435
5601
  if (options.raw) {
5436
5602
  console.log(JSON.stringify(data, null, 2));
5437
5603
  return;
@@ -5466,8 +5632,10 @@ Available tools (${tools.length}):
5466
5632
  }
5467
5633
  return num;
5468
5634
  }
5469
- if (type === "boolean")
5470
- return value !== "false" && value !== "0";
5635
+ if (type === "boolean") {
5636
+ const falsy = ["false", "0", "no", "off", ""];
5637
+ return !falsy.includes(value.toLowerCase());
5638
+ }
5471
5639
  if (type === "array") {
5472
5640
  try {
5473
5641
  const parsed = JSON.parse(value);
@@ -5480,58 +5648,96 @@ Available tools (${tools.length}):
5480
5648
  return value;
5481
5649
  }
5482
5650
  async function runTool(client, tool, rawArgs, options) {
5483
- const params = schemaToParams(tool);
5484
- const sub = new commander_1.Command(tool.name);
5485
- if (tool.description)
5486
- sub.description(tool.description);
5487
- for (const param of params) {
5488
- let flagStr;
5489
- if (param.type === "boolean") {
5490
- flagStr = `--${param.cliFlag}`;
5491
- } else if (param.type === "array") {
5492
- flagStr = `--${param.cliFlag} <values...>`;
5493
- } else {
5494
- 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);
5495
5662
  }
5496
- const opt = new commander_1.Option(flagStr, param.description);
5497
- if (param.required)
5498
- opt.makeOptionMandatory(true);
5499
- if (param.defaultValue !== void 0)
5500
- opt.default(param.defaultValue);
5501
- if (param.enumValues)
5502
- opt.choices(param.enumValues);
5503
- sub.addOption(opt);
5504
- }
5505
- sub.allowUnknownOption(false);
5506
- sub.exitOverride();
5507
- sub.configureOutput({
5508
- writeErr: (str) => process.stderr.write(str)
5509
- });
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"}
5703
+ `);
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);
5727
+ }
5728
+ }
5510
5729
  try {
5511
- sub.parse(["node", tool.name, ...rawArgs]);
5730
+ const result = await client.callTool({ name: tool.name, arguments: toolArgs });
5731
+ formatResult(result, options);
5512
5732
  } catch (err) {
5513
- const e = err;
5514
- if (e.code === "commander.missingMandatoryOptionValue" || e.code === "commander.optionMissingArgument") {
5515
- process.stderr.write(`${e.message ?? "Missing required option"}
5516
- `);
5517
- 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);
5518
5736
  }
5519
5737
  throw err;
5520
5738
  }
5521
- const opts = sub.opts();
5522
- const toolArgs = {};
5523
- for (const param of params) {
5524
- const cliKey = param.cliFlag.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
5525
- const rawVal = opts[cliKey];
5526
- if (rawVal === void 0)
5527
- continue;
5528
- const coerced = param.type === "array" && Array.isArray(rawVal) ? rawVal.map((v) => coerceValue(v, "string")) : typeof rawVal === "string" ? coerceValue(rawVal, param.type) : rawVal;
5529
- toolArgs[param.name] = coerced;
5530
- }
5531
- const result = await client.callTool({ name: tool.name, arguments: toolArgs });
5532
- formatResult(result, options);
5533
5739
  }
5534
5740
  }
5535
5741
  });
5536
5742
  export default require_runner();
5537
- //# sourceMappingURL=runner-GVYIJNHN.js.map
5743
+ //# sourceMappingURL=runner-ROLDMGH3.js.map