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.mjs CHANGED
@@ -44,6 +44,8 @@ var MCPConfigLinterService = class {
44
44
  };
45
45
 
46
46
  // src/services/mcp-server-manager-service.ts
47
+ import { execSync } from "child_process";
48
+ import { platform } from "os";
47
49
  var MCPServerManagerService = class {
48
50
  static {
49
51
  __name(this, "MCPServerManagerService");
@@ -77,7 +79,311 @@ var MCPServerManagerService = class {
77
79
  return this.env;
78
80
  }
79
81
  isRunning() {
80
- return this.running;
82
+ try {
83
+ let psOutput;
84
+ if (platform() === "win32") {
85
+ psOutput = execSync('powershell -Command "Get-CimInstance -ClassName Win32_Process | Select-Object ProcessId,Name,CommandLine,ParentProcessId | ConvertTo-Csv -NoTypeInformation"', {
86
+ encoding: "utf8",
87
+ timeout: 5e3
88
+ });
89
+ } else {
90
+ psOutput = execSync("ps -eao pid,ppid,args", {
91
+ encoding: "utf8",
92
+ timeout: 5e3
93
+ });
94
+ }
95
+ const processMap = /* @__PURE__ */ new Map();
96
+ const processes = psOutput.trim().split("\n");
97
+ for (const processLine of processes) {
98
+ if (!processLine.trim()) continue;
99
+ let pid;
100
+ let ppid;
101
+ let commandLine;
102
+ if (platform() === "win32") {
103
+ if (processLine.startsWith('"ProcessId"') || processLine.startsWith("ProcessId")) continue;
104
+ const parts = this.parseCSVLine(processLine);
105
+ if (parts.length < 4) continue;
106
+ pid = parts[0] || "";
107
+ commandLine = parts[2] || "";
108
+ ppid = 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
+ parseCSVLine(line) {
300
+ const result = [];
301
+ let current = "";
302
+ let inQuotes = false;
303
+ for (let i = 0; i < line.length; i++) {
304
+ const char = line[i];
305
+ if (char === '"') {
306
+ if (inQuotes && line[i + 1] === '"') {
307
+ current += '"';
308
+ i++;
309
+ } else {
310
+ inQuotes = !inQuotes;
311
+ }
312
+ } else if (char === "," && !inQuotes) {
313
+ result.push(current);
314
+ current = "";
315
+ } else {
316
+ current += char;
317
+ }
318
+ }
319
+ result.push(current);
320
+ return result;
321
+ }
322
+ parseCommandLine(commandLine) {
323
+ const tokens = [];
324
+ let current = "";
325
+ let inQuotes = false;
326
+ let quoteChar = "";
327
+ for (let i = 0; i < commandLine.length; i++) {
328
+ const char = commandLine[i];
329
+ if (!inQuotes && (char === '"' || char === "'")) {
330
+ inQuotes = true;
331
+ quoteChar = char;
332
+ } else if (inQuotes && char === quoteChar) {
333
+ inQuotes = false;
334
+ quoteChar = "";
335
+ } else if (!inQuotes && char === " ") {
336
+ if (current.trim()) {
337
+ tokens.push(current.trim());
338
+ current = "";
339
+ }
340
+ } else {
341
+ current += char;
342
+ }
343
+ }
344
+ if (current.trim()) {
345
+ tokens.push(current.trim());
346
+ }
347
+ return tokens;
348
+ }
349
+ /*
350
+ example to match:
351
+ ```
352
+ "command": "npx",
353
+ "args": [
354
+ "-y",
355
+ "@modelcontextprotocol/server-postgres",
356
+ "postgresql://localhost/mydb"
357
+ ]
358
+ }
359
+ ```
360
+
361
+ with a process command like:
362
+ ```
363
+ npm exec @modelcontextprotocol/server-postgres postgresql://localhost/mydb
364
+ ```
365
+ */
366
+ matchNpxProcess(commandTokens) {
367
+ if (commandTokens.length < 3) return false;
368
+ if (commandTokens[1] !== "exec") return false;
369
+ let argsToMatch = [];
370
+ const yIndex = this.args.indexOf("-y");
371
+ if (yIndex !== -1 && yIndex + 1 < this.args.length) {
372
+ argsToMatch = this.args.slice(yIndex + 1);
373
+ } else {
374
+ argsToMatch = this.args;
375
+ }
376
+ if (commandTokens.length - 2 !== argsToMatch.length) {
377
+ return false;
378
+ }
379
+ for (let i = 0; i < argsToMatch.length; i++) {
380
+ const commandToken = commandTokens[i + 2];
381
+ const expectedArg = argsToMatch[i];
382
+ if (commandToken !== expectedArg) {
383
+ return false;
384
+ }
385
+ }
386
+ return true;
81
387
  }
82
388
  };
83
389
 
@@ -88,7 +394,7 @@ var MCPFiles = class {
88
394
  }
89
395
  mcpFilePathGroups = {
90
396
  claude: {
91
- name: "claude",
397
+ name: "claude-desktop",
92
398
  friendlyName: "Claude Desktop",
93
399
  paths: [
94
400
  { filePath: "~/Library/Application Support/Claude/claude_desktop_config.json", type: "global" }
@@ -98,8 +404,8 @@ var MCPFiles = class {
98
404
  name: "cursor",
99
405
  friendlyName: "Cursor",
100
406
  paths: [
101
- { filePath: ".cursor/mcp.json", type: "local" },
102
- { filePath: "~/.cursor/mcp.json", type: "global" }
407
+ { filePath: "~/.cursor/mcp.json", type: "global" },
408
+ { filePath: ".cursor/mcp.json", type: "local" }
103
409
  ]
104
410
  }
105
411
  };
@@ -135,13 +441,20 @@ var MCPFiles = class {
135
441
  env: serverConfigRaw.env
136
442
  };
137
443
  const MCPServerManager = new MCPServerManagerService(serverConfig);
444
+ const mcpServerProcessDetection = MCPServerManager.isRunning();
445
+ let mcpServerProcess = false;
446
+ if (mcpServerProcessDetection) {
447
+ if (typeof mcpServerProcessDetection === "object" && mcpServerProcessDetection.estimatedProduct === clientsGroup.name) {
448
+ mcpServerProcess = true;
449
+ }
450
+ }
138
451
  mcpServersData.push({
139
452
  name: MCPServerManager.getName(),
140
453
  command: MCPServerManager.getCmd(),
141
454
  args: MCPServerManager.getArgs(),
142
455
  transport: MCPServerManager.getTransport(),
143
456
  env: MCPServerManager.getEnv(),
144
- status: MCPServerManager.isRunning() ? "running" : "stopped"
457
+ status: mcpServerProcess ? "running" : "stopped"
145
458
  });
146
459
  }
147
460
  filePathData.servers = mcpServersData;
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "ls-mcp",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "description": "list and detect MCP servers and configurations",
5
5
  "types": "dist/main.d.ts",
6
6
  "type": "module",
7
- "bin": "./dist/bin/cli.cjs",
7
+ "bin": {
8
+ "ls-mcp": "./dist/bin/cli.cjs"
9
+ },
8
10
  "exports": {
9
11
  ".": {
10
12
  "import": {
@@ -33,7 +35,7 @@
33
35
  "bin"
34
36
  ],
35
37
  "scripts": {
36
- "start": "node --import tsx src/bin/cli.ts",
38
+ "start": "npm run build && node --import tsx src/bin/cli.ts",
37
39
  "build": "tsc && tsup",
38
40
  "lint": "eslint . && npm run lint:lockfile",
39
41
  "lint:fix": "eslint . --fix",
package/src/bin/cli.ts CHANGED
@@ -1,3 +1,5 @@
1
+ #!/usr/bin/env node
2
+
1
3
  // import { debuglog } from 'node:util'
2
4
  import { MCPFiles } from '../main.ts'
3
5
  import { RenderService } from '../services/render-service.ts'
@@ -26,14 +28,15 @@ async function init () {
26
28
  return
27
29
  }
28
30
 
29
- let groupIndex = 0
31
+ let pathIndex = 0
30
32
  for (const groupName of Object.keys(mcpFilesList)) {
31
- groupIndex++
32
33
  const group = mcpFilesList[groupName]
33
34
 
34
35
  if (group.paths.length >= 0) {
35
36
  // handle file path list of MCP Servers
36
37
  for (const filePathData of group.paths) {
38
+ pathIndex++
39
+
37
40
  const filePath = filePathData.filePath.replace('~', process.env.HOME || '')
38
41
  const filePathValid = filePathData.parsable ? 'VALID' : 'INVALID'
39
42
  const filePathDataType = filePathData.type.toUpperCase()
@@ -45,8 +48,8 @@ async function init () {
45
48
  const mcpGroupData = [
46
49
  { key: 'PROVIDER', value: group.friendlyName },
47
50
  { key: 'FILE', value: filePath },
48
- { key: 'PARSABLE', value: filePathValid },
49
51
  { key: 'TYPE', value: filePathDataType },
52
+ { key: 'PARSABLE', value: filePathValid },
50
53
  ]
51
54
 
52
55
  const groupMetadata = {
@@ -54,7 +57,7 @@ async function init () {
54
57
  mcpServersRunning: totalMCPServersRunning,
55
58
  }
56
59
 
57
- RenderService.printMcpGroup(groupIndex, mcpGroupData, groupMetadata)
60
+ RenderService.printMcpGroup(pathIndex, mcpGroupData, groupMetadata)
58
61
  RenderService.printMcpServers(mcpServers)
59
62
  }
60
63
  } else {
@@ -6,7 +6,7 @@ export default function render (text: string) {
6
6
  if (formattedText === 'running') {
7
7
  data = styleText(['green'], '●')
8
8
  } else {
9
- data = styleText(['red'], '○')
9
+ data = styleText(['red'], '●')
10
10
  }
11
11
 
12
12
  return data
@@ -4,9 +4,9 @@ export default function render (text: string) {
4
4
  const formattedText = text.toUpperCase().replace(/_/g, ' ')
5
5
  let data = formattedText
6
6
  if (formattedText === 'VALID') {
7
- data = styleText(['green'], formattedText)
7
+ data = styleText(['green'], '●')
8
8
  } else {
9
- data = styleText(['red'], formattedText)
9
+ data = styleText(['red'], '●')
10
10
  }
11
11
 
12
12
  return data
package/src/main.ts CHANGED
@@ -42,7 +42,7 @@ type MCPFileGroupsResultRecord = Record<string, MCPFileGroupsResult>
42
42
  export class MCPFiles {
43
43
  private mcpFilePathGroups: MCPFilePathGroupsRecord = {
44
44
  claude: {
45
- name: 'claude',
45
+ name: 'claude-desktop',
46
46
  friendlyName: 'Claude Desktop',
47
47
  paths: [
48
48
  { filePath: '~/Library/Application Support/Claude/claude_desktop_config.json', type: 'global' },
@@ -52,8 +52,8 @@ export class MCPFiles {
52
52
  name: 'cursor',
53
53
  friendlyName: 'Cursor',
54
54
  paths: [
55
- { filePath: '.cursor/mcp.json', type: 'local' },
56
55
  { filePath: '~/.cursor/mcp.json', type: 'global' },
56
+ { filePath: '.cursor/mcp.json', type: 'local' },
57
57
  ]
58
58
  }
59
59
  }
@@ -97,13 +97,21 @@ export class MCPFiles {
97
97
  }
98
98
  const MCPServerManager = new MCPServerManagerService(serverConfig)
99
99
 
100
+ const mcpServerProcessDetection = MCPServerManager.isRunning()
101
+ let mcpServerProcess = false
102
+ if (mcpServerProcessDetection) {
103
+ if (typeof mcpServerProcessDetection === 'object' && mcpServerProcessDetection.estimatedProduct === clientsGroup.name) {
104
+ mcpServerProcess = true
105
+ }
106
+ }
107
+
100
108
  mcpServersData.push({
101
109
  name: MCPServerManager.getName(),
102
110
  command: MCPServerManager.getCmd(),
103
111
  args: MCPServerManager.getArgs(),
104
112
  transport: MCPServerManager.getTransport(),
105
113
  env: MCPServerManager.getEnv(),
106
- status: MCPServerManager.isRunning() ? 'running' : 'stopped'
114
+ status: mcpServerProcess ? 'running' : 'stopped'
107
115
  })
108
116
  }
109
117