ls-mcp 1.2.0 → 1.3.0

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,287 @@ 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)("wmic process get ProcessId,ParentProcessId,CommandLine /format:csv", {
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
+ const parts = processLine.split(",");
127
+ if (parts.length < 4) continue;
128
+ commandLine = parts[1] || "";
129
+ ppid = parts[2] || "";
130
+ pid = parts[3] || "";
131
+ } else {
132
+ const match = processLine.trim().match(/^\s*(\d+)\s+(\d+)\s+(.+)$/);
133
+ if (!match) continue;
134
+ pid = match[1];
135
+ ppid = match[2];
136
+ commandLine = match[3];
137
+ }
138
+ const commandTokens = this.parseCommandLine(commandLine);
139
+ if (commandTokens.length > 0) {
140
+ processMap.set(pid, { ppid, commandTokens });
141
+ }
142
+ }
143
+ let mcpServerDetection;
144
+ for (const [pid, processData] of processMap) {
145
+ if (this.isCommandMatch(processData.commandTokens, pid, processData.ppid)) {
146
+ mcpServerDetection = {
147
+ pid,
148
+ commandLine: processData.commandTokens.join(" "),
149
+ ppid: processData.ppid
150
+ };
151
+ const parentProcess = processMap.get(processData.ppid);
152
+ if (parentProcess) {
153
+ const { estimatedVendor, estimatedProduct } = this.getVendorFromCommand(parentProcess.commandTokens) || {};
154
+ if (estimatedProduct || estimatedVendor) {
155
+ mcpServerDetection = {
156
+ ...mcpServerDetection,
157
+ parentCommandLine: parentProcess.commandTokens.join(" "),
158
+ estimatedVendor,
159
+ estimatedProduct
160
+ };
161
+ return mcpServerDetection;
162
+ }
163
+ }
164
+ }
165
+ }
166
+ if (mcpServerDetection) {
167
+ return mcpServerDetection;
168
+ }
169
+ return false;
170
+ } catch (error) {
171
+ return false;
172
+ }
173
+ }
174
+ getVendorFromCommand(commandTokens) {
175
+ const commandString = commandTokens.join(" ").toLowerCase();
176
+ if (commandString.includes("claude.app")) {
177
+ return {
178
+ estimatedVendor: "anthropic",
179
+ estimatedProduct: "claude-desktop"
180
+ };
181
+ }
182
+ if (commandString.includes("claude")) {
183
+ return {
184
+ estimatedVendor: "anthropic",
185
+ estimatedProduct: "claude-desktop"
186
+ };
187
+ }
188
+ }
189
+ isCommandMatch(commandTokens, pid, ppid) {
190
+ if (commandTokens.length === 0) return false;
191
+ const baseCommand = this.getBaseCommand(commandTokens[0]);
192
+ if (this.command === "uvx" && baseCommand === "uv") {
193
+ return this.matchUvxProcess(commandTokens);
194
+ }
195
+ if (this.command === "npx" && baseCommand === "npm") {
196
+ return this.matchNpxProcess(commandTokens);
197
+ }
198
+ if (this.command === "uv" && baseCommand === "uv") {
199
+ return this.matchGenericArgsToArgs(commandTokens);
200
+ }
201
+ const commandConfigPythonBase = this.getBaseCommand(this.command);
202
+ const commandAliasesPython = ["python3", "python", "python3.10", "python3.11", "python3.12", "cpython3", "cpython", "python3", "python2"];
203
+ if (commandAliasesPython.includes(commandConfigPythonBase) && commandAliasesPython.includes(baseCommand)) {
204
+ return this.matchGenericArgsToArgs(commandTokens);
205
+ }
206
+ const commandGenericBase = this.getBaseCommand(this.command);
207
+ const commandGenericProcessBase = this.getBaseCommand(commandTokens[0]);
208
+ if (commandGenericBase === commandGenericProcessBase) {
209
+ return this.matchGenericArgsToArgs(commandTokens);
210
+ }
211
+ return false;
212
+ }
213
+ matchGenericArgsToArgs(commandTokens) {
214
+ if (this.args.length === 0) {
215
+ return commandTokens[0] === this.command;
216
+ }
217
+ if (commandTokens.length < 2) {
218
+ return false;
219
+ }
220
+ const commandWithoutArgs = commandTokens.slice(1);
221
+ for (let i = 0; i < this.args.length; i++) {
222
+ if (i >= commandWithoutArgs.length) return false;
223
+ const arg = this.args[i];
224
+ const token = commandWithoutArgs[i];
225
+ if (arg !== token && !token.includes(arg)) {
226
+ return false;
227
+ }
228
+ }
229
+ return true;
230
+ }
231
+ // @TODO refactor this to use path.basename or similar
232
+ // to extract the base command from the full command path
233
+ getBaseCommand(fullCommandPath) {
234
+ const parts = fullCommandPath.split(/[/\\]/);
235
+ return parts[parts.length - 1];
236
+ }
237
+ /*
238
+ example1:
239
+ ```
240
+ "command": "uvx",
241
+ "args": ["--from", "mcp-alchemy==2025.5.2.210242", "--with", "oracledb",
242
+ "--refresh-package", "mcp-alchemy", "mcp-alchemy"],
243
+ ```
244
+
245
+ example 2:
246
+ ```
247
+ "command": "uvx",
248
+ "args": [
249
+ "mcp-neo4j-memory@0.1.4",
250
+ "--db-url",
251
+ "neo4j+s://xxxx.databases.neo4j.io",
252
+ "--username",
253
+ "<your-username>",
254
+ "--password",
255
+ "<your-password>"
256
+ ]
257
+ ```
258
+
259
+ example 3:
260
+ ```
261
+ "vefaas": {
262
+ "command": "uvx",
263
+ "args": [
264
+ "--from",
265
+ "git+https://github.com/volcengine/mcp-server#subdirectory=server/mcp_server_vefaas_function",
266
+ "mcp-server-vefaas-function"
267
+ ],
268
+ "env": {
269
+ "VOLC_ACCESSKEY": "xxx",
270
+ "VOLC_SECRETKEY": "xxx"
271
+ }
272
+ }
273
+ }
274
+ ```
275
+
276
+ example 4:
277
+ ```
278
+ "time": {
279
+ "command": "uvx",
280
+ "args": ["mcp-server-time", "--local-timezone=America/New_York"]
281
+ }
282
+ ```
283
+ */
284
+ getUvxMcpServerNameFromArgs() {
285
+ if (this.args.length === 0) return void 0;
286
+ let mcpServerName;
287
+ if (this.args.length === 1) {
288
+ mcpServerName = this.args[0];
289
+ return mcpServerName;
290
+ }
291
+ for (let i = 0; i < this.args.length; i++) {
292
+ if (this.args[i] === "--from" && i + 1 < this.args.length) {
293
+ mcpServerName = this.args[i + 1];
294
+ return mcpServerName;
295
+ }
296
+ }
297
+ const firstArg = this.args[0];
298
+ if (firstArg.startsWith("-") || firstArg.startsWith("--")) {
299
+ const lastArg = this.args[this.args.length - 1];
300
+ mcpServerName = lastArg;
301
+ return mcpServerName;
302
+ }
303
+ mcpServerName = firstArg;
304
+ return mcpServerName;
305
+ }
306
+ matchUvxProcess(commandTokens) {
307
+ if (commandTokens.length === 0) return false;
308
+ const mcpServerName = this.getUvxMcpServerNameFromArgs();
309
+ if (!mcpServerName) return false;
310
+ return this.findMcpServerNameInProcessArguments(commandTokens, mcpServerName);
311
+ }
312
+ findMcpServerNameInProcessArguments(commandTokens, mcpServerName) {
313
+ for (let i = 0; i < commandTokens.length; i++) {
314
+ const token = commandTokens[i];
315
+ if (mcpServerName === token || token.includes(mcpServerName)) {
316
+ return true;
317
+ }
318
+ }
319
+ return false;
320
+ }
321
+ parseCommandLine(commandLine) {
322
+ const tokens = [];
323
+ let current = "";
324
+ let inQuotes = false;
325
+ let quoteChar = "";
326
+ for (let i = 0; i < commandLine.length; i++) {
327
+ const char = commandLine[i];
328
+ if (!inQuotes && (char === '"' || char === "'")) {
329
+ inQuotes = true;
330
+ quoteChar = char;
331
+ } else if (inQuotes && char === quoteChar) {
332
+ inQuotes = false;
333
+ quoteChar = "";
334
+ } else if (!inQuotes && char === " ") {
335
+ if (current.trim()) {
336
+ tokens.push(current.trim());
337
+ current = "";
338
+ }
339
+ } else {
340
+ current += char;
341
+ }
342
+ }
343
+ if (current.trim()) {
344
+ tokens.push(current.trim());
345
+ }
346
+ return tokens;
347
+ }
348
+ /*
349
+ example to match:
350
+ ```
351
+ "command": "npx",
352
+ "args": [
353
+ "-y",
354
+ "@modelcontextprotocol/server-postgres",
355
+ "postgresql://localhost/mydb"
356
+ ]
357
+ }
358
+ ```
359
+
360
+ with a process command like:
361
+ ```
362
+ npm exec @modelcontextprotocol/server-postgres postgresql://localhost/mydb
363
+ ```
364
+ */
365
+ matchNpxProcess(commandTokens) {
366
+ if (commandTokens.length < 3) return false;
367
+ if (commandTokens[1] !== "exec") return false;
368
+ let argsToMatch = [];
369
+ const yIndex = this.args.indexOf("-y");
370
+ if (yIndex !== -1 && yIndex + 1 < this.args.length) {
371
+ argsToMatch = this.args.slice(yIndex + 1);
372
+ } else {
373
+ argsToMatch = this.args;
374
+ }
375
+ if (commandTokens.length - 2 !== argsToMatch.length) {
376
+ return false;
377
+ }
378
+ for (let i = 0; i < argsToMatch.length; i++) {
379
+ const commandToken = commandTokens[i + 2];
380
+ const expectedArg = argsToMatch[i];
381
+ if (commandToken !== expectedArg) {
382
+ return false;
383
+ }
384
+ }
385
+ return true;
103
386
  }
