ls-mcp 1.2.0 → 1.3.1

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/cli.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  "use strict";
2
3
  var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
@@ -66,6 +67,8 @@ var MCPConfigLinterService = class {
66
67
  };
67
68
 
68
69
  // src/services/mcp-server-manager-service.ts
70
+ var import_node_child_process = require("child_process");
71
+ var import_node_os = require("os");
69
72
  var MCPServerManagerService = class {
70
73
  static {
71
74
  __name(this, "MCPServerManagerService");
@@ -99,7 +102,311 @@ var MCPServerManagerService = class {
99
102
  return this.env;
100
103
  }
101
104
  isRunning() {
102
- return this.running;
105
+ try {
106
+ let psOutput;
107
+ if ((0, import_node_os.platform)() === "win32") {
108
+ psOutput = (0, import_node_child_process.execSync)('powershell -Command "Get-CimInstance -ClassName Win32_Process | Select-Object ProcessId,Name,CommandLine,ParentProcessId | ConvertTo-Csv -NoTypeInformation"', {
109
+ encoding: "utf8",
110
+ timeout: 5e3
111
+ });
112
+ } else {
113
+ psOutput = (0, import_node_child_process.execSync)("ps -eao pid,ppid,args", {
114
+ encoding: "utf8",
115
+ timeout: 5e3
116
+ });
117
+ }
118
+ const processMap = /* @__PURE__ */ new Map();
119
+ const processes = psOutput.trim().split("\n");
120
+ for (const processLine of processes) {
121
+ if (!processLine.trim()) continue;
122
+ let pid;
123
+ let ppid;
124
+ let commandLine;
125
+ if ((0, import_node_os.platform)() === "win32") {
126
+ if (processLine.startsWith('"ProcessId"') || processLine.startsWith("ProcessId")) continue;
127
+ const parts = this.parseCSVLine(processLine);
128
+ if (parts.length < 4) continue;
129
+ pid = parts[0] || "";
130
+ commandLine = parts[2] || "";
131
+ ppid = parts[3] || "";
132
+ } else {
133
+ const match = processLine.trim().match(/^\s*(\d+)\s+(\d+)\s+(.+)$/);
134
+ if (!match) continue;
135
+ pid = match[1];
136
+ ppid = match[2];
137
+ commandLine = match[3];
138
+ }
139
+ const commandTokens = this.parseCommandLine(commandLine);
140
+ if (commandTokens.length > 0) {
141
+ processMap.set(pid, { ppid, commandTokens });
142
+ }
143
+ }
144
+ let mcpServerDetection;
145
+ for (const [pid, processData] of processMap) {
146
+ if (this.isCommandMatch(processData.commandTokens, pid, processData.ppid)) {
147
+ mcpServerDetection = {
148
+ pid,
149
+ commandLine: processData.commandTokens.join(" "),
150
+ ppid: processData.ppid
151
+ };
152
+ const parentProcess = processMap.get(processData.ppid);
153
+ if (parentProcess) {
154
+ const { estimatedVendor, estimatedProduct } = this.getVendorFromCommand(parentProcess.commandTokens) || {};
155
+ if (estimatedProduct || estimatedVendor) {
156
+ mcpServerDetection = {
157
+ ...mcpServerDetection,
158
+ parentCommandLine: parentProcess.commandTokens.join(" "),
159
+ estimatedVendor,
160
+ estimatedProduct
161
+ };
162
+ return mcpServerDetection;
163
+ }
164
+ }
165
+ }
166
+ }
167
+ if (mcpServerDetection) {
168
+ return mcpServerDetection;
169
+ }
170
+ return false;
171
+ } catch (error) {
172
+ return false;
173
+ }
174
+ }
175
+ getVendorFromCommand(commandTokens) {
176
+ const commandString = commandTokens.join(" ").toLowerCase();
177
+ if (commandString.includes("claude.app")) {
178
+ return {
179
+ estimatedVendor: "anthropic",
180
+ estimatedProduct: "claude-desktop"
181
+ };
182
+ }
183
+ if (commandString.includes("claude")) {
184
+ return {
185
+ estimatedVendor: "anthropic",
186
+ estimatedProduct: "claude-desktop"
187
+ };
188
+ }
189
+ }
190
+ isCommandMatch(commandTokens, pid, ppid) {
191
+ if (commandTokens.length === 0) return false;
192
+ const baseCommand = this.getBaseCommand(commandTokens[0]);
193
+ if (this.command === "uvx" && baseCommand === "uv") {
194
+ return this.matchUvxProcess(commandTokens);
195
+ }
196
+ if (this.command === "npx" && baseCommand === "npm") {
197
+ return this.matchNpxProcess(commandTokens);
198
+ }
199
+ if (this.command === "uv" && baseCommand === "uv") {
200
+ return this.matchGenericArgsToArgs(commandTokens);
201
+ }
202
+ const commandConfigPythonBase = this.getBaseCommand(this.command);
203
+ const commandAliasesPython = ["python3", "python", "python3.10", "python3.11", "python3.12", "cpython3", "cpython", "python3", "python2"];
204
+ if (commandAliasesPython.includes(commandConfigPythonBase) && commandAliasesPython.includes(baseCommand)) {
205
+ return this.matchGenericArgsToArgs(commandTokens);
206
+ }
207
+ const commandGenericBase = this.getBaseCommand(this.command);
208
+ const commandGenericProcessBase = this.getBaseCommand(commandTokens[0]);
209
+ if (commandGenericBase === commandGenericProcessBase) {
210
+ return this.matchGenericArgsToArgs(commandTokens);
211
+ }
212
+ return false;
213
+ }
214
+ matchGenericArgsToArgs(commandTokens) {
215
+ if (this.args.length === 0) {
216
+ return commandTokens[0] === this.command;
217
+ }
218
+ if (commandTokens.length < 2) {
219
+ return false;
220
+ }
221
+ const commandWithoutArgs = commandTokens.slice(1);
222
+ for (let i = 0; i < this.args.length; i++) {
223
+ if (i >= commandWithoutArgs.length) return false;
224
+ const arg = this.args[i];
225
+ const token = commandWithoutArgs[i];
226
+ if (arg !== token && !token.includes(arg)) {
227
+ return false;
228
+ }
229
+ }
230
+ return true;
231
+ }
232
+ // @TODO refactor this to use path.basename or similar
233
+ // to extract the base command from the full command path
234
+ getBaseCommand(fullCommandPath) {
235
+ const parts = fullCommandPath.split(/[/\\]/);
236
+ return parts[parts.length - 1];
237
+ }
238
+ /*
239
+ example1:
240
+ ```
241
+ "command": "uvx",
242
+ "args": ["--from", "mcp-alchemy==2025.5.2.210242", "--with", "oracledb",
243
+ "--refresh-package", "mcp-alchemy", "mcp-alchemy"],
244
+ ```
245
+
246
+ example 2:
247
+ ```
248
+ "command": "uvx",
249
+ "args": [
250
+ "mcp-neo4j-memory@0.1.4",
251
+ "--db-url",
252
+ "neo4j+s://xxxx.databases.neo4j.io",
253
+ "--username",
254
+ "<your-username>",
255
+ "--password",
256
+ "<your-password>"
257
+ ]
258
+ ```
259
+
260
+ example 3:
261
+ ```
262
+ "vefaas": {
263
+ "command": "uvx",
264
+ "args": [
265
+ "--from",
266
+ "git+https://github.com/volcengine/mcp-server#subdirectory=server/mcp_server_vefaas_function",
267
+ "mcp-server-vefaas-function"
268
+ ],
269
+ "env": {
270
+ "VOLC_ACCESSKEY": "xxx",
271
+ "VOLC_SECRETKEY": "xxx"
272
+ }
273
+ }
274
+ }
275
+ ```
276
+
277
+ example 4:
278
+ ```
279
+ "time": {
280
+ "command": "uvx",
281
+ "args": ["mcp-server-time", "--local-timezone=America/New_York"]
282
+ }
283
+ ```
284
+ */
285
+ getUvxMcpServerNameFromArgs() {
286
+ if (this.args.length === 0) return void 0;
287
+ let mcpServerName;
288
+ if (this.args.length === 1) {
289
+ mcpServerName = this.args[0];
290
+ return mcpServerName;
291
+ }
292
+ for (let i = 0; i < this.args.length; i++) {
293
+ if (this.args[i] === "--from" && i + 1 < this.args.length) {
294
+ mcpServerName = this.args[i + 1];
295
+ return mcpServerName;
296
+ }
297
+ }
298
+ const firstArg = this.args[0];
299
+ if (firstArg.startsWith("-") || firstArg.startsWith("--")) {
300
+ const lastArg = this.args[this.args.length - 1];
301
+ mcpServerName = lastArg;
302
+ return mcpServerName;
303
+ }
304
+ mcpServerName = firstArg;
305
+ return mcpServerName;
306
+ }
307
+ matchUvxProcess(commandTokens) {
308
+ if (commandTokens.length === 0) return false;
309
+ const mcpServerName = this.getUvxMcpServerNameFromArgs();
310
+ if (!mcpServerName) return false;
311
+ return this.findMcpServerNameInProcessArguments(commandTokens, mcpServerName);
312
+ }
313
+ findMcpServerNameInProcessArguments(commandTokens, mcpServerName) {
314
+ for (let i = 0; i < commandTokens.length; i++) {
315
+ const token = commandTokens[i];
316
+ if (mcpServerName === token || token.includes(mcpServerName)) {
317
+ return true;
318
+ }
319
+ }
320
+ return false;
321
+ }
322
+ parseCSVLine(line) {
323
+ const result = [];
324
+ let current = "";
325
+ let inQuotes = false;
326
+ for (let i = 0; i < line.length; i++) {
327
+ const char = line[i];
328
+ if (char === '"') {
329
+ if (inQuotes && line[i + 1] === '"') {
330
+ current += '"';
331
+ i++;
332
+ } else {
333
+ inQuotes = !inQuotes;
334
+ }
335
+ } else if (char === "," && !inQuotes) {
336
+ result.push(current);
337
+ current = "";
338
+ } else {
339
+ current += char;
340
+ }
341
+ }
342
+ result.push(current);
343
+ return result;
344
+ }
345
+ parseCommandLine(commandLine) {
346
+ const tokens = [];
347
+ let current = "";
348
+ let inQuotes = false;
349
+ let quoteChar = "";
350
+ for (let i = 0; i < commandLine.length; i++) {
351
+ const char = commandLine[i];
352
+ if (!inQuotes && (char === '"' || char === "'")) {
353
+ inQuotes = true;
354
+ quoteChar = char;
355
+ } else if (inQuotes && char === quoteChar) {
356
+ inQuotes = false;
357
+ quoteChar = "";
358
+ } else if (!inQuotes && char === " ") {
359
+ if (current.trim()) {
360
+ tokens.push(current.trim());
361
+ current = "";
362
+ }
363
+ } else {
364
+ current += char;
365
+ }
366
+ }
367
+ if (current.trim()) {
368
+ tokens.push(current.trim());
369
+ }
370
+ return tokens;
371
+ }
372
+ /*
373
+ example to match:
374
+ ```
375
+ "command": "npx",
376
+ "args": [
377
+ "-y",
378
+ "@modelcontextprotocol/server-postgres",
379
+ "postgresql://localhost/mydb"
380
+ ]
381
+ }
382
+ ```
383
+
384
+ with a process command like:
385
+ ```
386
+ npm exec @modelcontextprotocol/server-postgres postgresql://localhost/mydb
387
+ ```
388
+ */
389
+ matchNpxProcess(commandTokens) {
390
+ if (commandTokens.length < 3) return false;
391
+ if (commandTokens[1] !== "exec") return false;
392
+ let argsToMatch = [];
393
+ const yIndex = this.args.indexOf("-y");
394
+ if (yIndex !== -1 && yIndex + 1 < this.args.length) {
395
+ argsToMatch = this.args.slice(yIndex + 1);
396
+ } else {
397
+ argsToMatch = this.args;
398
+ }
399
+ if (commandTokens.length - 2 !== argsToMatch.length) {
400
+ return false;
401
+ }
402
+ for (let i = 0; i < argsToMatch.length; i++) {
403
+ const commandToken = commandTokens[i + 2];
404
+ const expectedArg = argsToMatch[i];
405
+ if (commandToken !== expectedArg) {
406
+ return false;
407
+ }
408
+ }
409
+ return true;
103
410
  }
104
411
  };
105
412
 
@@ -110,7 +417,7 @@ var MCPFiles = class {
110
417
  }
111
418
  mcpFilePathGroups = {
112
419
  claude: {
113
- name: "claude",
420
+ name: "claude-desktop",
114
421
  friendlyName: "Claude Desktop",
115
422
  paths: [
116
423
  { filePath: "~/Library/Application Support/Claude/claude_desktop_config.json", type: "global" }
@@ -120,8 +427,8 @@ var MCPFiles = class {
120
427
  name: "cursor",
121
428
  friendlyName: "Cursor",
122
429
  paths: [
123
- { filePath: ".cursor/mcp.json", type: "local" },
124
- { filePath: "~/.cursor/mcp.json", type: "global" }
430
+ { filePath: "~/.cursor/mcp.json", type: "global" },
431
+ { filePath: ".cursor/mcp.json", type: "local" }
125
432
  ]
126
433
  }
127
434
  };
@@ -157,13 +464,20 @@ var MCPFiles = class {
157
464
  env: serverConfigRaw.env
158
465
  };
159
466
  const MCPServerManager = new MCPServerManagerService(serverConfig);
467
+ const mcpServerProcessDetection = MCPServerManager.isRunning();
468
+ let mcpServerProcess = false;
469
+ if (mcpServerProcessDetection) {
470
+ if (typeof mcpServerProcessDetection === "object" && mcpServerProcessDetection.estimatedProduct === clientsGroup.name) {
471
+ mcpServerProcess = true;
472
+ }
473
+ }
160
474
  mcpServersData.push({
161
475
  name: MCPServerManager.getName(),
162
476
  command: MCPServerManager.getCmd(),
163
477
  args: MCPServerManager.getArgs(),
164
478
  transport: MCPServerManager.getTransport(),
165
479
  env: MCPServerManager.getEnv(),
166
- status: MCPServerManager.isRunning() ? "running" : "stopped"
480
+ status: mcpServerProcess ? "running" : "stopped"
167
481
  });
168
482
  }
169
483
  filePathData.servers = mcpServersData;
@@ -212,7 +526,7 @@ function render3(text) {
212
526
  if (formattedText === "running") {
213
527
  data = (0, import_node_util3.styleText)(["green"], "\u25CF");
214
528
  } else {
215
- data = (0, import_node_util3.styleText)(["red"], "\u25CB");
529
+ data = (0, import_node_util3.styleText)(["red"], "\u25CF");
216
530
  }
217
531
  return data;
218
532
  }
@@ -242,9 +556,9 @@ function render6(text) {
242
556
  const formattedText = text.toUpperCase().replace(/_/g, " ");
243
557
  let data = formattedText;
244
558
  if (formattedText === "VALID") {
245
- data = (0, import_node_util6.styleText)(["green"], formattedText);
559
+ data = (0, import_node_util6.styleText)(["green"], "\u25CF");
246
560
  } else {
247
- data = (0, import_node_util6.styleText)(["red"], formattedText);
561
+ data = (0, import_node_util6.styleText)(["red"], "\u25CF");
248
562
  }
249
563
  return data;
250
564
  }
@@ -268,18 +582,37 @@ var RenderService = class {
268
582
  if (data.length === 0) return;
269
583
  const headers = ["STATUS", "NAME", "TRANSPORT"];
270
584
  const keys = ["status", "name", "transport"];
271
- const centerColumns = [0, 2, 4, 5];
585
+ const centerColumns = [0, 2];
272
586
  const leftPadding = " ";
273
587
  const columnWidths = headers.map((header, index) => {
274
- const dataWidth = Math.max(...data.map((row) => String(row[keys[index]]).length));
275
- return Math.max(header.length, dataWidth);
588
+ const headerWidth = this.getVisibleLength(render2(header));
589
+ const dataWidth = Math.max(...data.map((row) => {
590
+ let text = String(row[keys[index]]);
591
+ if (keys[index] === "transport") {
592
+ text = render(text);
593
+ }
594
+ if (keys[index] === "status") {
595
+ text = render3(text);
596
+ }
597
+ if (keys[index] === "name") {
598
+ text = render4(text);
599
+ }
600
+ return this.getVisibleLength(text);
601
+ }));
602
+ return Math.max(headerWidth, dataWidth);
276
603
  });
277
604
  const centerText = /* @__PURE__ */ __name((text, width) => {
278
- const padding = width - this.getVisibleLength(text);
605
+ const visibleLength = this.getVisibleLength(text);
606
+ const padding = width - visibleLength;
279
607
  const leftPad = Math.floor(padding / 2);
280
608
  const rightPad = padding - leftPad;
281
609
  return " ".repeat(leftPad) + text + " ".repeat(rightPad);
282
610
  }, "centerText");
611
+ const padRight = /* @__PURE__ */ __name((text, width) => {
612
+ const visibleLength = this.getVisibleLength(text);
613
+ const padding = Math.max(0, width - visibleLength);
614
+ return text + " ".repeat(padding);
615
+ }, "padRight");
283
616
  const totalWidth = columnWidths.reduce((sum, width) => sum + width, 0) + (columnWidths.length - 1) * 2;
284
617
  const separator = "\u2500".repeat(totalWidth);
285
618
  console.log("\n" + leftPadding + separator);
@@ -288,8 +621,7 @@ var RenderService = class {
288
621
  if (centerColumns.includes(index)) {
289
622
  return centerText(headerText, columnWidths[index]);
290
623
  }
291
- const padding = columnWidths[index] - this.getVisibleLength(headerText);
292
- return headerText + " ".repeat(Math.max(0, padding));
624
+ return padRight(headerText, columnWidths[index]);
293
625
  }).join(" ");
294
626
  console.log(leftPadding + headerRow);
295
627
  console.log(leftPadding + separator);
@@ -308,7 +640,7 @@ var RenderService = class {
308
640
  if (centerColumns.includes(index)) {
309
641
  return centerText(text, columnWidths[index]);
310
642
  }
311
- return text.padEnd(columnWidths[index]);
643
+ return padRight(text, columnWidths[index]);
312
644
  }).join(" ");
313
645
  console.log(leftPadding + dataRow);
314
646
  }
