ls-mcp 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.cjs CHANGED
@@ -34,32 +34,445 @@ __export(main_exports, {
34
34
  MCPFiles: () => MCPFiles
35
35
  });
36
36
  module.exports = __toCommonJS(main_exports);
37
+ var import_promises2 = __toESM(require("fs/promises"), 1);
38
+
39
+ // src/services/mcp-config-linter-service.ts
37
40
  var import_promises = __toESM(require("fs/promises"), 1);
41
+ var MCPConfigLinterService = class {
42
+ static {
43
+ __name(this, "MCPConfigLinterService");
44
+ }
45
+ filePath;
46
+ fileContents = null;
47
+ constructor(filePath) {
48
+ this.filePath = filePath;
49
+ }
50
+ async isValidSyntax() {
51
+ try {
52
+ const fileContent = await this.getFileContent();
53
+ JSON.parse(fileContent);
54
+ return true;
55
+ } catch (error) {
56
+ return false;
57
+ }
58
+ }
59
+ async countMCPServers() {
60
+ const mcpServers = await this.getMCPServers();
61
+ return Object.keys(mcpServers).length;
62
+ }
63
+ async getMCPServers() {
64
+ const fileContentRaw = await this.getFileContent();
65
+ const fileContentsData = JSON.parse(fileContentRaw);
66
+ const mcpServers = fileContentsData?.mcpServers;
67
+ return mcpServers;
68
+ }
69
+ async getFileContent() {
70
+ if (this.fileContents) {
71
+ return this.fileContents;
72
+ }
73
+ this.fileContents = await import_promises.default.readFile(this.filePath, "utf-8");
74
+ return this.fileContents;
75
+ }
76
+ };
77
+
78
+ // src/services/mcp-server-manager-service.ts
79
+ var import_node_child_process = require("child_process");
80
+ var import_node_os = require("os");
81
+ var MCPServerManagerService = class {
82
+ static {
83
+ __name(this, "MCPServerManagerService");
84
+ }
85
+ name;
86
+ command;
87
+ args;
88
+ transport;
89
+ env;
90
+ running = false;
91
+ constructor(serverConfig) {
92
+ this.name = serverConfig.name;
93
+ this.command = serverConfig.command;
94
+ this.args = serverConfig.args || [];
95
+ this.transport = serverConfig.transport || "stdio";
96
+ this.env = serverConfig.env || {};
97
+ }
98
+ getName() {
99
+ return this.name;
100
+ }
101
+ getCmd() {
102
+ return this.command;
103
+ }
104
+ getArgs() {
105
+ return this.args;
106
+ }
107
+ getTransport() {
108
+ return this.transport;
109
+ }
110
+ getEnv() {
111
+ return this.env;
112
+ }
113
+ isRunning() {
114
+ try {
115
+ let psOutput;
116
+ if ((0, import_node_os.platform)() === "win32") {
117
+ psOutput = (0, import_node_child_process.execSync)("wmic process get ProcessId,ParentProcessId,CommandLine /format:csv", {
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
+ const parts = processLine.split(",");
136
+ if (parts.length < 4) continue;
137
+ commandLine = parts[1] || "";
138
+ ppid = parts[2] || "";
139
+ pid = parts[3] || "";
140
+ } else {
141
+ const match = processLine.trim().match(/^\s*(\d+)\s+(\d+)\s+(.+)$/);
142
+ if (!match) continue;
143
+ pid = match[1];
144
+ ppid = match[2];
145
+ commandLine = match[3];
146
+ }
147
+ const commandTokens = this.parseCommandLine(commandLine);
148
+ if (commandTokens.length > 0) {
149
+ processMap.set(pid, { ppid, commandTokens });
150
+ }
151
+ }
152
+ let mcpServerDetection;
153
+ for (const [pid, processData] of processMap) {
154
+ if (this.isCommandMatch(processData.commandTokens, pid, processData.ppid)) {
155
+ mcpServerDetection = {
156
+ pid,
157
+ commandLine: processData.commandTokens.join(" "),
158
+ ppid: processData.ppid
159
+ };
160
+ const parentProcess = processMap.get(processData.ppid);
161
+ if (parentProcess) {
162
+ const { estimatedVendor, estimatedProduct } = this.getVendorFromCommand(parentProcess.commandTokens) || {};
163
+ if (estimatedProduct || estimatedVendor) {
164
+ mcpServerDetection = {
165
+ ...mcpServerDetection,
166
+ parentCommandLine: parentProcess.commandTokens.join(" "),
167
+ estimatedVendor,
168
+ estimatedProduct
169
+ };
170
+ return mcpServerDetection;
171
+ }
172
+ }
173
+ }
174
+ }
175
+ if (mcpServerDetection) {
176
+ return mcpServerDetection;
177
+ }
178
+ return false;
179
+ } catch (error) {
180
+ return false;
181
+ }
182
+ }
183
+ getVendorFromCommand(commandTokens) {
184
+ const commandString = commandTokens.join(" ").toLowerCase();
185
+ if (commandString.includes("claude.app")) {
186
+ return {
187
+ estimatedVendor: "anthropic",
188
+ estimatedProduct: "claude-desktop"
189
+ };
190
+ }
191
+ if (commandString.includes("claude")) {
192
+ return {
193
+ estimatedVendor: "anthropic",
194
+ estimatedProduct: "claude-desktop"
195
+ };
196
+ }
197
+ }
198
+ isCommandMatch(commandTokens, pid, ppid) {
199
+ if (commandTokens.length === 0) return false;
200
+ const baseCommand = this.getBaseCommand(commandTokens[0]);
201
+ if (this.command === "uvx" && baseCommand === "uv") {
202
+ return this.matchUvxProcess(commandTokens);
203
+ }
204
+ if (this.command === "npx" && baseCommand === "npm") {
205
+ return this.matchNpxProcess(commandTokens);
206
+ }
207
+ if (this.command === "uv" && baseCommand === "uv") {
208
+ return this.matchGenericArgsToArgs(commandTokens);
209
+ }
210
+ const commandConfigPythonBase = this.getBaseCommand(this.command);
211
+ const commandAliasesPython = ["python3", "python", "python3.10", "python3.11", "python3.12", "cpython3", "cpython", "python3", "python2"];
212
+ if (commandAliasesPython.includes(commandConfigPythonBase) && commandAliasesPython.includes(baseCommand)) {
213
+ return this.matchGenericArgsToArgs(commandTokens);
214
+ }
215
+ const commandGenericBase = this.getBaseCommand(this.command);
216
+ const commandGenericProcessBase = this.getBaseCommand(commandTokens[0]);
217
+ if (commandGenericBase === commandGenericProcessBase) {
218
+ return this.matchGenericArgsToArgs(commandTokens);
219
+ }
220
+ return false;
221
+ }
222
+ matchGenericArgsToArgs(commandTokens) {
223
+ if (this.args.length === 0) {
224
+ return commandTokens[0] === this.command;
225
+ }
226
+ if (commandTokens.length < 2) {
227
+ return false;
228
+ }
229
+ const commandWithoutArgs = commandTokens.slice(1);
230
+ for (let i = 0; i < this.args.length; i++) {
231
+ if (i >= commandWithoutArgs.length) return false;
232
+ const arg = this.args[i];
233
+ const token = commandWithoutArgs[i];
234
+ if (arg !== token && !token.includes(arg)) {
235
+ return false;
236
+ }
237
+ }
238
+ return true;
239
+ }
240
+ // @TODO refactor this to use path.basename or similar
241
+ // to extract the base command from the full command path
242
+ getBaseCommand(fullCommandPath) {
243
+ const parts = fullCommandPath.split(/[/\\]/);
244
+ return parts[parts.length - 1];
245
+ }
246
+ /*
247
+ example1:
248
+ ```
249
+ "command": "uvx",
250
+ "args": ["--from", "mcp-alchemy==2025.5.2.210242", "--with", "oracledb",
251
+ "--refresh-package", "mcp-alchemy", "mcp-alchemy"],
252
+ ```
253
+
254
+ example 2:
255
+ ```
256
+ "command": "uvx",
257
+ "args": [
258
+ "mcp-neo4j-memory@0.1.4",
259
+ "--db-url",
260
+ "neo4j+s://xxxx.databases.neo4j.io",
261
+ "--username",
262
+ "<your-username>",
263
+ "--password",
264
+ "<your-password>"
265
+ ]
266
+ ```
267
+
268
+ example 3:
269
+ ```
270
+ "vefaas": {
271
+ "command": "uvx",
272
+ "args": [
273
+ "--from",
274
+ "git+https://github.com/volcengine/mcp-server#subdirectory=server/mcp_server_vefaas_function",
275
+ "mcp-server-vefaas-function"
276
+ ],
277
+ "env": {
278
+ "VOLC_ACCESSKEY": "xxx",
279
+ "VOLC_SECRETKEY": "xxx"
280
+ }
281
+ }
282
+ }
283
+ ```
284
+
285
+ example 4:
286
+ ```
287
+ "time": {
288
+ "command": "uvx",
289
+ "args": ["mcp-server-time", "--local-timezone=America/New_York"]
290
+ }
291
+ ```
292
+ */
293
+ getUvxMcpServerNameFromArgs() {
294
+ if (this.args.length === 0) return void 0;
295
+ let mcpServerName;
296
+ if (this.args.length === 1) {
297
+ mcpServerName = this.args[0];
298
+ return mcpServerName;
299
+ }
300
+ for (let i = 0; i < this.args.length; i++) {
301
+ if (this.args[i] === "--from" && i + 1 < this.args.length) {
302
+ mcpServerName = this.args[i + 1];
303
+ return mcpServerName;
304
+ }
305
+ }
306
+ const firstArg = this.args[0];
307
+ if (firstArg.startsWith("-") || firstArg.startsWith("--")) {
308
+ const lastArg = this.args[this.args.length - 1];
309
+ mcpServerName = lastArg;
310
+ return mcpServerName;
311
+ }
312
+ mcpServerName = firstArg;
313
+ return mcpServerName;
314
+ }
315
+ matchUvxProcess(commandTokens) {
316
+ if (commandTokens.length === 0) return false;
317
+ const mcpServerName = this.getUvxMcpServerNameFromArgs();
318
+ if (!mcpServerName) return false;
319
+ return this.findMcpServerNameInProcessArguments(commandTokens, mcpServerName);
320
+ }
321
+ findMcpServerNameInProcessArguments(commandTokens, mcpServerName) {
322
+ for (let i = 0; i < commandTokens.length; i++) {
323
+ const token = commandTokens[i];
324
+ if (mcpServerName === token || token.includes(mcpServerName)) {
325
+ return true;
326
+ }
327
+ }
328
+ return false;
329
+ }
330
+ parseCommandLine(commandLine) {
331
+ const tokens = [];
332
+ let current = "";
333
+ let inQuotes = false;
334
+ let quoteChar = "";
335
+ for (let i = 0; i < commandLine.length; i++) {
336
+ const char = commandLine[i];
337
+ if (!inQuotes && (char === '"' || char === "'")) {
338
+ inQuotes = true;
339
+ quoteChar = char;
340
+ } else if (inQuotes && char === quoteChar) {
341
+ inQuotes = false;
342
+ quoteChar = "";
343
+ } else if (!inQuotes && char === " ") {
344
+ if (current.trim()) {
345
+ tokens.push(current.trim());
346
+ current = "";
347
+ }
348
+ } else {
349
+ current += char;
350
+ }
351
+ }
352
+ if (current.trim()) {
353
+ tokens.push(current.trim());
354
+ }
355
+ return tokens;
356
+ }
357
+ /*
358
+ example to match:
359
+ ```
360
+ "command": "npx",
361
+ "args": [
362
+ "-y",
363
+ "@modelcontextprotocol/server-postgres",
364
+ "postgresql://localhost/mydb"
365
+ ]
366
+ }
367
+ ```
368
+
369
+ with a process command like:
370
+ ```
371
+ npm exec @modelcontextprotocol/server-postgres postgresql://localhost/mydb
372
+ ```
373
+ */
374
+ matchNpxProcess(commandTokens) {
375
+ if (commandTokens.length < 3) return false;
376
+ if (commandTokens[1] !== "exec") return false;
377
+ let argsToMatch = [];
378
+ const yIndex = this.args.indexOf("-y");
379
+ if (yIndex !== -1 && yIndex + 1 < this.args.length) {
380
+ argsToMatch = this.args.slice(yIndex + 1);
381
+ } else {
382
+ argsToMatch = this.args;
383
+ }
384
+ if (commandTokens.length - 2 !== argsToMatch.length) {
385
+ return false;
386
+ }
387
+ for (let i = 0; i < argsToMatch.length; i++) {
388
+ const commandToken = commandTokens[i + 2];
389
+ const expectedArg = argsToMatch[i];
390
+ if (commandToken !== expectedArg) {
391
+ return false;
392
+ }
393
+ }
394
+ return true;
395
+ }
396
+ };
397
+
398
+ // src/main.ts
38
399
  var MCPFiles = class {
39
400
  static {
40
401
  __name(this, "MCPFiles");
41
402
  }
42
- mcpFilePaths = [
43
- "~/Library/Application Support/Claude/claude_desktop_config.json",
44
- ".cursor/mcp.json",
45
- "~/.cursor/mcp.json"
46
- ];
47
- constructor(mcpFilePaths) {
48
- if (mcpFilePaths) {
49
- this.mcpFilePaths = mcpFilePaths;
403
+ mcpFilePathGroups = {
404
+ claude: {
405
+ name: "claude-desktop",
406
+ friendlyName: "Claude Desktop",
407
+ paths: [
408
+ { filePath: "~/Library/Application Support/Claude/claude_desktop_config.json", type: "global" }
409
+ ]
410
+ },
411
+ cursor: {
412
+ name: "cursor",
413
+ friendlyName: "Cursor",
414
+ paths: [
415
+ { filePath: "~/.cursor/mcp.json", type: "global" },
416
+ { filePath: ".cursor/mcp.json", type: "local" }
417
+ ]
50
418
  }
419
+ };
420
+ constructor(mcpFilePathGroups) {
421
+ this.mcpFilePathGroups = mcpFilePathGroups || this.mcpFilePathGroups;
51
422
  }
52
423
  async findFiles() {
53
- const files = [];
54
- for (const path of this.mcpFilePaths) {
55
- try {
56
- const resolvedPath = path.replace("~", process.env.HOME || "");
57
- await import_promises.default.access(resolvedPath);
58
- files.push(resolvedPath);
59
- } catch (error) {
424
+ const mcpFilesPathsData = {};
425
+ for (const groupName of Object.keys(this.mcpFilePathGroups)) {
426
+ const clientsGroup = this.mcpFilePathGroups[groupName];
427
+ mcpFilesPathsData[groupName] = {
428
+ name: clientsGroup.name,
429
+ friendlyName: clientsGroup.friendlyName,
430
+ paths: [],
431
+ stats: {}
432
+ };
433
+ for (const filePathData of clientsGroup.paths) {
434
+ const resolvedPath = filePathData.filePath.replace("~", process.env.HOME || "");
435
+ try {
436
+ await import_promises2.default.access(resolvedPath);
437
+ const MCPConfigLinter = new MCPConfigLinterService(resolvedPath);
438
+ const parsable = await MCPConfigLinter.isValidSyntax();
439
+ filePathData.parsable = parsable;
440
+ const mcpServersData = [];
441
+ const mcpServersFromConfig = await MCPConfigLinter.getMCPServers();
442
+ for (const serverName of Object.keys(mcpServersFromConfig)) {
443
+ const serverConfigRaw = mcpServersFromConfig[serverName];
444
+ const serverConfig = {
445
+ name: serverName,
446
+ command: serverConfigRaw.command || "",
447
+ args: serverConfigRaw.args,
448
+ transport: serverConfigRaw.transport,
449
+ env: serverConfigRaw.env
450
+ };
451
+ const MCPServerManager = new MCPServerManagerService(serverConfig);
452
+ const mcpServerProcessDetection = MCPServerManager.isRunning();
453
+ let mcpServerProcess = false;
454
+ if (mcpServerProcessDetection) {
455
+ if (typeof mcpServerProcessDetection === "object" && mcpServerProcessDetection.estimatedProduct === clientsGroup.name) {
456
+ mcpServerProcess = true;
457
+ }
458
+ }
459
+ mcpServersData.push({
460
+ name: MCPServerManager.getName(),
461
+ command: MCPServerManager.getCmd(),
462
+ args: MCPServerManager.getArgs(),
463
+ transport: MCPServerManager.getTransport(),
464
+ env: MCPServerManager.getEnv(),
465
+ status: mcpServerProcess ? "running" : "stopped"
466
+ });
467
+ }
468
+ filePathData.servers = mcpServersData;
469
+ mcpFilesPathsData[groupName]["stats"]["serversCount"] = await MCPConfigLinter.countMCPServers();
470
+ mcpFilesPathsData[groupName].paths.push(filePathData);
471
+ } catch (error) {
472
+ }
60
473
  }
61
474
  }
62
- return files;
475
+ return mcpFilesPathsData;
63
476
  }
64
477
  };
65
478
  // Annotate the CommonJS export names for ESM import in node:
package/dist/main.d.cts CHANGED
@@ -1,7 +1,39 @@
1
+ interface MCPServerInfo {
2
+ name: string;
3
+ command: string;
4
+ args?: string[];
5
+ transport?: 'stdio' | 'sse';
6
+ env?: Record<string, string>;
7
+ status?: 'running' | 'stopped';
8
+ }
9
+ interface MCPFilePath {
10
+ filePath: string;
11
+ type: 'local' | 'global';
12
+ parsable?: boolean;
13
+ servers?: MCPServerInfo[];
14
+ }
15
+ interface MCPFileGroups {
16
+ name: string;
17
+ friendlyName: string;
18
+ paths: MCPFilePath[];
19
+ stats?: {
20
+ serversCount?: number;
21
+ };
22
+ }
23
+ interface MCPFileGroupsResult {
24
+ name: string;
25
+ friendlyName: string;
26
+ paths: MCPFilePath[];
27
+ stats: {
28
+ serversCount?: number;
29
+ };
30
+ }
31
+ type MCPFilePathGroupsRecord = Record<string, MCPFileGroups>;
32
+ type MCPFileGroupsResultRecord = Record<string, MCPFileGroupsResult>;
1
33
  declare class MCPFiles {
2
- private mcpFilePaths;
3
- constructor(mcpFilePaths?: string[]);
4
- findFiles(): Promise<string[]>;
34
+ private mcpFilePathGroups;
35
+ constructor(mcpFilePathGroups?: MCPFilePathGroupsRecord);
36
+ findFiles(): Promise<MCPFileGroupsResultRecord>;
5
37
  }
6
38
 
7
39
  export { MCPFiles };
package/dist/main.d.ts CHANGED
@@ -1,7 +1,39 @@
1
+ interface MCPServerInfo {
2
+ name: string;
3
+ command: string;
4
+ args?: string[];
5
+ transport?: 'stdio' | 'sse';
6
+ env?: Record<string, string>;
7
+ status?: 'running' | 'stopped';
8
+ }
9
+ interface MCPFilePath {
10
+ filePath: string;
11
+ type: 'local' | 'global';
12
+ parsable?: boolean;
13
+ servers?: MCPServerInfo[];
14
+ }
15
+ interface MCPFileGroups {
16
+ name: string;
17
+ friendlyName: string;
18
+ paths: MCPFilePath[];
19
+ stats?: {
20
+ serversCount?: number;
21
+ };
22
+ }
23
+ interface MCPFileGroupsResult {
24
+ name: string;
25
+ friendlyName: string;
26
+ paths: MCPFilePath[];
27
+ stats: {
28
+ serversCount?: number;
29
+ };
30
+ }
31
+ type MCPFilePathGroupsRecord = Record<string, MCPFileGroups>;
32
+ type MCPFileGroupsResultRecord = Record<string, MCPFileGroupsResult>;
1
33
  declare class MCPFiles {
2
- private mcpFilePaths;
3
- constructor(mcpFilePaths?: string[]);
4
- findFiles(): Promise<string[]>;
34
+ private mcpFilePathGroups;
35
+ constructor(mcpFilePathGroups?: MCPFilePathGroupsRecord);
36
+ findFiles(): Promise<MCPFileGroupsResultRecord>;
5
37
  }
6
38
 
7
39
  export { MCPFiles };