104
387
  };
105
388
 
@@ -110,7 +393,7 @@ var MCPFiles = class {
110
393
  }
111
394
  mcpFilePathGroups = {
112
395
  claude: {
113
- name: "claude",
396
+ name: "claude-desktop",
114
397
  friendlyName: "Claude Desktop",
115
398
  paths: [
116
399
  { filePath: "~/Library/Application Support/Claude/claude_desktop_config.json", type: "global" }
@@ -120,8 +403,8 @@ var MCPFiles = class {
120
403
  name: "cursor",
121
404
  friendlyName: "Cursor",
122
405
  paths: [
123
- { filePath: ".cursor/mcp.json", type: "local" },
124
- { filePath: "~/.cursor/mcp.json", type: "global" }
406
+ { filePath: "~/.cursor/mcp.json", type: "global" },
407
+ { filePath: ".cursor/mcp.json", type: "local" }
125
408
  ]
126
409
  }
127
410
  };
@@ -157,13 +440,20 @@ var MCPFiles = class {
157
440
  env: serverConfigRaw.env
158
441
  };
159
442
  const MCPServerManager = new MCPServerManagerService(serverConfig);
443
+ const mcpServerProcessDetection = MCPServerManager.isRunning();
444
+ let mcpServerProcess = false;
445
+ if (mcpServerProcessDetection) {
446
+ if (typeof mcpServerProcessDetection === "object" && mcpServerProcessDetection.estimatedProduct === clientsGroup.name) {
447
+ mcpServerProcess = true;
448
+ }
449
+ }
160
450
  mcpServersData.push({
161
451
  name: MCPServerManager.getName(),
162
452
  command: MCPServerManager.getCmd(),
163
453
  args: MCPServerManager.getArgs(),
164
454
  transport: MCPServerManager.getTransport(),
165
455
  env: MCPServerManager.getEnv(),
166
- status: MCPServerManager.isRunning() ? "running" : "stopped"
456
+ status: mcpServerProcess ? "running" : "stopped"
167
457
  });
168
458
  }
169
459
  filePathData.servers = mcpServersData;
@@ -212,7 +502,7 @@ function render3(text) {
212
502
  if (formattedText === "running") {
213
503
  data = (0, import_node_util3.styleText)(["green"], "\u25CF");
214
504
  } else {
215
- data = (0, import_node_util3.styleText)(["red"], "\u25CB");
505
+ data = (0, import_node_util3.styleText)(["red"], "\u25CF");
216
506
  }
217
507
  return data;
218
508
  }
@@ -242,9 +532,9 @@ function render6(text) {
242
532
  const formattedText = text.toUpperCase().replace(/_/g, " ");
243
533
  let data = formattedText;
244
534
  if (formattedText === "VALID") {
245
- data = (0, import_node_util6.styleText)(["green"], formattedText);
535
+ data = (0, import_node_util6.styleText)(["green"], "\u25CF");
246
536
  } else {
247
- data = (0, import_node_util6.styleText)(["red"], formattedText);
537
+ data = (0, import_node_util6.styleText)(["red"], "\u25CF");
248
538
  }
249
539
  return data;
250
540
  }
@@ -268,18 +558,37 @@ var RenderService = class {
268
558
  if (data.length === 0) return;
269
559
  const headers = ["STATUS", "NAME", "TRANSPORT"];
270
560
  const keys = ["status", "name", "transport"];
271
- const centerColumns = [0, 2, 4, 5];
561
+ const centerColumns = [0, 2];
272
562
  const leftPadding = " ";
273
563
  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);
564
+ const headerWidth = this.getVisibleLength(render2(header));
565
+ const dataWidth = Math.max(...data.map((row) => {
566
+ let text = String(row[keys[index]]);
567
+ if (keys[index] === "transport") {
568
+ text = render(text);
569
+ }
570
+ if (keys[index] === "status") {
571
+ text = render3(text);
572
+ }
573
+ if (keys[index] === "name") {
574
+ text = render4(text);
575
+ }
576
+ return this.getVisibleLength(text);
577
+ }));
578
+ return Math.max(headerWidth, dataWidth);
276
579
  });
