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.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  var __defProp = Object.defineProperty;
2
3
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
4
 
@@ -44,6 +45,8 @@ var MCPConfigLinterService = class {
44
45
  };
45
46
 
46
47
  // src/services/mcp-server-manager-service.ts
48
+ import { execSync } from "child_process";
49
+ import { platform } from "os";
47
50
  var MCPServerManagerService = class {
48
51
  static {
49
52
  __name(this, "MCPServerManagerService");
@@ -77,7 +80,287 @@ var MCPServerManagerService = class {
77
80
  return this.env;
78
81
  }
79
82
  isRunning() {
80
- return this.running;
83
+ try {
84
+ let psOutput;
85
+ if (platform() === "win32") {
86
+ psOutput = execSync("wmic process get ProcessId,ParentProcessId,CommandLine /format:csv", {
87
+ encoding: "utf8",
88
+ timeout: 5e3
89
+ });
90
+ } else {
91
+ psOutput = execSync("ps -eao pid,ppid,args", {
92
+ encoding: "utf8",
93
+ timeout: 5e3
94
+ });
95
+ }
96
+ const processMap = /* @__PURE__ */ new Map();
97
+ const processes = psOutput.trim().split("\n");
98
+ for (const processLine of processes) {
99
+ if (!processLine.trim()) continue;
100
+ let pid;
101
+ let ppid;
102
+ let commandLine;
103
+ if (platform() === "win32") {
104
+ const parts = processLine.split(",");
105
+ if (parts.length < 4) continue;
106
+ commandLine = parts[1] || "";
107
+ ppid = parts[2] || "";
108
+ pid = parts[3] || "";
109
+ } else {
110
+ const match = processLine.trim().match(/^\s*(\d+)\s+(\d+)\s+(.+)$/);
111
+ if (!match) continue;
112
+ pid = match[1];
113
+ ppid = match[2];
114
+ commandLine = match[3];
115
+ }
116
+ const commandTokens = this.parseCommandLine(commandLine);
117
+ if (commandTokens.length > 0) {
118
+ processMap.set(pid, { ppid, commandTokens });
119
+ }
120
+ }
121
+ let mcpServerDetection;
122
+ for (const [pid, processData] of processMap) {
123
+ if (this.isCommandMatch(processData.commandTokens, pid, processData.ppid)) {
124
+ mcpServerDetection = {
125
+ pid,
126
+ commandLine: processData.commandTokens.join(" "),
127
+ ppid: processData.ppid
128
+ };
129
+ const parentProcess = processMap.get(processData.ppid);
130
+ if (parentProcess) {
131
+ const { estimatedVendor, estimatedProduct } = this.getVendorFromCommand(parentProcess.commandTokens) || {};
132
+ if (estimatedProduct || estimatedVendor) {
133
+ mcpServerDetection = {
134
+ ...mcpServerDetection,
135
+ parentCommandLine: parentProcess.commandTokens.join(" "),
136
+ estimatedVendor,
137
+ estimatedProduct
138
+ };
139
+ return mcpServerDetection;
140
+ }
141
+ }
142
+ }
143
+ }
144
+ if (mcpServerDetection) {
145
+ return mcpServerDetection;
146
+ }
147
+ return false;
148
+ } catch (error) {
149
+ return false;
150
+ }
151
+ }
152
+ getVendorFromCommand(commandTokens) {
153
+ const commandString = commandTokens.join(" ").toLowerCase();
154
+ if (commandString.includes("claude.app")) {
155
+ return {
156
+ estimatedVendor: "anthropic",
157
+ estimatedProduct: "claude-desktop"
158
+ };
159
+ }
160
+ if (commandString.includes("claude")) {
161
+ return {
162
+ estimatedVendor: "anthropic",
163
+ estimatedProduct: "claude-desktop"
164
+ };
165
+ }
166
+ }
167
+ isCommandMatch(commandTokens, pid, ppid) {
168
+ if (commandTokens.length === 0) return false;
169
+ const baseCommand = this.getBaseCommand(commandTokens[0]);
170
+ if (this.command === "uvx" && baseCommand === "uv") {
171
+ return this.matchUvxProcess(commandTokens);
172
+ }
173
+ if (this.command === "npx" && baseCommand === "npm") {
174
+ return this.matchNpxProcess(commandTokens);
175
+ }
176
+ if (this.command === "uv" && baseCommand === "uv") {
177
+ return this.matchGenericArgsToArgs(commandTokens);
178
+ }
179
+ const commandConfigPythonBase = this.getBaseCommand(this.command);
180
+ const commandAliasesPython = ["python3", "python", "python3.10", "python3.11", "python3.12", "cpython3", "cpython", "python3", "python2"];
181
+ if (commandAliasesPython.includes(commandConfigPythonBase) && commandAliasesPython.includes(baseCommand)) {
182
+ return this.matchGenericArgsToArgs(commandTokens);
183
+ }
184
+ const commandGenericBase = this.getBaseCommand(this.command);
185
+ const commandGenericProcessBase = this.getBaseCommand(commandTokens[0]);
186
+ if (commandGenericBase === commandGenericProcessBase) {
187
+ return this.matchGenericArgsToArgs(commandTokens);
188
+ }
189
+ return false;
190
+ }
191
+ matchGenericArgsToArgs(commandTokens) {
192
+ if (this.args.length === 0) {
193
+ return commandTokens[0] === this.command;
194
+ }
195
+ if (commandTokens.length < 2) {
196
+ return false;
197
+ }
198
+ const commandWithoutArgs = commandTokens.slice(1);
199
+ for (let i = 0; i < this.args.length; i++) {
200
+ if (i >= commandWithoutArgs.length) return false;
201
+ const arg = this.args[i];
202
+ const token = commandWithoutArgs[i];
203
+ if (arg !== token && !token.includes(arg)) {
204
+ return false;
205
+ }
206
+ }
207
+ return true;
208
+ }
209
+ // @TODO refactor this to use path.basename or similar
210
+ // to extract the base command from the full command path
211
+ getBaseCommand(fullCommandPath) {
212
+ const parts = fullCommandPath.split(/[/\\]/);
213
+ return parts[parts.length - 1];
214
+ }
215
+ /*
216
+ example1:
217
+ ```
218
+ "command": "uvx",
219
+ "args": ["--from", "mcp-alchemy==2025.5.2.210242", "--with", "oracledb",
220
+ "--refresh-package", "mcp-alchemy", "mcp-alchemy"],
221
+ ```
222
+
223
+ example 2:
224
+ ```
225
+ "command": "uvx",
226
+ "args": [
227
+ "mcp-neo4j-memory@0.1.4",
228
+ "--db-url",
229
+ "neo4j+s://xxxx.databases.neo4j.io",
230
+ "--username",
231
+ "<your-username>",
232
+ "--password",
233
+ "<your-password>"
234
+ ]
235
+ ```
236
+
237
+ example 3:
238
+ ```
239
+ "vefaas": {
240
+ "command": "uvx",
241
+ "args": [
242
+ "--from",
243
+ "git+https://github.com/volcengine/mcp-server#subdirectory=server/mcp_server_vefaas_function",
244
+ "mcp-server-vefaas-function"
245
+ ],
246
+ "env": {
247
+ "VOLC_ACCESSKEY": "xxx",
248
+ "VOLC_SECRETKEY": "xxx"
249
+ }
250
+ }
251
+ }
252
+ ```
253
+
254
+ example 4:
255
+ ```
256
+ "time": {
257
+ "command": "uvx",
258
+ "args": ["mcp-server-time", "--local-timezone=America/New_York"]
259
+ }
260
+ ```
261
+ */
262
+ getUvxMcpServerNameFromArgs() {
263
+ if (this.args.length === 0) return void 0;
264
+ let mcpServerName;
265
+ if (this.args.length === 1) {
266
+ mcpServerName = this.args[0];
267
+ return mcpServerName;
268
+ }
269
+ for (let i = 0; i < this.args.length; i++) {
270
+ if (this.args[i] === "--from" && i + 1 < this.args.length) {
271
+ mcpServerName = this.args[i + 1];
272
+ return mcpServerName;
273
+ }
274
+ }
275
+ const firstArg = this.args[0];
276
+ if (firstArg.startsWith("-") || firstArg.startsWith("--")) {
277
+ const lastArg = this.args[this.args.length - 1];
278
+ mcpServerName = lastArg;
279
+ return mcpServerName;
280
+ }
281
+ mcpServerName = firstArg;
282
+ return mcpServerName;
283
+ }
284
+ matchUvxProcess(commandTokens) {
285
+ if (commandTokens.length === 0) return false;
286
+ const mcpServerName = this.getUvxMcpServerNameFromArgs();
287
+ if (!mcpServerName) return false;
288
+ return this.findMcpServerNameInProcessArguments(commandTokens, mcpServerName);
289
+ }
290
+ findMcpServerNameInProcessArguments(commandTokens, mcpServerName) {
291
+ for (let i = 0; i < commandTokens.length; i++) {
292
+ const token = commandTokens[i];
293
+ if (mcpServerName === token || token.includes(mcpServerName)) {
294
+ return true;
295
+ }
296
+ }
297
+ return false;
298
+ }
299
+ parseCommandLine(commandLine) {
300
+ const tokens = [];
301
+ let current = "";
302
+ let inQuotes = false;
303
+ let quoteChar = "";
304
+ for (let i = 0; i < commandLine.length; i++) {
305
+ const char = commandLine[i];
306
+ if (!inQuotes && (char === '"' || char === "'")) {
307
+ inQuotes = true;
308
+ quoteChar = char;
309
+ } else if (inQuotes && char === quoteChar) {
310
+ inQuotes = false;
311
+ quoteChar = "";
312
+ } else if (!inQuotes && char === " ") {
313
+ if (current.trim()) {
314
+ tokens.push(current.trim());
315
+ current = "";
316
+ }
317
+ } else {
318
+ current += char;
319
+ }
320
+ }
321
+ if (current.trim()) {
322
+ tokens.push(current.trim());
323
+ }
324
+ return tokens;
325
+ }
326
+ /*
327
+ example to match:
328
+ ```
329
+ "command": "npx",
330
+ "args": [
331
+ "-y",
332
+ "@modelcontextprotocol/server-postgres",
333
+ "postgresql://localhost/mydb"
334
+ ]
335
+ }
336
+ ```
337
+
338
+ with a process command like:
339
+ ```
340
+ npm exec @modelcontextprotocol/server-postgres postgresql://localhost/mydb
341
+ ```
342
+ */
343
+ matchNpxProcess(commandTokens) {
344
+ if (commandTokens.length < 3) return false;
345
+ if (commandTokens[1] !== "exec") return false;
346
+ let argsToMatch = [];
347
+ const yIndex = this.args.indexOf("-y");
348
+ if (yIndex !== -1 && yIndex + 1 < this.args.length) {
349
+ argsToMatch = this.args.slice(yIndex + 1);
350
+ } else {
351
+ argsToMatch = this.args;
352
+ }
353
+ if (commandTokens.length - 2 !== argsToMatch.length) {
354
+ return false;
355
+ }
356
+ for (let i = 0; i < argsToMatch.length; i++) {
357
+ const commandToken = commandTokens[i + 2];
358
+ const expectedArg = argsToMatch[i];
359
+ if (commandToken !== expectedArg) {
360
+ return false;
361
+ }
362
+ }
363
+ return true;
81
364
  }
82
365
  };
83
366
 
@@ -88,7 +371,7 @@ var MCPFiles = class {
88
371
  }
89
372
  mcpFilePathGroups = {
90
373
  claude: {
91
- name: "claude",
374
+ name: "claude-desktop",
92
375
  friendlyName: "Claude Desktop",
93
376
  paths: [
94
377
  { filePath: "~/Library/Application Support/Claude/claude_desktop_config.json", type: "global" }
@@ -98,8 +381,8 @@ var MCPFiles = class {
98
381
  name: "cursor",
99
382
  friendlyName: "Cursor",
100
383
  paths: [
101
- { filePath: ".cursor/mcp.json", type: "local" },
102
- { filePath: "~/.cursor/mcp.json", type: "global" }
384
+ { filePath: "~/.cursor/mcp.json", type: "global" },
385
+ { filePath: ".cursor/mcp.json", type: "local" }
103
386
  ]
104
387
  }
105
388
  };
@@ -135,13 +418,20 @@ var MCPFiles = class {
135
418
  env: serverConfigRaw.env
136
419
  };
137
420
  const MCPServerManager = new MCPServerManagerService(serverConfig);
421
+ const mcpServerProcessDetection = MCPServerManager.isRunning();
422
+ let mcpServerProcess = false;
423
+ if (mcpServerProcessDetection) {
424
+ if (typeof mcpServerProcessDetection === "object" && mcpServerProcessDetection.estimatedProduct === clientsGroup.name) {
425
+ mcpServerProcess = true;
426
+ }
427
+ }
138
428
  mcpServersData.push({
139
429
  name: MCPServerManager.getName(),
140
430
  command: MCPServerManager.getCmd(),
141
431
  args: MCPServerManager.getArgs(),
142
432
  transport: MCPServerManager.getTransport(),
143
433
  env: MCPServerManager.getEnv(),
144
- status: MCPServerManager.isRunning() ? "running" : "stopped"
434
+ status: mcpServerProcess ? "running" : "stopped"
145
435
  });
146
436
  }
147
437
  filePathData.servers = mcpServersData;
@@ -190,7 +480,7 @@ function render3(text) {
190
480
  if (formattedText === "running") {
191
481
  data = styleText3(["green"], "\u25CF");
192
482
  } else {
193
- data = styleText3(["red"], "\u25CB");
483
+ data = styleText3(["red"], "\u25CF");
194
484
  }
195
485
  return data;
196
486
  }
@@ -220,9 +510,9 @@ function render6(text) {
220
510
  const formattedText = text.toUpperCase().replace(/_/g, " ");
221
511
  let data = formattedText;
222
512
  if (formattedText === "VALID") {
223
- data = styleText6(["green"], formattedText);
513
+ data = styleText6(["green"], "\u25CF");
224
514
  } else {
225
- data = styleText6(["red"], formattedText);
515
+ data = styleText6(["red"], "\u25CF");
226
516
  }
227
517
  return data;
228
518
  }
@@ -246,18 +536,37 @@ var RenderService = class {
246
536
  if (data.length === 0) return;
247
537
  const headers = ["STATUS", "NAME", "TRANSPORT"];
248
538
  const keys = ["status", "name", "transport"];
249
- const centerColumns = [0, 2, 4, 5];
539
+ const centerColumns = [0, 2];
250
540
  const leftPadding = " ";
251
541
  const columnWidths = headers.map((header, index) => {
252
- const dataWidth = Math.max(...data.map((row) => String(row[keys[index]]).length));
253
- return Math.max(header.length, dataWidth);
542
+ const headerWidth = this.getVisibleLength(render2(header));
543
+ const dataWidth = Math.max(...data.map((row) => {
544
+ let text = String(row[keys[index]]);
545
+ if (keys[index] === "transport") {
546
+ text = render(text);
547
+ }
548
+ if (keys[index] === "status") {
549
+ text = render3(text);
550
+ }
551
+ if (keys[index] === "name") {
552
+ text = render4(text);
553
+ }
554
+ return this.getVisibleLength(text);
555
+ }));
556
+ return Math.max(headerWidth, dataWidth);
254
557
  });
255
558
  const centerText = /* @__PURE__ */ __name((text, width) => {
256
- const padding = width - this.getVisibleLength(text);
559
+ const visibleLength = this.getVisibleLength(text);
560
+ const padding = width - visibleLength;
257
561
  const leftPad = Math.floor(padding / 2);
258
562
  const rightPad = padding - leftPad;
259
563
  return " ".repeat(leftPad) + text + " ".repeat(rightPad);
260
564
  }, "centerText");
565
+ const padRight = /* @__PURE__ */ __name((text, width) => {
566
+ const visibleLength = this.getVisibleLength(text);
567
+ const padding = Math.max(0, width - visibleLength);
568
+ return text + " ".repeat(padding);
569
+ }, "padRight");
261
570
  const totalWidth = columnWidths.reduce((sum, width) => sum + width, 0) + (columnWidths.length - 1) * 2;
262
571
  const separator = "\u2500".repeat(totalWidth);
263
572
  console.log("\n" + leftPadding + separator);
@@ -266,8 +575,7 @@ var RenderService = class {
266
575
  if (centerColumns.includes(index)) {
267
576
  return centerText(headerText, columnWidths[index]);
268
577
  }
269
- const padding = columnWidths[index] - this.getVisibleLength(headerText);
270
- return headerText + " ".repeat(Math.max(0, padding));
578
+ return padRight(headerText, columnWidths[index]);
271
579
  }).join(" ");
272
580
  console.log(leftPadding + headerRow);
273
581
  console.log(leftPadding + separator);
@@ -286,7 +594,7 @@ var RenderService = class {
286
594
  if (centerColumns.includes(index)) {
287
595
  return centerText(text, columnWidths[index]);
288
596
  }
289
- return text.padEnd(columnWidths[index]);
597
+ return padRight(text, columnWidths[index]);
290
598
  }).join(" ");
291
599
  console.log(leftPadding + dataRow);
292
600
  }
