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