277
580
  const centerText = /* @__PURE__ */ __name((text, width) => {
278
- const padding = width - this.getVisibleLength(text);
581
+ const visibleLength = this.getVisibleLength(text);
582
+ const padding = width - visibleLength;
279
583
  const leftPad = Math.floor(padding / 2);
280
584
  const rightPad = padding - leftPad;
281
585
  return " ".repeat(leftPad) + text + " ".repeat(rightPad);
282
586
  }, "centerText");
587
+ const padRight = /* @__PURE__ */ __name((text, width) => {
588
+ const visibleLength = this.getVisibleLength(text);
589
+ const padding = Math.max(0, width - visibleLength);
590
+ return text + " ".repeat(padding);
591
+ }, "padRight");
283
592
  const totalWidth = columnWidths.reduce((sum, width) => sum + width, 0) + (columnWidths.length - 1) * 2;
284
593
  const separator = "\u2500".repeat(totalWidth);
285
594
  console.log("\n" + leftPadding + separator);
@@ -288,8 +597,7 @@ var RenderService = class {
288
597
  if (centerColumns.includes(index)) {
289
598
  return centerText(headerText, columnWidths[index]);
290
599
  }
291
- const padding = columnWidths[index] - this.getVisibleLength(headerText);
292
- return headerText + " ".repeat(Math.max(0, padding));
600
+ return padRight(headerText, columnWidths[index]);
293
601
  }).join(" ");
