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/main.cjs CHANGED
@@ -76,6 +76,8 @@ var MCPConfigLinterService = class {
76
76
  };
77
77
 
78
78
  // src/services/mcp-server-manager-service.ts
79
+ var import_node_child_process = require("child_process");
80
+ var import_node_os = require("os");
79
81
  var MCPServerManagerService = class {
80
82
  static {
81
83
  __name(this, "MCPServerManagerService");
@@ -109,7 +111,311 @@ var MCPServerManagerService = class {
109
111
  return this.env;
110
112
  }
111
113
  isRunning() {
112
- return this.running;
114
+ try {
115
+ let psOutput;
116
+ if ((0, import_node_os.platform)() === "win32") {
117
+ psOutput = (0, import_node_child_process.execSync)('powershell -Command "Get-CimInstance -ClassName Win32_Process | Select-Object ProcessId,Name,CommandLine,ParentProcessId | ConvertTo-Csv -NoTypeInformation"', {
118
+ encoding: "utf8",
119
+ timeout: 5e3
120
+ });
121
+ } else {
122
+ psOutput = (0, import_node_child_process.execSync)("ps -eao pid,ppid,args", {
123
+ encoding: "utf8",
124
+ timeout: 5e3
125
+ });
126
+ }
127
+ const processMap = /* @__PURE__ */ new Map();
128
+ const processes = psOutput.trim().split("\n");
129
+ for (const processLine of processes) {
130
+ if (!processLine.trim()) continue;
131
+ let pid;
132
+ let ppid;
133
+ let commandLine;
134
+ if ((0, import_node_os.platform)() === "win32") {
135
+ if (processLine.startsWith('"ProcessId"') || processLine.startsWith("ProcessId")) continue;
136
+ const parts = this.parseCSVLine(processLine);
137
+ if (parts.length < 4) continue;
138
+ pid = parts[0] || "";
139
+ commandLine = parts[2] || "";
140
+ ppid = parts[3] || "";
141
+ } else {
142
+ const match = processLine.trim().match(/^\s*(\d+)\s+(\d+)\s+(.+)$/);
143
+ if (!match) continue;
144
+ pid = match[1];
145
+ ppid = match[2];
146
+ commandLine = match[3];
147
+ }
148
+ const commandTokens = this.parseCommandLine(commandLine);
149
+ if (commandTokens.length > 0) {
150
+ processMap.set(pid, { ppid, commandTokens });
151
+ }
152
+ }
153
+ let mcpServerDetection;
154
+ for (const [pid, processData] of processMap) {
155
+ if (this.isCommandMatch(processData.commandTokens, pid, processData.ppid)) {
156
+ mcpServerDetection = {
157
+ pid,
158
+ commandLine: processData.commandTokens.join(" "),
159
+ ppid: processData.ppid
160
+ };
161
+ const parentProcess = processMap.get(processData.ppid);
162
+ if (parentProcess) {
163
+ const { estimatedVendor, estimatedProduct } = this.getVendorFromCommand(parentProcess.commandTokens) || {};
164
+ if (estimatedProduct || estimatedVendor) {
165
+ mcpServerDetection = {
166
+ ...mcpServerDetection,
167
+ parentCommandLine: parentProcess.commandTokens.join(" "),
168
+ estimatedVendor,
169
+ estimatedProduct
170
+ };
171
+ return mcpServerDetection;
172
+ }
173
+ }
174
+ }
175
+ }
176
+ if (mcpServerDetection) {
177
+ return mcpServerDetection;
178
+ }
179
+ return false;
180
+ } catch (error) {
181
+ return false;
182
+ }
183
+ }
184
+ getVendorFromCommand(commandTokens) {
185
+ const commandString = commandTokens.join(" ").toLowerCase();
186
+ if (commandString.includes("claude.app")) {
187
+ return {
188
+ estimatedVendor: "anthropic",
189
+ estimatedProduct: "claude-desktop"
190
+ };
191
+ }
192
+ if (commandString.includes("claude")) {
193
+ return {
194
+ estimatedVendor: "anthropic",
195
+ estimatedProduct: "claude-desktop"
196
+ };
197
+ }
198
+ }
199
+ isCommandMatch(commandTokens, pid, ppid) {
200
+ if (commandTokens.length === 0) return false;
201
+ const baseCommand = this.getBaseCommand(commandTokens[0]);
202
+ if (this.command === "uvx" && baseCommand === "uv") {
203
+ return this.matchUvxProcess(commandTokens);
204
+ }
205
+ if (this.command === "npx" && baseCommand === "npm") {
206
+ return this.matchNpxProcess(commandTokens);
207
+ }
208
+ if (this.command === "uv" && baseCommand === "uv") {
209
+ return this.matchGenericArgsToArgs(commandTokens);
210
+ }
211
+ const commandConfigPythonBase = this.getBaseCommand(this.command);
212
+ const commandAliasesPython = ["python3", "python", "python3.10", "python3.11", "python3.12", "cpython3", "cpython", "python3", "python2"];
213
+ if (commandAliasesPython.includes(commandConfigPythonBase) && commandAliasesPython.includes(baseCommand)) {
214
+ return this.matchGenericArgsToArgs(commandTokens);
215
+ }
216
+ const commandGenericBase = this.getBaseCommand(this.command);
217
+ const commandGenericProcessBase = this.getBaseCommand(commandTokens[0]);
218
+ if (commandGenericBase === commandGenericProcessBase) {
219
+ return this.matchGenericArgsToArgs(commandTokens);
220
+ }
221
+ return false;
222
+ }
223
+ matchGenericArgsToArgs(commandTokens) {
224
+ if (this.args.length === 0) {
225
+ return commandTokens[0] === this.command;
226
+ }
227
+ if (commandTokens.length < 2) {
228
+ return false;
229
+ }
230
+ const commandWithoutArgs = commandTokens.slice(1);
231
+ for (let i = 0; i < this.args.length; i++) {
232
+ if (i >= commandWithoutArgs.length) return false;
233
+ const arg = this.args[i];
234
+ const token = commandWithoutArgs[i];
235
+ if (arg !== token && !token.includes(arg)) {
236
+ return false;
237
+ }
238
+ }
239
+ return true;
240
+ }
241
+ // @TODO refactor this to use path.basename or similar
242
+ // to extract the base command from the full command path
243
+ getBaseCommand(fullCommandPath) {
244
+ const parts = fullCommandPath.split(/[/\\]/);
245
+ return parts[parts.length - 1];
246
+ }
247
+ /*
248
+ example1:
249
+ ```
250
+ "command": "uvx",
251
+ "args": ["--from", "mcp-alchemy==2025.5.2.210242", "--with", "oracledb",
252
+ "--refresh-package", "mcp-alchemy", "mcp-alchemy"],
253
+ ```
254
+
255
+ example 2:
256
+ ```
257
+ "command": "uvx",
258
+ "args": [
259
+ "mcp-neo4j-memory@0.1.4",
260
+ "--db-url",
261
+ "neo4j+s://xxxx.databases.neo4j.io",
262
+ "--username",
263
+ "<your-username>",
264
+ "--password",
265
+ "<your-password>"
266
+ ]
267
+ ```
268
+
269
+ example 3:
270
+ ```
271
+ "vefaas": {
272
+ "command": "uvx",
273
+ "args": [
274
+ "--from",
275
+ "git+https://github.com/volcengine/mcp-server#subdirectory=server/mcp_server_vefaas_function",
276
+ "mcp-server-vefaas-function"
277
+ ],
278
+ "env": {
279
+ "VOLC_ACCESSKEY": "xxx",
280
+ "VOLC_SECRETKEY": "xxx"
281
+ }
282
+ }
283
+ }
284
+ ```
285
+
286
+ example 4:
287
+ ```
288
+ "time": {
289
+ "command": "uvx",
290
+ "args": ["mcp-server-time", "--local-timezone=America/New_York"]
291
+ }
292
+ ```
293
+ */
294
+ getUvxMcpServerNameFromArgs() {
295
+ if (this.args.length === 0) return void 0;
296
+ let mcpServerName;
297
+ if (this.args.length === 1) {
298
+ mcpServerName = this.args[0];
299
+ return mcpServerName;
300
+ }
301
+ for (let i = 0; i < this.args.length; i++) {
302
+ if (this.args[i] === "--from" && i + 1 < this.args.length) {
303
+ mcpServerName = this.args[i + 1];
304
+ return mcpServerName;
305
+ }
306
+ }
307
+ const firstArg = this.args[0];
308
+ if (firstArg.startsWith("-") || firstArg.startsWith("--")) {
309
+ const lastArg = this.args[this.args.length - 1];
310
+ mcpServerName = lastArg;
311
+ return mcpServerName;
312
+ }
313
+ mcpServerName = firstArg;
314
+ return mcpServerName;
315
+ }
316
+ matchUvxProcess(commandTokens) {
317
+ if (commandTokens.length === 0) return false;
318
+ const mcpServerName = this.getUvxMcpServerNameFromArgs();
319
+ if (!mcpServerName) return false;
320
+ return this.findMcpServerNameInProcessArguments(commandTokens, mcpServerName);
321
+ }
322
+ findMcpServerNameInProcessArguments(commandTokens, mcpServerName) {
323
+ for (let i = 0; i < commandTokens.length; i++) {
324
+ const token = commandTokens[i];
325
+ if (mcpServerName === token || token.includes(mcpServerName)) {
326
+ return true;
327
+ }
328
+ }
329
+ return false;
330
+ }
331
+ parseCSVLine(line) {
332
+ const result = [];
333
+ let current = "";
334
+ let inQuotes = false;
335
+ for (let i = 0; i < line.length; i++) {
336
+ const char = line[i];
337
+ if (char === '"') {
338
+ if (inQuotes && line[i + 1] === '"') {
339
+ current += '"';
340
+ i++;
341
+ } else {
342
+ inQuotes = !inQuotes;
343
+ }
344
+ } else if (char === "," && !inQuotes) {
345
+ result.push(current);
346
+ current = "";
347
+ } else {
348
+ current += char;
349
+ }
350
+ }
351
+ result.push(current);
352
+ return result;
353
+ }
354
+ parseCommandLine(commandLine) {
355
+ const tokens = [];
356
+ let current = "";
357
+ let inQuotes = false;
358
+ let quoteChar = "";
359
+ for (let i = 0; i < commandLine.length; i++) {
360
+ const char = commandLine[i];
361
+ if (!inQuotes && (char === '"' || char === "'")) {
362
+ inQuotes = true;
363
+ quoteChar = char;
364
+ } else if (inQuotes && char === quoteChar) {
365
+ inQuotes = false;
366
+ quoteChar = "";
367
+ } else if (!inQuotes && char === " ") {
368
+ if (current.trim()) {
369
+ tokens.push(current.trim());
370
+ current = "";
371
+ }
372
+ } else {
373
+ current += char;
374
+ }
375
+ }
376
+ if (current.trim()) {
377
+ tokens.push(current.trim());
378
+ }
379
+ return tokens;
380
+ }
381
+ /*
382
+ example to match:
383
+ ```
384
+ "command": "npx",
385
+ "args": [
386
+ "-y",
387
+ "@modelcontextprotocol/server-postgres",
388
+ "postgresql://localhost/mydb"
389
+ ]
390
+ }
391
+ ```
392
+
393
+ with a process command like:
394
+ ```
395
+ npm exec @modelcontextprotocol/server-postgres postgresql://localhost/mydb
396
+ ```
397
+ */
398
+ matchNpxProcess(commandTokens) {
399
+ if (commandTokens.length < 3) return false;
400
+ if (commandTokens[1] !== "exec") return false;
401
+ let argsToMatch = [];
402
+ const yIndex = this.args.indexOf("-y");
403
+ if (yIndex !== -1 && yIndex + 1 < this.args.length) {
404
+ argsToMatch = this.args.slice(yIndex + 1);
405
+ } else {
406
+ argsToMatch = this.args;
407
+ }
408
+ if (commandTokens.length - 2 !== argsToMatch.length) {
409
+ return false;
410
+ }
411
+ for (let i = 0; i < argsToMatch.length; i++) {
412
+ const commandToken = commandTokens[i + 2];
413
+ const expectedArg = argsToMatch[i];
414
+ if (commandToken !== expectedArg) {
415
+ return false;
416
+ }
417
+ }
418
+ return true;
113
419
  }
114
420
  };
115
421
 
@@ -120,7 +426,7 @@ var MCPFiles = class {
120
426
  }
121
427
  mcpFilePathGroups = {
122
428
  claude: {
123
- name: "claude",
429
+ name: "claude-desktop",
124
430
  friendlyName: "Claude Desktop",
125
431
  paths: [
126
432
  { filePath: "~/Library/Application Support/Claude/claude_desktop_config.json", type: "global" }
@@ -130,8 +436,8 @@ var MCPFiles = class {
130
436
  name: "cursor",
131
437
  friendlyName: "Cursor",
132
438
  paths: [
133
- { filePath: ".cursor/mcp.json", type: "local" },
134
- { filePath: "~/.cursor/mcp.json", type: "global" }
439
+ { filePath: "~/.cursor/mcp.json", type: "global" },
440
+ { filePath: ".cursor/mcp.json", type: "local" }
135
441
  ]
136
442
  }
137
443
  };
@@ -167,13 +473,20 @@ var MCPFiles = class {
167
473
  env: serverConfigRaw.env
168
474
  };
169
475
  const MCPServerManager = new MCPServerManagerService(serverConfig);
476
+ const mcpServerProcessDetection = MCPServerManager.isRunning();
477
+ let mcpServerProcess = false;
478
+ if (mcpServerProcessDetection) {
479
+ if (typeof mcpServerProcessDetection === "object" && mcpServerProcessDetection.estimatedProduct === clientsGroup.name) {
480
+ mcpServerProcess = true;
481
+ }
482
+ }
170
483
  mcpServersData.push({
171
484
  name: MCPServerManager.getName(),
172
485
  command: MCPServerManager.getCmd(),
173
486
  args: MCPServerManager.getArgs(),
174
487
  transport: MCPServerManager.getTransport(),
175
488
  env: MCPServerManager.getEnv(),
176
- status: MCPServerManager.isRunning() ? "running" : "stopped"
489
+ status: mcpServerProcess ? "running" : "stopped"
177
490
  });
178
491
  }
179
492
  filePathData.servers = mcpServersData;