@@ -371,10 +703,15 @@ var RenderService = class {
371
703
  const progress = Math.min(count / total, 1);
372
704
  const filledWidth = Math.round(progress * width);
373
705
  const emptyWidth = width - filledWidth;
374
- const colorRunning = count > 0 ? "greenBright" : "red";
375
- const colorEmpty = count > 0 ? "green" : "red";
376
- const filled = (0, import_node_util7.styleText)([colorRunning], "\u2588".repeat(filledWidth));
377
- const empty = (0, import_node_util7.styleText)([colorEmpty], "\u2591".repeat(emptyWidth));
706
+ let filled;
707
+ let empty;
708
+ if (count > 0) {
709
+ filled = (0, import_node_util7.styleText)(["greenBright"], "\u2588".repeat(filledWidth));
710
+ empty = (0, import_node_util7.styleText)(["green"], "\u2591".repeat(emptyWidth));
711
+ } else {
712
+ filled = "\u2588".repeat(filledWidth);
713
+ empty = "\u2591".repeat(emptyWidth);
714
+ }
378
715
  return `${filled}${empty} ${count} / ${total} ${label}`;
379
716
  }
380
717
  };
@@ -388,12 +725,12 @@ async function init() {
388
725
  console.log("No MCP files found.");
389
726
  return;
390
727
  }