294
602
  console.log(leftPadding + headerRow);
295
603
  console.log(leftPadding + separator);
@@ -308,7 +616,7 @@ var RenderService = class {
308
616
  if (centerColumns.includes(index)) {
309
617
  return centerText(text, columnWidths[index]);
310
618
  }
311
- return text.padEnd(columnWidths[index]);
619
+ return padRight(text, columnWidths[index]);
312
620
  }).join(" ");
313
621
  console.log(leftPadding + dataRow);
314
622
  }
@@ -371,10 +679,15 @@ var RenderService = class {
371
679
  const progress = Math.min(count / total, 1);
372
680
  const filledWidth = Math.round(progress * width);
373
681
  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));
682
+ let filled;
683
+ let empty;
684
+ if (count > 0) {
685
+ filled = (0, import_node_util7.styleText)(["greenBright"], "\u2588".repeat(filledWidth));
686
+ empty = (0, import_node_util7.styleText)(["green"], "\u2591".repeat(emptyWidth));
687
+ } else {
688
+ filled = "\u2588".repeat(filledWidth);
689
+ empty = "\u2591".repeat(emptyWidth);
690
+ }
378
691
  return `${filled}${empty} ${count} / ${total} ${label}`;
379
692
  }
380
693
  };
@@ -388,12 +701,12 @@ async function init() {
388
701
  console.log("No MCP files found.");
389
702
  return;
390
703
  }
391
- let groupIndex = 0;
704
+ let pathIndex = 0;
392
705
  for (const groupName of Object.keys(mcpFilesList)) {
393
- groupIndex++;
394
706
  const group = mcpFilesList[groupName];
395
707
  if (group.paths.length >= 0) {
396
708
  for (const filePathData of group.paths) {
709
+ pathIndex++;
397
710
  const filePath = filePathData.filePath.replace("~", process.env.HOME || "");
398
711
  const filePathValid = filePathData.parsable ? "VALID" : "INVALID";
399
712
  const filePathDataType = filePathData.type.toUpperCase();
@@ -403,14 +716,14 @@ async function init() {
403
716
  const mcpGroupData = [
404
717
  { key: "PROVIDER", value: group.friendlyName },
405
718
  { key: "FILE", value: filePath },
406
- { key: "PARSABLE", value: filePathValid },
407
- { key: "TYPE", value: filePathDataType }
719
+ { key: "TYPE", value: filePathDataType },
720
+ { key: "PARSABLE", value: filePathValid }
408
721
  ];
409
722
  const groupMetadata = {
410
723
  mcpServersTotal: totalMCPServers,
411
724
  mcpServersRunning: totalMCPServersRunning
412
725
  };
413
- RenderService.printMcpGroup(groupIndex, mcpGroupData, groupMetadata);
726
+ RenderService.printMcpGroup(pathIndex, mcpGroupData, groupMetadata);
414
727
  RenderService.printMcpServers(mcpServers);
415
728
  }
416
729
  } 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