ls-mcp 1.3.0 → 1.4.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
@@ -24,8 +24,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  mod
25
25
  ));
26
26
 
27
+ // src/bin/cli.ts
28
+ var import_node_util8 = require("util");
29
+
27
30
  // src/main.ts
28
31
  var import_promises2 = __toESM(require("fs/promises"), 1);
32
+ var import_node_os2 = require("os");
29
33
 
30
34
  // src/services/mcp-config-linter-service.ts
31
35
  var import_promises = __toESM(require("fs/promises"), 1);
@@ -67,6 +71,7 @@ var MCPConfigLinterService = class {
67
71
  };
68
72
 
69
73
  // src/services/mcp-server-manager-service.ts
74
+ var import_node_path = __toESM(require("path"), 1);
70
75
  var import_node_child_process = require("child_process");
71
76
  var import_node_os = require("os");
72
77
  var MCPServerManagerService = class {
@@ -105,7 +110,7 @@ var MCPServerManagerService = class {
105
110
  try {
106
111
  let psOutput;
107
112
  if ((0, import_node_os.platform)() === "win32") {
108
- psOutput = (0, import_node_child_process.execSync)("wmic process get ProcessId,ParentProcessId,CommandLine /format:csv", {
113
+ psOutput = (0, import_node_child_process.execSync)('powershell -Command "Get-CimInstance -ClassName Win32_Process | Select-Object ProcessId,Name,CommandLine,ParentProcessId | ConvertTo-Csv -NoTypeInformation"', {
109
114
  encoding: "utf8",
110
115
  timeout: 5e3
111
116
  });
@@ -123,17 +128,18 @@ var MCPServerManagerService = class {
123
128
  let ppid;
124
129
  let commandLine;
125
130
  if ((0, import_node_os.platform)() === "win32") {
126
- const parts = processLine.split(",");
131
+ if (processLine.startsWith('"ProcessId"') || processLine.startsWith("ProcessId")) continue;
132
+ const parts = this.parseCSVLine(processLine);
127
133
  if (parts.length < 4) continue;
128
- commandLine = parts[1] || "";
129
- ppid = parts[2] || "";
130
- pid = parts[3] || "";
134
+ pid = parts[0].trim() || "";
135
+ commandLine = parts[2].trim() || "";
136
+ ppid = parts[3].trim() || "";
131
137
  } else {
132
138
  const match = processLine.trim().match(/^\s*(\d+)\s+(\d+)\s+(.+)$/);
133
139
  if (!match) continue;
134
- pid = match[1];
135
- ppid = match[2];
136
- commandLine = match[3];
140
+ pid = match[1].trim() || "";
141
+ ppid = match[2].trim() || "";
142
+ commandLine = match[3].trim() || "";
137
143
  }
138
144
  const commandTokens = this.parseCommandLine(commandLine);
139
145
  if (commandTokens.length > 0) {
@@ -142,7 +148,20 @@ var MCPServerManagerService = class {
142
148
  }
143
149
  let mcpServerDetection;
144
150
  for (const [pid, processData] of processMap) {
145
- if (this.isCommandMatch(processData.commandTokens, pid, processData.ppid)) {
151
+ const commandMatchLinux = this.isCommandMatch(processData.commandTokens, pid, processData.ppid);
152
+ let commandMatchWin32 = false;
153
+ if ((0, import_node_os.platform)() === "win32") {
154
+ let commandTokensOnWin32 = processData.commandTokens;
155
+ if (commandTokensOnWin32.length > 0 && commandTokensOnWin32[0].toLowerCase().startsWith("cmd")) {
156
+ commandTokensOnWin32 = commandTokensOnWin32.slice(1);
157
+ while (commandTokensOnWin32.length > 0 && commandTokensOnWin32[0].startsWith("/")) {
158
+ commandTokensOnWin32 = commandTokensOnWin32.slice(1);
159
+ }
160
+ }
161
+ commandMatchWin32 = this.isCommandMatch(commandTokensOnWin32, pid, processData.ppid);
162
+ }
163
+ const commandMatch = commandMatchLinux || commandMatchWin32;
164
+ if (commandMatch) {
146
165
  mcpServerDetection = {
147
166
  pid,
148
167
  commandLine: processData.commandTokens.join(" "),
@@ -189,13 +208,14 @@ var MCPServerManagerService = class {
189
208
  isCommandMatch(commandTokens, pid, ppid) {
190
209
  if (commandTokens.length === 0) return false;
191
210
  const baseCommand = this.getBaseCommand(commandTokens[0]);
192
- if (this.command === "uvx" && baseCommand === "uv") {
211
+ const commandInConfig = this.getBaseCommand(this.command);
212
+ if (commandInConfig === "uvx" && baseCommand === "uv") {
193
213
  return this.matchUvxProcess(commandTokens);
194
214
  }
195
- if (this.command === "npx" && baseCommand === "npm") {
215
+ if (commandInConfig === "npx" && baseCommand === "npm") {
196
216
  return this.matchNpxProcess(commandTokens);
197
217
  }
198
- if (this.command === "uv" && baseCommand === "uv") {
218
+ if (commandInConfig === "uv" && baseCommand === "uv") {
199
219
  return this.matchGenericArgsToArgs(commandTokens);
200
220
  }
201
221
  const commandConfigPythonBase = this.getBaseCommand(this.command);
@@ -220,19 +240,21 @@ var MCPServerManagerService = class {
220
240
  const commandWithoutArgs = commandTokens.slice(1);
221
241
  for (let i = 0; i < this.args.length; i++) {
222
242
  if (i >= commandWithoutArgs.length) return false;
223
- const arg = this.args[i];
224
- const token = commandWithoutArgs[i];
243
+ const arg = this.args[i].toLowerCase();
244
+ const token = commandWithoutArgs[i].toLowerCase();
225
245
  if (arg !== token && !token.includes(arg)) {
226
246
  return false;
227
247
  }
228
248
  }
229
249
  return true;
230
250
  }
231
- // @TODO refactor this to use path.basename or similar
232
- // to extract the base command from the full command path
233
251
  getBaseCommand(fullCommandPath) {
234
- const parts = fullCommandPath.split(/[/\\]/);
235
- return parts[parts.length - 1];
252
+ let baseCommand = import_node_path.default.basename(fullCommandPath);
253
+ if ((0, import_node_os.platform)() === "win32") {
254
+ baseCommand = import_node_path.default.basename(fullCommandPath, ".exe");
255
+ }
256
+ baseCommand = baseCommand.toLowerCase();
257
+ return baseCommand;
236
258
  }
237
259
  /*
238
260
  example1:
@@ -311,13 +333,37 @@ var MCPServerManagerService = class {
311
333
  }
312
334
  findMcpServerNameInProcessArguments(commandTokens, mcpServerName) {
313
335
  for (let i = 0; i < commandTokens.length; i++) {
314
- const token = commandTokens[i];
315
- if (mcpServerName === token || token.includes(mcpServerName)) {
336
+ const token = commandTokens[i].toLowerCase();
337
+ const normalizedMcpServerName = mcpServerName.toLowerCase();
338
+ if (normalizedMcpServerName === token || token.includes(normalizedMcpServerName)) {
316
339
  return true;
317
340
  }
318
341
  }
319
342
  return false;
320
343
  }
344
+ parseCSVLine(line) {
345
+ const result = [];
346
+ let current = "";
347
+ let inQuotes = false;
348
+ for (let i = 0; i < line.length; i++) {
349
+ const char = line[i];
350
+ if (char === '"') {
351
+ if (inQuotes && line[i + 1] === '"') {
352
+ current += '"';
353
+ i++;
354
+ } else {
355
+ inQuotes = !inQuotes;
356
+ }
357
+ } else if (char === "," && !inQuotes) {
358
+ result.push(current);
359
+ current = "";
360
+ } else {
361
+ current += char;
362
+ }
363
+ }
364
+ result.push(current);
365
+ return result;
366
+ }
321
367
  parseCommandLine(commandLine) {
322
368
  const tokens = [];
323
369
  let current = "";
@@ -376,8 +422,8 @@ var MCPServerManagerService = class {
376
422
  return false;
377
423
  }
378
424
  for (let i = 0; i < argsToMatch.length; i++) {
379
- const commandToken = commandTokens[i + 2];
380
- const expectedArg = argsToMatch[i];
425
+ const commandToken = commandTokens[i + 2].toLowerCase();
426
+ const expectedArg = argsToMatch[i].toLowerCase();
381
427
  if (commandToken !== expectedArg) {
382
428
  return false;
383
429
  }
@@ -387,6 +433,27 @@ var MCPServerManagerService = class {
387
433
  };
388
434
 
389
435
  // src/main.ts
436
+ var osSpecificPaths = {
437
+ claude: [],
438
+ cursor: []
439
+ };
440
+ if ((0, import_node_os2.platform)() === "win32") {
441
+ osSpecificPaths["claude"] = [
442
+ { filePath: `${process.env.APPDATA}\\Claude\\claude_desktop_config.json`, type: "global" }
443
+ ];
444
+ osSpecificPaths["cursor"] = [
445
+ { filePath: `${process.env.HOME}\\.cursor\\mcp.json`, type: "global" },
446
+ { filePath: ".cursor\\mcp.json", type: "local" }
447
+ ];
448
+ } else {
449
+ osSpecificPaths["claude"] = [
450
+ { filePath: "~/Library/Application Support/Claude/claude_desktop_config.json", type: "global" }
451
+ ];
452
+ osSpecificPaths["cursor"] = [
453
+ { filePath: "~/.cursor/mcp.json", type: "global" },
454
+ { filePath: ".cursor/mcp.json", type: "local" }
455
+ ];
456
+ }
390
457
  var MCPFiles = class {
391
458
  static {
392
459
  __name(this, "MCPFiles");
@@ -395,17 +462,12 @@ var MCPFiles = class {
395
462
  claude: {
396
463
  name: "claude-desktop",
397
464
  friendlyName: "Claude Desktop",
398
- paths: [
399
- { filePath: "~/Library/Application Support/Claude/claude_desktop_config.json", type: "global" }
400
- ]
465
+ paths: osSpecificPaths["claude"]
401
466
  },
402
467
  cursor: {
403
468
  name: "cursor",
404
469
  friendlyName: "Cursor",
405
- paths: [
406
- { filePath: "~/.cursor/mcp.json", type: "global" },
407
- { filePath: ".cursor/mcp.json", type: "local" }
408
- ]
470
+ paths: osSpecificPaths["cursor"]
409
471
  }
410
472
  };
411
473
  constructor(mcpFilePathGroups) {
@@ -693,18 +755,18 @@ var RenderService = class {
693
755
  };
694
756
 
695
757
  // src/bin/cli.ts
696
- console.log();
697
758
  async function init() {
759
+ console.log();
760
+ console.log("[+] Detecting MCP Server configurations...");
698
761
  const mcpFilesManager = new MCPFiles();
699
762
  const mcpFilesList = await mcpFilesManager.findFiles();
700
763
  if (Object.keys(mcpFilesList).length === 0) {
701
- console.log("No MCP files found.");
702
- return;
764
+ exitWithError("No configuration for MCP Server applications found.");
703
765
  }
704
766
  let pathIndex = 0;
705
767
  for (const groupName of Object.keys(mcpFilesList)) {
706
768
  const group = mcpFilesList[groupName];
707
- if (group.paths.length >= 0) {
769
+ if (group.paths.length > 0) {
708
770
  for (const filePathData of group.paths) {
709
771
  pathIndex++;
710
772
  const filePath = filePathData.filePath.replace("~", process.env.HOME || "");
@@ -726,12 +788,19 @@ async function init() {
726
788
  RenderService.printMcpGroup(pathIndex, mcpGroupData, groupMetadata);
727
789
  RenderService.printMcpServers(mcpServers);
728
790
  }
729
- } else {
730
- console.log("No files found in this group.");
731
791
  }
732
792
  }
793
+ if (pathIndex === 0) {
794
+ exitWithError("No MCP servers found in known configuration files.");
795
+ }
733
796
  }
734
797
  __name(init, "init");
735
798
  init().then(() => {
736
799
  console.log("\n");
737
800
  });
801
+ function exitWithError(message) {
802
+ console.error(`${(0, import_node_util8.styleText)(["red"], "\u25CF")} ${message}
803
+ `);
804
+ process.exit(1);
805
+ }
806
+ __name(exitWithError, "exitWithError");
package/dist/bin/cli.mjs CHANGED
@@ -2,8 +2,12 @@
2
2
  var __defProp = Object.defineProperty;
3
3
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
4
 
5
+ // src/bin/cli.ts
6
+ import { styleText as styleText8 } from "util";
7
+
5
8
  // src/main.ts
6
9
  import fs2 from "fs/promises";
10
+ import { platform as platform2 } from "os";
7
11
 
8
12
  // src/services/mcp-config-linter-service.ts
9
13
  import fs from "fs/promises";
@@ -45,6 +49,7 @@ var MCPConfigLinterService = class {
45
49
  };
46
50
 
47
51
  // src/services/mcp-server-manager-service.ts
52
+ import path from "path";
48
53
  import { execSync } from "child_process";
49
54
  import { platform } from "os";
50
55
  var MCPServerManagerService = class {
@@ -83,7 +88,7 @@ var MCPServerManagerService = class {
83
88
  try {
84
89
  let psOutput;
85
90
  if (platform() === "win32") {
86
- psOutput = execSync("wmic process get ProcessId,ParentProcessId,CommandLine /format:csv", {
91
+ psOutput = execSync('powershell -Command "Get-CimInstance -ClassName Win32_Process | Select-Object ProcessId,Name,CommandLine,ParentProcessId | ConvertTo-Csv -NoTypeInformation"', {
87
92
  encoding: "utf8",
88
93
  timeout: 5e3
89
94
  });
@@ -101,17 +106,18 @@ var MCPServerManagerService = class {
101
106
  let ppid;
102
107
  let commandLine;
103
108
  if (platform() === "win32") {
104
- const parts = processLine.split(",");
109
+ if (processLine.startsWith('"ProcessId"') || processLine.startsWith("ProcessId")) continue;
110
+ const parts = this.parseCSVLine(processLine);
105
111
  if (parts.length < 4) continue;
106
- commandLine = parts[1] || "";
107
- ppid = parts[2] || "";
108
- pid = parts[3] || "";
112
+ pid = parts[0].trim() || "";
113
+ commandLine = parts[2].trim() || "";
114
+ ppid = parts[3].trim() || "";
109
115
  } else {
110
116
  const match = processLine.trim().match(/^\s*(\d+)\s+(\d+)\s+(.+)$/);
111
117
  if (!match) continue;
112
- pid = match[1];
113
- ppid = match[2];
114
- commandLine = match[3];
118
+ pid = match[1].trim() || "";
119
+ ppid = match[2].trim() || "";
120
+ commandLine = match[3].trim() || "";
115
121
  }
116
122
  const commandTokens = this.parseCommandLine(commandLine);
117
123
  if (commandTokens.length > 0) {
@@ -120,7 +126,20 @@ var MCPServerManagerService = class {
120
126
  }
121
127
  let mcpServerDetection;
122
128
  for (const [pid, processData] of processMap) {
123
- if (this.isCommandMatch(processData.commandTokens, pid, processData.ppid)) {
129
+ const commandMatchLinux = this.isCommandMatch(processData.commandTokens, pid, processData.ppid);
130
+ let commandMatchWin32 = false;
131
+ if (platform() === "win32") {
132
+ let commandTokensOnWin32 = processData.commandTokens;
133
+ if (commandTokensOnWin32.length > 0 && commandTokensOnWin32[0].toLowerCase().startsWith("cmd")) {
134
+ commandTokensOnWin32 = commandTokensOnWin32.slice(1);
135
+ while (commandTokensOnWin32.length > 0 && commandTokensOnWin32[0].startsWith("/")) {
136
+ commandTokensOnWin32 = commandTokensOnWin32.slice(1);
137
+ }
138
+ }
139
+ commandMatchWin32 = this.isCommandMatch(commandTokensOnWin32, pid, processData.ppid);
140
+ }
141
+ const commandMatch = commandMatchLinux || commandMatchWin32;
142
+ if (commandMatch) {
124
143
  mcpServerDetection = {
125
144
  pid,
126
145
  commandLine: processData.commandTokens.join(" "),
@@ -167,13 +186,14 @@ var MCPServerManagerService = class {
167
186
  isCommandMatch(commandTokens, pid, ppid) {
168
187
  if (commandTokens.length === 0) return false;
169
188
  const baseCommand = this.getBaseCommand(commandTokens[0]);
170
- if (this.command === "uvx" && baseCommand === "uv") {
189
+ const commandInConfig = this.getBaseCommand(this.command);
190
+ if (commandInConfig === "uvx" && baseCommand === "uv") {
171
191
  return this.matchUvxProcess(commandTokens);
172
192
  }
173
- if (this.command === "npx" && baseCommand === "npm") {
193
+ if (commandInConfig === "npx" && baseCommand === "npm") {
174
194
  return this.matchNpxProcess(commandTokens);
175
195
  }
176
- if (this.command === "uv" && baseCommand === "uv") {
196
+ if (commandInConfig === "uv" && baseCommand === "uv") {
177
197
  return this.matchGenericArgsToArgs(commandTokens);
178
198
  }
179
199
  const commandConfigPythonBase = this.getBaseCommand(this.command);
@@ -198,19 +218,21 @@ var MCPServerManagerService = class {
198
218
  const commandWithoutArgs = commandTokens.slice(1);
199
219
  for (let i = 0; i < this.args.length; i++) {
200
220
  if (i >= commandWithoutArgs.length) return false;
201
- const arg = this.args[i];
202
- const token = commandWithoutArgs[i];
221
+ const arg = this.args[i].toLowerCase();
222
+ const token = commandWithoutArgs[i].toLowerCase();
203
223
  if (arg !== token && !token.includes(arg)) {
204
224
  return false;
205
225
  }
206
226
  }
207
227
  return true;
208
228
  }
209
- // @TODO refactor this to use path.basename or similar
210
- // to extract the base command from the full command path
211
229
  getBaseCommand(fullCommandPath) {
212
- const parts = fullCommandPath.split(/[/\\]/);
213
- return parts[parts.length - 1];
230
+ let baseCommand = path.basename(fullCommandPath);
231
+ if (platform() === "win32") {
232
+ baseCommand = path.basename(fullCommandPath, ".exe");
233
+ }
234
+ baseCommand = baseCommand.toLowerCase();
235
+ return baseCommand;
214
236
  }
215
237
  /*
216
238
  example1:
@@ -289,13 +311,37 @@ var MCPServerManagerService = class {
289
311
  }
290
312
  findMcpServerNameInProcessArguments(commandTokens, mcpServerName) {
291
313
  for (let i = 0; i < commandTokens.length; i++) {
292
- const token = commandTokens[i];
293
- if (mcpServerName === token || token.includes(mcpServerName)) {
314
+ const token = commandTokens[i].toLowerCase();
315
+ const normalizedMcpServerName = mcpServerName.toLowerCase();
316
+ if (normalizedMcpServerName === token || token.includes(normalizedMcpServerName)) {
294
317
  return true;
295
318
  }
296
319
  }
297
320
  return false;
298
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
+ }
299
345
  parseCommandLine(commandLine) {
300
346
  const tokens = [];
301
347
  let current = "";
@@ -354,8 +400,8 @@ var MCPServerManagerService = class {
354
400
  return false;
355
401
  }
356
402
  for (let i = 0; i < argsToMatch.length; i++) {
357
- const commandToken = commandTokens[i + 2];
358
- const expectedArg = argsToMatch[i];
403
+ const commandToken = commandTokens[i + 2].toLowerCase();
404
+ const expectedArg = argsToMatch[i].toLowerCase();
359
405
  if (commandToken !== expectedArg) {
360
406
  return false;
361
407
  }
@@ -365,6 +411,27 @@ var MCPServerManagerService = class {
365
411
  };
366
412
 
367
413
  // src/main.ts
414
+ var osSpecificPaths = {
415
+ claude: [],
416
+ cursor: []
417
+ };
418
+ if (platform2() === "win32") {
419
+ osSpecificPaths["claude"] = [
420
+ { filePath: `${process.env.APPDATA}\\Claude\\claude_desktop_config.json`, type: "global" }
421
+ ];
422
+ osSpecificPaths["cursor"] = [
423
+ { filePath: `${process.env.HOME}\\.cursor\\mcp.json`, type: "global" },
424
+ { filePath: ".cursor\\mcp.json", type: "local" }
425
+ ];
426
+ } else {
427
+ osSpecificPaths["claude"] = [
428
+ { filePath: "~/Library/Application Support/Claude/claude_desktop_config.json", type: "global" }
429
+ ];
430
+ osSpecificPaths["cursor"] = [
431
+ { filePath: "~/.cursor/mcp.json", type: "global" },
432
+ { filePath: ".cursor/mcp.json", type: "local" }
433
+ ];
434
+ }
368
435
  var MCPFiles = class {
369
436
  static {
370
437
  __name(this, "MCPFiles");
@@ -373,17 +440,12 @@ var MCPFiles = class {
373
440
  claude: {
374
441
  name: "claude-desktop",
375
442
  friendlyName: "Claude Desktop",
376
- paths: [
377
- { filePath: "~/Library/Application Support/Claude/claude_desktop_config.json", type: "global" }
378
- ]
443
+ paths: osSpecificPaths["claude"]
379
444
  },
380
445
  cursor: {
381
446
  name: "cursor",
382
447
  friendlyName: "Cursor",
383
- paths: [
384
- { filePath: "~/.cursor/mcp.json", type: "global" },
385
- { filePath: ".cursor/mcp.json", type: "local" }
386
- ]
448
+ paths: osSpecificPaths["cursor"]
387
449
  }
388
450
  };
389
451
  constructor(mcpFilePathGroups) {
@@ -671,18 +733,18 @@ var RenderService = class {
671
733
  };
672
734
 
673
735
  // src/bin/cli.ts
674
- console.log();
675
736
  async function init() {
737
+ console.log();
738
+ console.log("[+] Detecting MCP Server configurations...");
676
739
  const mcpFilesManager = new MCPFiles();
677
740
  const mcpFilesList = await mcpFilesManager.findFiles();
678
741
  if (Object.keys(mcpFilesList).length === 0) {
679
- console.log("No MCP files found.");
680
- return;
742
+ exitWithError("No configuration for MCP Server applications found.");
681
743
  }
682
744
  let pathIndex = 0;
683
745
  for (const groupName of Object.keys(mcpFilesList)) {
684
746
  const group = mcpFilesList[groupName];
685
- if (group.paths.length >= 0) {
747
+ if (group.paths.length > 0) {
686
748
  for (const filePathData of group.paths) {
687
749
  pathIndex++;
688
750
  const filePath = filePathData.filePath.replace("~", process.env.HOME || "");
@@ -704,12 +766,19 @@ async function init() {
704
766
  RenderService.printMcpGroup(pathIndex, mcpGroupData, groupMetadata);
705
767
  RenderService.printMcpServers(mcpServers);
706
768
  }
707
- } else {
708
- console.log("No files found in this group.");
709
769
  }
710
770
  }
771
+ if (pathIndex === 0) {
772
+ exitWithError("No MCP servers found in known configuration files.");
773
+ }
711
774
  }
712
775
  __name(init, "init");
713
776
  init().then(() => {
714
777
  console.log("\n");
715
778
  });
779
+ function exitWithError(message) {
780
+ console.error(`${styleText8(["red"], "\u25CF")} ${message}
781
+ `);
782
+ process.exit(1);
783
+ }
784
+ __name(exitWithError, "exitWithError");
package/dist/main.cjs CHANGED
@@ -35,6 +35,7 @@ __export(main_exports, {
35
35
  });
36
36
  module.exports = __toCommonJS(main_exports);
37
37
  var import_promises2 = __toESM(require("fs/promises"), 1);
38
+ var import_node_os2 = require("os");
38
39
 
39
40
  // src/services/mcp-config-linter-service.ts
40
41
  var import_promises = __toESM(require("fs/promises"), 1);
@@ -76,6 +77,7 @@ var MCPConfigLinterService = class {
76
77
  };
77
78
 
78
79
  // src/services/mcp-server-manager-service.ts
80
+ var import_node_path = __toESM(require("path"), 1);
79
81
  var import_node_child_process = require("child_process");
80
82
  var import_node_os = require("os");
81
83
  var MCPServerManagerService = class {
@@ -114,7 +116,7 @@ var MCPServerManagerService = class {
114
116
  try {
115
117
  let psOutput;
116
118
  if ((0, import_node_os.platform)() === "win32") {
117
- psOutput = (0, import_node_child_process.execSync)("wmic process get ProcessId,ParentProcessId,CommandLine /format:csv", {
119
+ psOutput = (0, import_node_child_process.execSync)('powershell -Command "Get-CimInstance -ClassName Win32_Process | Select-Object ProcessId,Name,CommandLine,ParentProcessId | ConvertTo-Csv -NoTypeInformation"', {
118
120
  encoding: "utf8",
119
121
  timeout: 5e3
120
122
  });
@@ -132,17 +134,18 @@ var MCPServerManagerService = class {
132
134
  let ppid;
133
135
  let commandLine;
134
136
  if ((0, import_node_os.platform)() === "win32") {
135
- const parts = processLine.split(",");
137
+ if (processLine.startsWith('"ProcessId"') || processLine.startsWith("ProcessId")) continue;
138
+ const parts = this.parseCSVLine(processLine);
136
139
  if (parts.length < 4) continue;
137
- commandLine = parts[1] || "";
138
- ppid = parts[2] || "";
139
- pid = parts[3] || "";
140
+ pid = parts[0].trim() || "";
141
+ commandLine = parts[2].trim() || "";
142
+ ppid = parts[3].trim() || "";
140
143
  } else {
141
144
  const match = processLine.trim().match(/^\s*(\d+)\s+(\d+)\s+(.+)$/);
142
145
  if (!match) continue;
143
- pid = match[1];
144
- ppid = match[2];
145
- commandLine = match[3];
146
+ pid = match[1].trim() || "";
147
+ ppid = match[2].trim() || "";
148
+ commandLine = match[3].trim() || "";
146
149
  }
147
150
  const commandTokens = this.parseCommandLine(commandLine);
148
151
  if (commandTokens.length > 0) {
@@ -151,7 +154,20 @@ var MCPServerManagerService = class {
151
154
  }
152
155
  let mcpServerDetection;
153
156
  for (const [pid, processData] of processMap) {
154
- if (this.isCommandMatch(processData.commandTokens, pid, processData.ppid)) {
157
+ const commandMatchLinux = this.isCommandMatch(processData.commandTokens, pid, processData.ppid);
158
+ let commandMatchWin32 = false;
159
+ if ((0, import_node_os.platform)() === "win32") {
160
+ let commandTokensOnWin32 = processData.commandTokens;
161
+ if (commandTokensOnWin32.length > 0 && commandTokensOnWin32[0].toLowerCase().startsWith("cmd")) {
162
+ commandTokensOnWin32 = commandTokensOnWin32.slice(1);
163
+ while (commandTokensOnWin32.length > 0 && commandTokensOnWin32[0].startsWith("/")) {
164
+ commandTokensOnWin32 = commandTokensOnWin32.slice(1);
165
+ }
166
+ }
167
+ commandMatchWin32 = this.isCommandMatch(commandTokensOnWin32, pid, processData.ppid);
168
+ }
169
+ const commandMatch = commandMatchLinux || commandMatchWin32;
170
+ if (commandMatch) {
155
171
  mcpServerDetection = {
156
172
  pid,
157
173
  commandLine: processData.commandTokens.join(" "),
@@ -198,13 +214,14 @@ var MCPServerManagerService = class {
198
214
  isCommandMatch(commandTokens, pid, ppid) {
199
215
  if (commandTokens.length === 0) return false;
200
216
  const baseCommand = this.getBaseCommand(commandTokens[0]);
201
- if (this.command === "uvx" && baseCommand === "uv") {
217
+ const commandInConfig = this.getBaseCommand(this.command);
218
+ if (commandInConfig === "uvx" && baseCommand === "uv") {
202
219
  return this.matchUvxProcess(commandTokens);
203
220
  }
204
- if (this.command === "npx" && baseCommand === "npm") {
221
+ if (commandInConfig === "npx" && baseCommand === "npm") {
205
222
  return this.matchNpxProcess(commandTokens);
206
223
  }
207
- if (this.command === "uv" && baseCommand === "uv") {
224
+ if (commandInConfig === "uv" && baseCommand === "uv") {
208
225
  return this.matchGenericArgsToArgs(commandTokens);
209
226
  }
210
227
  const commandConfigPythonBase = this.getBaseCommand(this.command);
@@ -229,19 +246,21 @@ var MCPServerManagerService = class {
229
246
  const commandWithoutArgs = commandTokens.slice(1);
230
247
  for (let i = 0; i < this.args.length; i++) {
231
248
  if (i >= commandWithoutArgs.length) return false;
232
- const arg = this.args[i];
233
- const token = commandWithoutArgs[i];
249
+ const arg = this.args[i].toLowerCase();
250
+ const token = commandWithoutArgs[i].toLowerCase();
234
251
  if (arg !== token && !token.includes(arg)) {
235
252
  return false;
236
253
  }
237
254
  }
238
255
  return true;
239
256
  }
240
- // @TODO refactor this to use path.basename or similar
241
- // to extract the base command from the full command path
242
257
  getBaseCommand(fullCommandPath) {
243
- const parts = fullCommandPath.split(/[/\\]/);
244
- return parts[parts.length - 1];
258
+ let baseCommand = import_node_path.default.basename(fullCommandPath);
259
+ if ((0, import_node_os.platform)() === "win32") {
260
+ baseCommand = import_node_path.default.basename(fullCommandPath, ".exe");
261
+ }
262
+ baseCommand = baseCommand.toLowerCase();
263
+ return baseCommand;
245
264
  }
246
265
  /*
247
266
  example1:
@@ -320,13 +339,37 @@ var MCPServerManagerService = class {
320
339
  }
321
340
  findMcpServerNameInProcessArguments(commandTokens, mcpServerName) {
322
341
  for (let i = 0; i < commandTokens.length; i++) {
323
- const token = commandTokens[i];
324
- if (mcpServerName === token || token.includes(mcpServerName)) {
342
+ const token = commandTokens[i].toLowerCase();
343
+ const normalizedMcpServerName = mcpServerName.toLowerCase();
344
+ if (normalizedMcpServerName === token || token.includes(normalizedMcpServerName)) {
325
345
  return true;
326
346
  }
327
347
  }
328
348
  return false;
329
349
  }
350
+ parseCSVLine(line) {
351
+ const result = [];
352
+ let current = "";
353
+ let inQuotes = false;
354
+ for (let i = 0; i < line.length; i++) {
355
+ const char = line[i];
356
+ if (char === '"') {
357
+ if (inQuotes && line[i + 1] === '"') {
358
+ current += '"';
359
+ i++;
360
+ } else {
361
+ inQuotes = !inQuotes;
362
+ }
363
+ } else if (char === "," && !inQuotes) {
364
+ result.push(current);
365
+ current = "";
366
+ } else {
367
+ current += char;
368
+ }
369
+ }
370
+ result.push(current);
371
+ return result;
372
+ }
330
373
  parseCommandLine(commandLine) {
331
374
  const tokens = [];
332
375
  let current = "";
@@ -385,8 +428,8 @@ var MCPServerManagerService = class {
385
428
  return false;
386
429
  }
387
430
  for (let i = 0; i < argsToMatch.length; i++) {
388
- const commandToken = commandTokens[i + 2];
389
- const expectedArg = argsToMatch[i];
431
+ const commandToken = commandTokens[i + 2].toLowerCase();
432
+ const expectedArg = argsToMatch[i].toLowerCase();
390
433
  if (commandToken !== expectedArg) {
391
434
  return false;
392
435
  }
@@ -396,6 +439,27 @@ var MCPServerManagerService = class {
396
439
  };
397
440
 
398
441
  // src/main.ts
442
+ var osSpecificPaths = {
443
+ claude: [],
444
+ cursor: []
445
+ };
446
+ if ((0, import_node_os2.platform)() === "win32") {
447
+ osSpecificPaths["claude"] = [
448
+ { filePath: `${process.env.APPDATA}\\Claude\\claude_desktop_config.json`, type: "global" }
449
+ ];
450
+ osSpecificPaths["cursor"] = [
451
+ { filePath: `${process.env.HOME}\\.cursor\\mcp.json`, type: "global" },
452
+ { filePath: ".cursor\\mcp.json", type: "local" }
453
+ ];
454
+ } else {
455
+ osSpecificPaths["claude"] = [
456
+ { filePath: "~/Library/Application Support/Claude/claude_desktop_config.json", type: "global" }
457
+ ];
458
+ osSpecificPaths["cursor"] = [
459
+ { filePath: "~/.cursor/mcp.json", type: "global" },
460
+ { filePath: ".cursor/mcp.json", type: "local" }
461
+ ];
462
+ }
399
463
  var MCPFiles = class {
400
464
  static {
401
465
  __name(this, "MCPFiles");
@@ -404,17 +468,12 @@ var MCPFiles = class {
404
468
  claude: {
405
469
  name: "claude-desktop",
406
470
  friendlyName: "Claude Desktop",
407
- paths: [
408
- { filePath: "~/Library/Application Support/Claude/claude_desktop_config.json", type: "global" }
409
- ]
471
+ paths: osSpecificPaths["claude"]
410
472
  },
411
473
  cursor: {
412
474
  name: "cursor",
413
475
  friendlyName: "Cursor",
414
- paths: [
415
- { filePath: "~/.cursor/mcp.json", type: "global" },
416
- { filePath: ".cursor/mcp.json", type: "local" }
417
- ]
476
+ paths: osSpecificPaths["cursor"]
418
477
  }
419
478
  };
420
479
  constructor(mcpFilePathGroups) {
package/dist/main.mjs CHANGED
@@ -3,6 +3,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
3
3
 
4
4
  // src/main.ts
5
5
  import fs2 from "fs/promises";
6
+ import { platform as platform2 } from "os";
6
7
 
7
8
  // src/services/mcp-config-linter-service.ts
8
9
  import fs from "fs/promises";
@@ -44,6 +45,7 @@ var MCPConfigLinterService = class {
44
45
  };
45
46
 
46
47
  // src/services/mcp-server-manager-service.ts
48
+ import path from "path";
47
49
  import { execSync } from "child_process";
48
50
  import { platform } from "os";
49
51
  var MCPServerManagerService = class {
@@ -82,7 +84,7 @@ var MCPServerManagerService = class {
82
84
  try {
83
85
  let psOutput;
84
86
  if (platform() === "win32") {
85
- psOutput = execSync("wmic process get ProcessId,ParentProcessId,CommandLine /format:csv", {
87
+ psOutput = execSync('powershell -Command "Get-CimInstance -ClassName Win32_Process | Select-Object ProcessId,Name,CommandLine,ParentProcessId | ConvertTo-Csv -NoTypeInformation"', {
86
88
  encoding: "utf8",
87
89
  timeout: 5e3
88
90
  });
@@ -100,17 +102,18 @@ var MCPServerManagerService = class {
100
102
  let ppid;
101
103
  let commandLine;
102
104
  if (platform() === "win32") {
103
- const parts = processLine.split(",");
105
+ if (processLine.startsWith('"ProcessId"') || processLine.startsWith("ProcessId")) continue;
106
+ const parts = this.parseCSVLine(processLine);
104
107
  if (parts.length < 4) continue;
105
- commandLine = parts[1] || "";
106
- ppid = parts[2] || "";
107
- pid = parts[3] || "";
108
+ pid = parts[0].trim() || "";
109
+ commandLine = parts[2].trim() || "";
110
+ ppid = parts[3].trim() || "";
108
111
  } else {
109
112
  const match = processLine.trim().match(/^\s*(\d+)\s+(\d+)\s+(.+)$/);
110
113
  if (!match) continue;
111
- pid = match[1];
112
- ppid = match[2];
113
- commandLine = match[3];
114
+ pid = match[1].trim() || "";
115
+ ppid = match[2].trim() || "";
116
+ commandLine = match[3].trim() || "";
114
117
  }
115
118
  const commandTokens = this.parseCommandLine(commandLine);
116
119
  if (commandTokens.length > 0) {
@@ -119,7 +122,20 @@ var MCPServerManagerService = class {
119
122
  }
120
123
  let mcpServerDetection;
121
124
  for (const [pid, processData] of processMap) {
122
- if (this.isCommandMatch(processData.commandTokens, pid, processData.ppid)) {
125
+ const commandMatchLinux = this.isCommandMatch(processData.commandTokens, pid, processData.ppid);
126
+ let commandMatchWin32 = false;
127
+ if (platform() === "win32") {
128
+ let commandTokensOnWin32 = processData.commandTokens;
129
+ if (commandTokensOnWin32.length > 0 && commandTokensOnWin32[0].toLowerCase().startsWith("cmd")) {
130
+ commandTokensOnWin32 = commandTokensOnWin32.slice(1);
131
+ while (commandTokensOnWin32.length > 0 && commandTokensOnWin32[0].startsWith("/")) {
132
+ commandTokensOnWin32 = commandTokensOnWin32.slice(1);
133
+ }
134
+ }
135
+ commandMatchWin32 = this.isCommandMatch(commandTokensOnWin32, pid, processData.ppid);
136
+ }
137
+ const commandMatch = commandMatchLinux || commandMatchWin32;
138
+ if (commandMatch) {
123
139
  mcpServerDetection = {
124
140
  pid,
125
141
  commandLine: processData.commandTokens.join(" "),
@@ -166,13 +182,14 @@ var MCPServerManagerService = class {
166
182
  isCommandMatch(commandTokens, pid, ppid) {
167
183
  if (commandTokens.length === 0) return false;
168
184
  const baseCommand = this.getBaseCommand(commandTokens[0]);
169
- if (this.command === "uvx" && baseCommand === "uv") {
185
+ const commandInConfig = this.getBaseCommand(this.command);
186
+ if (commandInConfig === "uvx" && baseCommand === "uv") {
170
187
  return this.matchUvxProcess(commandTokens);
171
188
  }
172
- if (this.command === "npx" && baseCommand === "npm") {
189
+ if (commandInConfig === "npx" && baseCommand === "npm") {
173
190
  return this.matchNpxProcess(commandTokens);
174
191
  }
175
- if (this.command === "uv" && baseCommand === "uv") {
192
+ if (commandInConfig === "uv" && baseCommand === "uv") {
176
193
  return this.matchGenericArgsToArgs(commandTokens);
177
194
  }
178
195
  const commandConfigPythonBase = this.getBaseCommand(this.command);
@@ -197,19 +214,21 @@ var MCPServerManagerService = class {
197
214
  const commandWithoutArgs = commandTokens.slice(1);
198
215
  for (let i = 0; i < this.args.length; i++) {
199
216
  if (i >= commandWithoutArgs.length) return false;
200
- const arg = this.args[i];
201
- const token = commandWithoutArgs[i];
217
+ const arg = this.args[i].toLowerCase();
218
+ const token = commandWithoutArgs[i].toLowerCase();
202
219
  if (arg !== token && !token.includes(arg)) {
203
220
  return false;
204
221
  }
205
222
  }
206
223
  return true;
207
224
  }
208
- // @TODO refactor this to use path.basename or similar
209
- // to extract the base command from the full command path
210
225
  getBaseCommand(fullCommandPath) {
211
- const parts = fullCommandPath.split(/[/\\]/);
212
- return parts[parts.length - 1];
226
+ let baseCommand = path.basename(fullCommandPath);
227
+ if (platform() === "win32") {
228
+ baseCommand = path.basename(fullCommandPath, ".exe");
229
+ }
230
+ baseCommand = baseCommand.toLowerCase();
231
+ return baseCommand;
213
232
  }
214
233
  /*
215
234
  example1:
@@ -288,13 +307,37 @@ var MCPServerManagerService = class {
288
307
  }
289
308
  findMcpServerNameInProcessArguments(commandTokens, mcpServerName) {
290
309
  for (let i = 0; i < commandTokens.length; i++) {
291
- const token = commandTokens[i];
292
- if (mcpServerName === token || token.includes(mcpServerName)) {
310
+ const token = commandTokens[i].toLowerCase();
311
+ const normalizedMcpServerName = mcpServerName.toLowerCase();
312
+ if (normalizedMcpServerName === token || token.includes(normalizedMcpServerName)) {
293
313
  return true;
294
314
  }
295
315
  }
296
316
  return false;
297
317
  }
318
+ parseCSVLine(line) {
319
+ const result = [];
320
+ let current = "";
321
+ let inQuotes = false;
322
+ for (let i = 0; i < line.length; i++) {
323
+ const char = line[i];
324
+ if (char === '"') {
325
+ if (inQuotes && line[i + 1] === '"') {
326
+ current += '"';
327
+ i++;
328
+ } else {
329
+ inQuotes = !inQuotes;
330
+ }
331
+ } else if (char === "," && !inQuotes) {
332
+ result.push(current);
333
+ current = "";
334
+ } else {
335
+ current += char;
336
+ }
337
+ }
338
+ result.push(current);
339
+ return result;
340
+ }
298
341
  parseCommandLine(commandLine) {
299
342
  const tokens = [];
300
343
  let current = "";
@@ -353,8 +396,8 @@ var MCPServerManagerService = class {
353
396
  return false;
354
397
  }
355
398
  for (let i = 0; i < argsToMatch.length; i++) {
356
- const commandToken = commandTokens[i + 2];
357
- const expectedArg = argsToMatch[i];
399
+ const commandToken = commandTokens[i + 2].toLowerCase();
400
+ const expectedArg = argsToMatch[i].toLowerCase();
358
401
  if (commandToken !== expectedArg) {
359
402
  return false;
360
403
  }
@@ -364,6 +407,27 @@ var MCPServerManagerService = class {
364
407
  };
365
408
 
366
409
  // src/main.ts
410
+ var osSpecificPaths = {
411
+ claude: [],
412
+ cursor: []
413
+ };
414
+ if (platform2() === "win32") {
415
+ osSpecificPaths["claude"] = [
416
+ { filePath: `${process.env.APPDATA}\\Claude\\claude_desktop_config.json`, type: "global" }
417
+ ];
418
+ osSpecificPaths["cursor"] = [
419
+ { filePath: `${process.env.HOME}\\.cursor\\mcp.json`, type: "global" },
420
+ { filePath: ".cursor\\mcp.json", type: "local" }
421
+ ];
422
+ } else {
423
+ osSpecificPaths["claude"] = [
424
+ { filePath: "~/Library/Application Support/Claude/claude_desktop_config.json", type: "global" }
425
+ ];
426
+ osSpecificPaths["cursor"] = [
427
+ { filePath: "~/.cursor/mcp.json", type: "global" },
428
+ { filePath: ".cursor/mcp.json", type: "local" }
429
+ ];
430
+ }
367
431
  var MCPFiles = class {
368
432
  static {
369
433
  __name(this, "MCPFiles");
@@ -372,17 +436,12 @@ var MCPFiles = class {
372
436
  claude: {
373
437
  name: "claude-desktop",
374
438
  friendlyName: "Claude Desktop",
375
- paths: [
376
- { filePath: "~/Library/Application Support/Claude/claude_desktop_config.json", type: "global" }
377
- ]
439
+ paths: osSpecificPaths["claude"]
378
440
  },
379
441
  cursor: {
380
442
  name: "cursor",
381
443
  friendlyName: "Cursor",
382
- paths: [
383
- { filePath: "~/.cursor/mcp.json", type: "global" },
384
- { filePath: ".cursor/mcp.json", type: "local" }
385
- ]
444
+ paths: osSpecificPaths["cursor"]
386
445
  }
387
446
  };
388
447
  constructor(mcpFilePathGroups) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ls-mcp",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "list and detect MCP servers and configurations",
5
5
  "types": "dist/main.d.ts",
6
6
  "type": "module",
package/src/bin/cli.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // import { debuglog } from 'node:util'
4
+ import { styleText } from 'node:util'
4
5
  import { MCPFiles } from '../main.ts'
5
6
  import { RenderService } from '../services/render-service.ts'
6
7
 
@@ -13,26 +14,26 @@ interface MCPServerInfo {
13
14
  status?: 'running' | 'stopped'
14
15
  }
15
16
 
16
- // Start the CLI with a new line for better readability
17
- console.log()
18
-
19
17
  // @TODO add debug logging
20
18
  // const debug = debuglog('ls-mcp')
21
19
 
22
20
  async function init () {
21
+ // Start the CLI with a new line for better readability
22
+ console.log()
23
+ console.log('[+] Detecting MCP Server configurations...')
24
+
23
25
  const mcpFilesManager = new MCPFiles()
24
26
  const mcpFilesList = await mcpFilesManager.findFiles()
25
27
 
26
28
  if (Object.keys(mcpFilesList).length === 0) {
27
- console.log('No MCP files found.')
28
- return
29
+ exitWithError('No configuration for MCP Server applications found.')
29
30
  }
30
31
 
31
32
  let pathIndex = 0
32
33
  for (const groupName of Object.keys(mcpFilesList)) {
33
34
  const group = mcpFilesList[groupName]
34
35
 
35
- if (group.paths.length >= 0) {
36
+ if (group.paths.length > 0) {
36
37
  // handle file path list of MCP Servers
37
38
  for (const filePathData of group.paths) {
38
39
  pathIndex++
@@ -60,12 +61,19 @@ async function init () {
60
61
  RenderService.printMcpGroup(pathIndex, mcpGroupData, groupMetadata)
61
62
  RenderService.printMcpServers(mcpServers)
62
63
  }
63
- } else {
64
- console.log('No files found in this group.')
65
64
  }
66
65
  }
66
+
67
+ if (pathIndex === 0) {
68
+ exitWithError('No MCP servers found in known configuration files.')
69
+ }
67
70
  }
68
71
 
69
72
  init().then(() => {
70
73
  console.log('\n')
71
74
  })
75
+
76
+ function exitWithError (message: string) {
77
+ console.error(`${styleText(['red'], '●')} ${message}\n`)
78
+ process.exit(1)
79
+ }
package/src/main.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import fs from 'node:fs/promises'
2
+ import { platform } from 'node:os'
2
3
  import { MCPConfigLinterService } from './services/mcp-config-linter-service.ts'
3
4
  import { MCPServerManagerService } from './services/mcp-server-manager-service.ts'
4
5
 
@@ -39,22 +40,40 @@ interface MCPFileGroupsResult {
39
40
  type MCPFilePathGroupsRecord = Record<string, MCPFileGroups>
40
41
  type MCPFileGroupsResultRecord = Record<string, MCPFileGroupsResult>
41
42
 
43
+ const osSpecificPaths: { [key: string]: MCPFilePath[] } = {
44
+ claude: [],
45
+ cursor: []
46
+ }
47
+
48
+ if (platform() === 'win32') {
49
+ osSpecificPaths['claude'] = [
50
+ { filePath: `${process.env.APPDATA}\\Claude\\claude_desktop_config.json`, type: 'global' }
51
+ ]
52
+ osSpecificPaths['cursor'] = [
53
+ { filePath: `${process.env.HOME}\\.cursor\\mcp.json`, type: 'global' },
54
+ { filePath: '.cursor\\mcp.json', type: 'local' }
55
+ ]
56
+ } else {
57
+ osSpecificPaths['claude'] = [
58
+ { filePath: '~/Library/Application Support/Claude/claude_desktop_config.json', type: 'global' }
59
+ ]
60
+ osSpecificPaths['cursor'] = [
61
+ { filePath: '~/.cursor/mcp.json', type: 'global' },
62
+ { filePath: '.cursor/mcp.json', type: 'local' }
63
+ ]
64
+ }
65
+
42
66
  export class MCPFiles {
43
67
  private mcpFilePathGroups: MCPFilePathGroupsRecord = {
44
68
  claude: {
45
69
  name: 'claude-desktop',
46
70
  friendlyName: 'Claude Desktop',
47
- paths: [
48
- { filePath: '~/Library/Application Support/Claude/claude_desktop_config.json', type: 'global' },
49
- ]
71
+ paths: osSpecificPaths['claude']
50
72
  },
51
73
  cursor: {
52
74
  name: 'cursor',
53
75
  friendlyName: 'Cursor',
54
- paths: [
55
- { filePath: '~/.cursor/mcp.json', type: 'global' },
56
- { filePath: '.cursor/mcp.json', type: 'local' },
57
- ]
76
+ paths: osSpecificPaths['cursor']
58
77
  }
59
78
  }
60
79
 
@@ -1,3 +1,4 @@
1
+ import path from 'node:path'
1
2
  import { execSync } from 'node:child_process'
2
3
  import { platform } from 'node:os'
3
4
 
@@ -59,8 +60,8 @@ export class MCPServerManagerService {
59
60
  let psOutput: string
60
61
 
61
62
  if (platform() === 'win32') {
62
- // Windows: Use wmic to get process info
63
- psOutput = execSync('wmic process get ProcessId,ParentProcessId,CommandLine /format:csv', {
63
+ // Windows: Use PowerShell Get-CimInstance to get process info
64
+ psOutput = execSync('powershell -Command "Get-CimInstance -ClassName Win32_Process | Select-Object ProcessId,Name,CommandLine,ParentProcessId | ConvertTo-Csv -NoTypeInformation"', {
64
65
  encoding: 'utf8',
65
66
  timeout: 5000
66
67
  })
@@ -83,19 +84,23 @@ export class MCPServerManagerService {
83
84
  let commandLine: string
84
85
 
85
86
  if (platform() === 'win32') {
86
- // Parse Windows CSV format: Node,CommandLine,ParentProcessId,ProcessId
87
- const parts = processLine.split(',')
87
+ // Parse Windows CSV format: ProcessId,Name,CommandLine,ParentProcessId
88
+ // Skip header line
89
+ if (processLine.startsWith('"ProcessId"') || processLine.startsWith('ProcessId')) continue
90
+
91
+ const parts = this.parseCSVLine(processLine)
88
92
  if (parts.length < 4) continue
89
- commandLine = parts[1] || ''
90
- ppid = parts[2] || ''
91
- pid = parts[3] || ''
93
+ pid = parts[0].trim() || ''
94
+ // Skip Name (parts[1])
95
+ commandLine = parts[2].trim() || ''
96
+ ppid = parts[3].trim() || ''
92
97
  } else {
93
98
  // Parse Unix ps output: PID PPID COMMAND
94
99
  const match = processLine.trim().match(/^\s*(\d+)\s+(\d+)\s+(.+)$/)
95
100
  if (!match) continue
96
- pid = match[1]
97
- ppid = match[2]
98
- commandLine = match[3]
101
+ pid = match[1].trim() || ''
102
+ ppid = match[2].trim() || ''
103
+ commandLine = match[3].trim() || ''
99
104
  }
100
105
 
101
106
  // Parse command line and store in map
@@ -107,8 +112,34 @@ export class MCPServerManagerService {
107
112
 
108
113
  // Then iterate the map to check for matches
109
114
  let mcpServerDetection: MatchedProcess | undefined
115
+
110
116
  for (const [pid, processData] of processMap) {
111
- if (this.isCommandMatch(processData.commandTokens, pid, processData.ppid)) {
117
+ const commandMatchLinux = this.isCommandMatch(processData.commandTokens, pid, processData.ppid)
118
+ let commandMatchWin32 = false
119
+ if (platform() === 'win32') {
120
+ // for Windows, we need to change commandTokens to also match another pattern
121
+ // where the command starts with `cmd` then follows potentially several command-line
122
+ // flags like /c /d and then the actual command.
123
+ // This is because Claude Desktop on Windows automatically starts MCP Servers like that
124
+ // even if the command specified in the MCP config is just `uvx` or `npx`.
125
+
126
+ let commandTokensOnWin32 = processData.commandTokens
127
+ if (commandTokensOnWin32.length > 0 && commandTokensOnWin32[0].toLowerCase().startsWith('cmd')) {
128
+ // If the first token is 'cmd', we need to skip it and check the next tokens
129
+ commandTokensOnWin32 = commandTokensOnWin32.slice(1)
130
+
131
+ // Skip any additional flags like /c, /d, etc.
132
+ while (commandTokensOnWin32.length > 0 && commandTokensOnWin32[0].startsWith('/')) {
133
+ commandTokensOnWin32 = commandTokensOnWin32.slice(1)
134
+ }
135
+ }
136
+
137
+ commandMatchWin32 = this.isCommandMatch(commandTokensOnWin32, pid, processData.ppid)
138
+ }
139
+
140
+ const commandMatch = commandMatchLinux || commandMatchWin32
141
+
142
+ if (commandMatch) {
112
143
  mcpServerDetection = {
113
144
  pid,
114
145
  commandLine: processData.commandTokens.join(' '),
@@ -170,13 +201,15 @@ export class MCPServerManagerService {
170
201
  // e.g. "/usr/homebrew/bin/uv" extracted to "uv"
171
202
  const baseCommand = this.getBaseCommand(commandTokens[0])
172
203
 
204
+ const commandInConfig: string = this.getBaseCommand(this.command)
205
+
173
206
  // Map configured command to actual process command for uvx case
174
- if (this.command === 'uvx' && baseCommand === 'uv') {
207
+ if (commandInConfig === 'uvx' && baseCommand === 'uv') {
175
208
  return this.matchUvxProcess(commandTokens)
176
209
  }
177
210
 
178
211
  // Map configured command to actual process command for npx case
179
- if (this.command === 'npx' && baseCommand === 'npm') {
212
+ if (commandInConfig === 'npx' && baseCommand === 'npm') {
180
213
  return this.matchNpxProcess(commandTokens)
181
214
  }
182
215
 
@@ -192,7 +225,7 @@ export class MCPServerManagerService {
192
225
  ]
193
226
  },
194
227
  */
195
- if (this.command === 'uv' && baseCommand === 'uv') {
228
+ if (commandInConfig === 'uv' && baseCommand === 'uv') {
196
229
  return this.matchGenericArgsToArgs(commandTokens)
197
230
  }
198
231
 
@@ -241,8 +274,8 @@ export class MCPServerManagerService {
241
274
  // If we reach the end of command tokens, we cannot match
242
275
  if (i >= commandWithoutArgs.length) return false
243
276
 
244
- const arg = this.args[i]
245
- const token = commandWithoutArgs[i]
277
+ const arg = this.args[i].toLowerCase()
278
+ const token = commandWithoutArgs[i].toLowerCase()
246
279
 
247
280
  // Check if the argument matches the command token
248
281
  if (arg !== token && !token.includes(arg)) {
@@ -254,12 +287,17 @@ export class MCPServerManagerService {
254
287
  return true
255
288
  }
256
289
 
257
- // @TODO refactor this to use path.basename or similar
258
- // to extract the base command from the full command path
259
290
  private getBaseCommand (fullCommandPath: string): string {
260
291
  // Extract base command name from full path
261
- const parts = fullCommandPath.split(/[/\\]/)
262
- return parts[parts.length - 1]
292
+ let baseCommand = path.basename(fullCommandPath)
293
+ // Detect if we're on Windows and if so we omit the .exe extension
294
+ if (platform() === 'win32') {
295
+ baseCommand = path.basename(fullCommandPath, '.exe')
296
+ }
297
+
298
+ // In any case, we want to return the base command as lowercase
299
+ baseCommand = baseCommand.toLowerCase()
300
+ return baseCommand
263
301
  }
264
302
 
265
303
  /*
@@ -358,8 +396,10 @@ export class MCPServerManagerService {
358
396
  private findMcpServerNameInProcessArguments (commandTokens: string[], mcpServerName: string): boolean {
359
397
  // Check if the command tokens contain the MCP server name
360
398
  for (let i = 0; i < commandTokens.length; i++) {
361
- const token = commandTokens[i]
362
- if (mcpServerName === token || token.includes(mcpServerName)) {
399
+ const token = commandTokens[i].toLowerCase()
400
+ const normalizedMcpServerName = mcpServerName.toLowerCase()
401
+
402
+ if (normalizedMcpServerName === token || token.includes(normalizedMcpServerName)) {
363
403
  // If we find the MCP server name in the command tokens, we consider it a match
364
404
  return true
365
405
  }
@@ -367,6 +407,35 @@ export class MCPServerManagerService {
367
407
  return false
368
408
  }
369
409
 
410
+ private parseCSVLine (line: string): string[] {
411
+ const result: string[] = []
412
+ let current = ''
413
+ let inQuotes = false
414
+
415
+ for (let i = 0; i < line.length; i++) {
416
+ const char = line[i]
417
+
418
+ if (char === '"') {
419
+ if (inQuotes && line[i + 1] === '"') {
420
+ // Escaped quote
421
+ current += '"'
422
+ i++ // Skip next quote
423
+ } else {
424
+ // Toggle quote state
425
+ inQuotes = !inQuotes
426
+ }
427
+ } else if (char === ',' && !inQuotes) {
428
+ result.push(current)
429
+ current = ''
430
+ } else {
431
+ current += char
432
+ }
433
+ }
434
+
435
+ result.push(current)
436
+ return result
437
+ }
438
+
370
439
  private parseCommandLine (commandLine: string): string[] {
371
440
  const tokens: string[] = []
372
441
  let current = ''
@@ -447,8 +516,9 @@ export class MCPServerManagerService {
447
516
 
448
517
  // Compare each argument starting from position 2 in commandTokens
449
518
  for (let i = 0; i < argsToMatch.length; i++) {
450
- const commandToken = commandTokens[i + 2] // Start from index 2 (after "npm exec")
451
- const expectedArg = argsToMatch[i]
519
+ // Start from index 2 (after "npm exec")
520
+ const commandToken = commandTokens[i + 2].toLowerCase()
521
+ const expectedArg = argsToMatch[i].toLowerCase()
452
522
 
453
523
  if (commandToken !== expectedArg) {
454
524
  return false
@@ -180,9 +180,6 @@ export class RenderService {
180
180
  const leftPadding = index === 0 ? leftPaddingGroupLead : leftPaddingGroupData
181
181
  console.log(leftPadding + dataRow)
182
182
  }
183
-
184
- // Print bottom separator
185
- // console.log('')
186
183
  }
187
184
 
188
185
  // draws progress bar components like this