391
- let groupIndex = 0;
728
+ let pathIndex = 0;
392
729
  for (const groupName of Object.keys(mcpFilesList)) {
393
- groupIndex++;
394
730
  const group = mcpFilesList[groupName];
395
731
  if (group.paths.length >= 0) {
396
732
  for (const filePathData of group.paths) {
733
+ pathIndex++;
397
734
  const filePath = filePathData.filePath.replace("~", process.env.HOME || "");
398
735
  const filePathValid = filePathData.parsable ? "VALID" : "INVALID";
399
736
  const filePathDataType = filePathData.type.toUpperCase();
@@ -403,14 +740,14 @@ async function init() {
403
740
  const mcpGroupData = [
404
741
  { key: "PROVIDER", value: group.friendlyName },
405
742
  { key: "FILE", value: filePath },
406
- { key: "PARSABLE", value: filePathValid },
407
- { key: "TYPE", value: filePathDataType }
743
+ { key: "TYPE", value: filePathDataType },
744
+ { key: "PARSABLE", value: filePathValid }
408
745
  ];
409
746
  const groupMetadata = {
410
747
  mcpServersTotal: totalMCPServers,
411
748
  mcpServersRunning: totalMCPServersRunning
412
749
  };
413
- RenderService.printMcpGroup(groupIndex, mcpGroupData, groupMetadata);
750
+ RenderService.printMcpGroup(pathIndex, mcpGroupData, groupMetadata);
414
751
  RenderService.printMcpServers(mcpServers);
415
752
  }
416
753
  } else {
@@ -1,2 +1 @@
1
-
2
- export { }
1
+ #!/usr/bin/env node
package/dist/bin/cli.d.ts CHANGED
@@ -1,2 +1 @@
1
-
2
- export { }
1
+ #!/usr/bin/env node