@mcpc-tech/cli 0.1.51 → 0.1.53

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/app.mjs CHANGED
@@ -509,7 +509,7 @@ var require_cross_spawn = __commonJS({
509
509
  var cp = __require("child_process");
510
510
  var parse2 = require_parse();
511
511
  var enoent = require_enoent();
512
- function spawn2(command, args, options) {
512
+ function spawn3(command, args, options) {
513
513
  const parsed = parse2(command, args, options);
514
514
  const spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
515
515
  enoent.hookChildProcess(spawned, parsed);
@@ -521,8 +521,8 @@ var require_cross_spawn = __commonJS({
521
521
  result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
522
522
  return result;
523
523
  }
524
- module.exports = spawn2;
525
- module.exports.spawn = spawn2;
524
+ module.exports = spawn3;
525
+ module.exports.spawn = spawn3;
526
526
  module.exports.sync = spawnSync;
527
527
  module.exports._parse = parse2;
528
528
  module.exports._enoent = enoent;
@@ -9803,6 +9803,7 @@ var ComposableMCPServer = class extends Server {
9803
9803
  toolManager;
9804
9804
  logger = createLogger("mcpc.compose");
9805
9805
  fileLoaders = /* @__PURE__ */ new Map();
9806
+ pluginsDisposed = false;
9806
9807
  // Legacy property for backward compatibility
9807
9808
  get toolNameMapping() {
9808
9809
  return this.toolManager.getToolNameMapping();
@@ -10278,11 +10279,21 @@ var ComposableMCPServer = class extends Server {
10278
10279
  async disposePlugins() {
10279
10280
  await this.pluginManager.dispose();
10280
10281
  }
10282
+ /**
10283
+ * Dispose plugins only once to avoid duplicated cleanup in chained handlers.
10284
+ */
10285
+ async disposePluginsOnce() {
10286
+ if (this.pluginsDisposed) {
10287
+ return;
10288
+ }
10289
+ this.pluginsDisposed = true;
10290
+ await this.disposePlugins();
10291
+ }
10281
10292
  /**
10282
10293
  * Close the server and ensure all plugins are disposed
10283
10294
  */
10284
10295
  async close() {
10285
- await this.disposePlugins();
10296
+ await this.disposePluginsOnce();
10286
10297
  await super.close();
10287
10298
  }
10288
10299
  async compose(name, description, depsConfig = {
@@ -10387,16 +10398,20 @@ var ComposableMCPServer = class extends Server {
10387
10398
  server: this,
10388
10399
  toolNames: Object.keys(allTools)
10389
10400
  });
10401
+ const previousOnClose = this.onclose;
10390
10402
  this.onclose = async () => {
10391
10403
  await cleanupClients();
10392
- await this.disposePlugins();
10404
+ await this.disposePluginsOnce();
10393
10405
  await this.logger.info(`[${name}] Event: closed - cleaned up dependent clients and plugins`);
10406
+ previousOnClose?.();
10394
10407
  };
10408
+ const previousOnError = this.onerror;
10395
10409
  this.onerror = async (error) => {
10396
10410
  await this.logger.error(`[${name}] Event: error - ${error?.stack ?? String(error)}`);
10397
10411
  await cleanupClients();
10398
- await this.disposePlugins();
10412
+ await this.disposePluginsOnce();
10399
10413
  await this.logger.info(`[${name}] Action: cleaned up dependent clients and plugins`);
10414
+ previousOnError?.(error);
10400
10415
  };
10401
10416
  const toolNameToDetailList = Object.entries(allTools);
10402
10417
  const publicToolNames = this.getPublicToolNames();
@@ -11048,6 +11063,152 @@ Skill path: ${meta.basePath}
11048
11063
  };
11049
11064
  }
11050
11065
 
11066
+ // __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/plugins/bash.js
11067
+ import { spawn as spawn2 } from "node:child_process";
11068
+ import process7 from "node:process";
11069
+ var DEFAULT_MAX_BYTES = 1e5;
11070
+ var DEFAULT_MAX_LINES = 2e3;
11071
+ var DEFAULT_TIMEOUT_MS = 6e4;
11072
+ function truncateOutput(stdout, stderr, maxBytes = DEFAULT_MAX_BYTES, maxLines = DEFAULT_MAX_LINES) {
11073
+ const fullOutput = (stderr ? `STDERR:
11074
+ ${stderr}
11075
+
11076
+ STDOUT:
11077
+ ` : "") + stdout;
11078
+ const lines = fullOutput.split("\n");
11079
+ if (lines.length > maxLines) {
11080
+ const truncatedLines = lines.slice(-maxLines);
11081
+ return {
11082
+ output: `[OUTPUT TRUNCATED] Showing last ${maxLines} lines of ${lines.length} total
11083
+
11084
+ ` + truncatedLines.join("\n"),
11085
+ truncated: true
11086
+ };
11087
+ }
11088
+ if (fullOutput.length > maxBytes) {
11089
+ const truncatedBytes = fullOutput.slice(-maxBytes);
11090
+ return {
11091
+ output: `[OUTPUT TRUNCATED] Showing last ${maxBytes} bytes of ${fullOutput.length} total
11092
+
11093
+ ` + truncatedBytes,
11094
+ truncated: true
11095
+ };
11096
+ }
11097
+ return {
11098
+ output: fullOutput,
11099
+ truncated: false
11100
+ };
11101
+ }
11102
+ function executeBash(command, cwd2, timeoutMs) {
11103
+ return new Promise((resolve5) => {
11104
+ const stdout = [];
11105
+ const stderr = [];
11106
+ const proc = spawn2("bash", [
11107
+ "-c",
11108
+ command
11109
+ ], {
11110
+ cwd: cwd2,
11111
+ stdio: [
11112
+ "ignore",
11113
+ "pipe",
11114
+ "pipe"
11115
+ ]
11116
+ });
11117
+ proc.stdout?.on("data", (data) => {
11118
+ stdout.push(data.toString());
11119
+ });
11120
+ proc.stderr?.on("data", (data) => {
11121
+ stderr.push(data.toString());
11122
+ });
11123
+ proc.on("close", (code) => {
11124
+ resolve5({
11125
+ stdout: stdout.join(""),
11126
+ stderr: stderr.join(""),
11127
+ exitCode: code
11128
+ });
11129
+ });
11130
+ proc.on("error", (err) => {
11131
+ resolve5({
11132
+ stdout: "",
11133
+ stderr: err.message,
11134
+ exitCode: null
11135
+ });
11136
+ });
11137
+ setTimeout(() => {
11138
+ proc.kill("SIGTERM");
11139
+ resolve5({
11140
+ stdout: stdout.join(""),
11141
+ stderr: stderr.join("") + "\n\n[TIMEOUT] Command execution timed out",
11142
+ exitCode: null
11143
+ });
11144
+ }, timeoutMs);
11145
+ });
11146
+ }
11147
+ function createBashPlugin(options = {}) {
11148
+ const { maxBytes, maxLines, timeoutMs } = {
11149
+ maxBytes: DEFAULT_MAX_BYTES,
11150
+ maxLines: DEFAULT_MAX_LINES,
11151
+ timeoutMs: DEFAULT_TIMEOUT_MS,
11152
+ ...options
11153
+ };
11154
+ let serverRef = null;
11155
+ return {
11156
+ name: "plugin-bash",
11157
+ version: "1.0.0",
11158
+ // Store server reference for tool registration
11159
+ configureServer: (server) => {
11160
+ serverRef = server;
11161
+ },
11162
+ // Register bash tool with agent name prefix
11163
+ composeStart: (context2) => {
11164
+ if (!serverRef) return;
11165
+ const agentName = context2.serverName;
11166
+ const toolName = `${agentName}__bash`;
11167
+ serverRef.tool(toolName, "Execute a bash command and return its output.\n\nUse this for:\n- Running shell commands\n- Executing scripts\n- System operations\n\nNote: Output is truncated if too large.", {
11168
+ type: "object",
11169
+ properties: {
11170
+ command: {
11171
+ type: "string",
11172
+ description: "The bash command to execute"
11173
+ },
11174
+ cwd: {
11175
+ type: "string",
11176
+ description: "Optional: Working directory for the command (defaults to current directory)"
11177
+ }
11178
+ },
11179
+ required: [
11180
+ "command"
11181
+ ]
11182
+ }, async (args) => {
11183
+ const cwd2 = args.cwd || process7.cwd();
11184
+ const result = await executeBash(args.command, cwd2, timeoutMs);
11185
+ const { output, truncated } = truncateOutput(result.stdout, result.stderr, maxBytes, maxLines);
11186
+ let finalOutput = output;
11187
+ if (result.exitCode !== null && result.exitCode !== 0) {
11188
+ finalOutput = `[EXIT CODE: ${result.exitCode}]
11189
+ ` + finalOutput;
11190
+ }
11191
+ if (truncated) {
11192
+ finalOutput += `
11193
+
11194
+ [Note: Output was truncated]`;
11195
+ }
11196
+ return {
11197
+ content: [
11198
+ {
11199
+ type: "text",
11200
+ text: finalOutput
11201
+ }
11202
+ ],
11203
+ isError: result.exitCode !== null && result.exitCode !== 0
11204
+ };
11205
+ }, {
11206
+ internal: true
11207
+ });
11208
+ }
11209
+ };
11210
+ }
11211
+
11051
11212
  // __mcpc__cli_latest/node_modules/@mcpc/cli/src/defaults.js
11052
11213
  import { createCodeExecutionPlugin } from "@mcpc-tech/plugin-code-execution";
11053
11214
 
@@ -13027,10 +13188,10 @@ function parse(content, options = {}) {
13027
13188
  }
13028
13189
 
13029
13190
  // __mcpc__cli_latest/node_modules/@jsr/mcpc__plugin-markdown-loader/src/markdown-loader.js
13030
- import process7 from "node:process";
13191
+ import process8 from "node:process";
13031
13192
  function replaceEnvVars(str2) {
13032
13193
  return str2.replace(/\$([A-Za-z_][A-Za-z0-9_]*)(?!\s*\()/g, (match, varName) => {
13033
- const value = process7.env[varName];
13194
+ const value = process8.env[varName];
13034
13195
  if (value !== void 0) {
13035
13196
  return value;
13036
13197
  }
@@ -13129,17 +13290,18 @@ var defaultPlugin = markdownLoaderPlugin();
13129
13290
 
13130
13291
  // __mcpc__cli_latest/node_modules/@mcpc/cli/src/defaults.js
13131
13292
  import { resolve as resolve3 } from "node:path";
13132
- import process8 from "node:process";
13293
+ import process9 from "node:process";
13133
13294
  var DEFAULT_SKILLS_PATHS = [
13134
13295
  ".agent/skills"
13135
13296
  ];
13136
13297
  function getGlobalPlugins(skillsPaths) {
13137
- const resolvedPaths = skillsPaths.map((p2) => resolve3(process8.cwd(), p2));
13298
+ const resolvedPaths = skillsPaths.map((p2) => resolve3(process9.cwd(), p2));
13138
13299
  return [
13139
13300
  markdownLoaderPlugin(),
13140
13301
  createSkillsPlugin({
13141
13302
  paths: resolvedPaths
13142
- })
13303
+ }),
13304
+ createBashPlugin()
13143
13305
  ];
13144
13306
  }
13145
13307
  function getDefaultAgents() {
@@ -13445,15 +13607,17 @@ var Response2 = class _Response {
13445
13607
  this.#init = init;
13446
13608
  }
13447
13609
  if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
13448
- headers ||= init?.headers || { "content-type": "text/plain; charset=UTF-8" };
13449
- this[cacheKey] = [init?.status || 200, body, headers];
13610
+ ;
13611
+ this[cacheKey] = [init?.status || 200, body, headers || init?.headers];
13450
13612
  }
13451
13613
  }
13452
13614
  get headers() {
13453
13615
  const cache = this[cacheKey];
13454
13616
  if (cache) {
13455
13617
  if (!(cache[2] instanceof Headers)) {
13456
- cache[2] = new Headers(cache[2]);
13618
+ cache[2] = new Headers(
13619
+ cache[2] || { "content-type": "text/plain; charset=UTF-8" }
13620
+ );
13457
13621
  }
13458
13622
  return cache[2];
13459
13623
  }
@@ -13578,15 +13742,32 @@ var flushHeaders = (outgoing) => {
13578
13742
  };
13579
13743
  var responseViaCache = async (res, outgoing) => {
13580
13744
  let [status, body, header] = res[cacheKey];
13581
- if (header instanceof Headers) {
13745
+ let hasContentLength = false;
13746
+ if (!header) {
13747
+ header = { "content-type": "text/plain; charset=UTF-8" };
13748
+ } else if (header instanceof Headers) {
13749
+ hasContentLength = header.has("content-length");
13582
13750
  header = buildOutgoingHttpHeaders(header);
13751
+ } else if (Array.isArray(header)) {
13752
+ const headerObj = new Headers(header);
13753
+ hasContentLength = headerObj.has("content-length");
13754
+ header = buildOutgoingHttpHeaders(headerObj);
13755
+ } else {
13756
+ for (const key in header) {
13757
+ if (key.length === 14 && key.toLowerCase() === "content-length") {
13758
+ hasContentLength = true;
13759
+ break;
13760
+ }
13761
+ }
13583
13762
  }
13584
- if (typeof body === "string") {
13585
- header["Content-Length"] = Buffer.byteLength(body);
13586
- } else if (body instanceof Uint8Array) {
13587
- header["Content-Length"] = body.byteLength;
13588
- } else if (body instanceof Blob) {
13589
- header["Content-Length"] = body.size;
13763
+ if (!hasContentLength) {
13764
+ if (typeof body === "string") {
13765
+ header["Content-Length"] = Buffer.byteLength(body);
13766
+ } else if (body instanceof Uint8Array) {
13767
+ header["Content-Length"] = body.byteLength;
13768
+ } else if (body instanceof Blob) {
13769
+ header["Content-Length"] = body.size;
13770
+ }
13590
13771
  }
13591
13772
  outgoing.writeHead(status, header);
13592
13773
  if (typeof body === "string" || body instanceof Uint8Array) {
@@ -14739,8 +14920,8 @@ function parseArgs(args, options) {
14739
14920
  import { mkdir, readFile as readFile3, writeFile as writeFile2 } from "node:fs/promises";
14740
14921
  import { homedir } from "node:os";
14741
14922
  import { dirname, join as join3, resolve as resolve4 } from "node:path";
14742
- import process9 from "node:process";
14743
- var CLI_VERSION = "0.1.51";
14923
+ import process10 from "node:process";
14924
+ var CLI_VERSION = "0.1.53";
14744
14925
  function extractServerName(command, commandArgs) {
14745
14926
  for (const arg of commandArgs) {
14746
14927
  if (!arg.startsWith("-")) {
@@ -14800,7 +14981,7 @@ async function saveUserConfig(config, newAgentName) {
14800
14981
  async function createWrapConfig(args) {
14801
14982
  if (!args.mcpServers || args.mcpServers.length === 0) {
14802
14983
  console.error("Error: --wrap/--add requires at least one MCP server\nExample: mcpc --wrap --mcp-stdio 'npx -y @wonderwhy-er/desktop-commander'\nMultiple: mcpc --add --mcp-stdio 'npx -y server1' --mcp-http 'https://api.example.com'");
14803
- process9.exit(1);
14984
+ process10.exit(1);
14804
14985
  }
14805
14986
  const mcpServers = {};
14806
14987
  const serverNames = [];
@@ -14923,7 +15104,7 @@ function parseMcpServer(cmdString, transportType) {
14923
15104
  };
14924
15105
  }
14925
15106
  function parseCLIArgs() {
14926
- const args = parseArgs(process9.argv.slice(2), {
15107
+ const args = parseArgs(process10.argv.slice(2), {
14927
15108
  boolean: [
14928
15109
  "help",
14929
15110
  "version",
@@ -15012,15 +15193,15 @@ async function loadConfig() {
15012
15193
  const args = parseCLIArgs();
15013
15194
  if (args.version) {
15014
15195
  printVersion();
15015
- process9.exit(0);
15196
+ process10.exit(0);
15016
15197
  }
15017
15198
  if (args.help) {
15018
15199
  printHelp();
15019
- process9.exit(0);
15200
+ process10.exit(0);
15020
15201
  }
15021
15202
  if (args.cwd) {
15022
- const targetCwd = resolve4(process9.cwd(), args.cwd);
15023
- process9.chdir(targetCwd);
15203
+ const targetCwd = resolve4(process10.cwd(), args.cwd);
15204
+ process10.chdir(targetCwd);
15024
15205
  console.error(`Changed working directory to: ${targetCwd}`);
15025
15206
  }
15026
15207
  const mergeSkills = (config) => {
@@ -15032,7 +15213,7 @@ async function loadConfig() {
15032
15213
  ...args,
15033
15214
  saveConfig: true
15034
15215
  });
15035
- process9.exit(0);
15216
+ process10.exit(0);
15036
15217
  }
15037
15218
  if (args.wrap) {
15038
15219
  return mergeSkills(await createWrapConfig({
@@ -15049,16 +15230,16 @@ async function loadConfig() {
15049
15230
  throw error;
15050
15231
  }
15051
15232
  }
15052
- if (process9.env.MCPC_CONFIG) {
15233
+ if (process10.env.MCPC_CONFIG) {
15053
15234
  try {
15054
- const parsed = JSON.parse(process9.env.MCPC_CONFIG);
15235
+ const parsed = JSON.parse(process10.env.MCPC_CONFIG);
15055
15236
  return mergeSkills(applyModeOverride(normalizeConfig(parsed), args.mode));
15056
15237
  } catch (error) {
15057
15238
  console.error("Failed to parse MCPC_CONFIG environment variable:", error);
15058
15239
  throw error;
15059
15240
  }
15060
15241
  }
15061
- const configUrl = args.configUrl || process9.env.MCPC_CONFIG_URL;
15242
+ const configUrl = args.configUrl || process10.env.MCPC_CONFIG_URL;
15062
15243
  if (configUrl) {
15063
15244
  try {
15064
15245
  const headers = {
@@ -15079,7 +15260,7 @@ async function loadConfig() {
15079
15260
  throw error;
15080
15261
  }
15081
15262
  }
15082
- const configFile = args.configFile || process9.env.MCPC_CONFIG_FILE;
15263
+ const configFile = args.configFile || process10.env.MCPC_CONFIG_FILE;
15083
15264
  if (configFile) {
15084
15265
  try {
15085
15266
  const config = await loadConfigFromFile(configFile);
@@ -15104,7 +15285,7 @@ async function loadConfig() {
15104
15285
  throw error;
15105
15286
  }
15106
15287
  }
15107
- const defaultJsonConfigPath = resolve4(process9.cwd(), "mcpc.config.json");
15288
+ const defaultJsonConfigPath = resolve4(process10.cwd(), "mcpc.config.json");
15108
15289
  try {
15109
15290
  const config = await loadConfigFromFile(defaultJsonConfigPath);
15110
15291
  return mergeSkills(applyModeOverride(config, args.mode));
@@ -15119,7 +15300,7 @@ async function loadConfig() {
15119
15300
  }
15120
15301
  function replaceEnvVars2(str2) {
15121
15302
  return str2.replace(/\$([A-Z_][A-Z0-9_]*)/g, (_match, varName) => {
15122
- return process9.env[varName] || "";
15303
+ return process10.env[varName] || "";
15123
15304
  });
15124
15305
  }
15125
15306
  function isMarkdownFile2(path) {
@@ -15163,7 +15344,7 @@ function applyModeOverride(config, mode) {
15163
15344
  agent.options.mode = mode;
15164
15345
  if (mode === "ai_acp" && !agent.options.acpSettings) {
15165
15346
  agent.options.acpSettings = {
15166
- command: "claude-code-acp",
15347
+ command: "claude-agent-acp",
15167
15348
  args: [],
15168
15349
  session: {}
15169
15350
  };