@@ -349,10 +657,15 @@ var RenderService = class {
349
657
  const progress = Math.min(count / total, 1);
350
658
  const filledWidth = Math.round(progress * width);
351
659
  const emptyWidth = width - filledWidth;
352
- const colorRunning = count > 0 ? "greenBright" : "red";
353
- const colorEmpty = count > 0 ? "green" : "red";
354
- const filled = styleText7([colorRunning], "\u2588".repeat(filledWidth));
355
- const empty = styleText7([colorEmpty], "\u2591".repeat(emptyWidth));
660
+ let filled;
661
+ let empty;
662
+ if (count > 0) {
663
+ filled = styleText7(["greenBright"], "\u2588".repeat(filledWidth));
664
+ empty = styleText7(["green"], "\u2591".repeat(emptyWidth));
665
+ } else {
666
+ filled = "\u2588".repeat(filledWidth);
667
+ empty = "\u2591".repeat(emptyWidth);
668
+ }
356
669
  return `${filled}${empty} ${count} / ${total} ${label}`;
357
670
  }
358
671
  };
@@ -366,12 +679,12 @@ async function init() {
366
679
  console.log("No MCP files found.");
367
680
  return;
368
681
  }
369
- let groupIndex = 0;
682
+ let pathIndex = 0;
370
683
  for (const groupName of Object.keys(mcpFilesList)) {
371
- groupIndex++;
372
684
  const group = mcpFilesList[groupName];
373
685
  if (group.paths.length >= 0) {
374
686
  for (const filePathData of group.paths) {
687
+ pathIndex++;
375
688
  const filePath = filePathData.filePath.replace("~", process.env.HOME || "");
376
689
  const filePathValid = filePathData.parsable ? "VALID" : "INVALID";
377
690
  const filePathDataType = filePathData.type.toUpperCase();
@@ -381,14 +694,14 @@ async function init() {
381
694
  const mcpGroupData = [
382
695
  { key: "PROVIDER", value: group.friendlyName },
383
696
  { key: "FILE", value: filePath },
384
- { key: "PARSABLE", value: filePathValid },
385
- { key: "TYPE", value: filePathDataType }
697
+ { key: "TYPE", value: filePathDataType },
698
+ { key: "PARSABLE", value: filePathValid }
386
699
  ];
387
700
  const groupMetadata = {
388
701
  mcpServersTotal: totalMCPServers,
389
702
  mcpServersRunning: totalMCPServersRunning
390
703
  };
391
- RenderService.printMcpGroup(groupIndex, mcpGroupData, groupMetadata);
704
+ RenderService.printMcpGroup(pathIndex, mcpGroupData, groupMetadata);
392
705
  RenderService.printMcpServers(mcpServers);
393
706
  }
394
707
  } else {