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/bin/cli.mjs CHANGED
@@ -2,52 +2,714 @@
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 { debuglog } from "util";
7
-
8
5
  // src/main.ts
6
+ import fs2 from "fs/promises";
7
+
8
+ // src/services/mcp-config-linter-service.ts
9
9
  import fs from "fs/promises";
10
+ var MCPConfigLinterService = class {
11
+ static {
12
+ __name(this, "MCPConfigLinterService");
13
+ }
14
+ filePath;
15
+ fileContents = null;
16
+ constructor(filePath) {
17
+ this.filePath = filePath;
18
+ }
19
+ async isValidSyntax() {
20
+ try {
21
+ const fileContent = await this.getFileContent();
22
+ JSON.parse(fileContent);
23
+ return true;
24
+ } catch (error) {
25
+ return false;
26
+ }
27
+ }
28
+ async countMCPServers() {
29
+ const mcpServers = await this.getMCPServers();
30
+ return Object.keys(mcpServers).length;
31
+ }
32
+ async getMCPServers() {
33
+ const fileContentRaw = await this.getFileContent();
34
+ const fileContentsData = JSON.parse(fileContentRaw);
35
+ const mcpServers = fileContentsData?.mcpServers;
36
+ return mcpServers;
37
+ }
38
+ async getFileContent() {
39
+ if (this.fileContents) {
40
+ return this.fileContents;
41
+ }
42
+ this.fileContents = await fs.readFile(this.filePath, "utf-8");
43
+ return this.fileContents;
44
+ }
45
+ };
46
+
47
+ // src/services/mcp-server-manager-service.ts
48
+ import { execSync } from "child_process";
49
+ import { platform } from "os";
50
+ var MCPServerManagerService = class {
51
+ static {
52
+ __name(this, "MCPServerManagerService");
53
+ }
54
+ name;
55
+ command;
56
+ args;
57
+ transport;
58
+ env;
59
+ running = false;
60
+ constructor(serverConfig) {
61
+ this.name = serverConfig.name;
62
+ this.command = serverConfig.command;
63
+ this.args = serverConfig.args || [];
64
+ this.transport = serverConfig.transport || "stdio";
65
+ this.env = serverConfig.env || {};
66
+ }
67
+ getName() {
68
+ return this.name;
69
+ }
70
+ getCmd() {
71
+ return this.command;
72
+ }
73
+ getArgs() {
74
+ return this.args;
75
+ }
76
+ getTransport() {
77
+ return this.transport;
78
+ }
79
+ getEnv() {
80
+ return this.env;
81
+ }
82
+ isRunning() {
83
+ try {
84
+ let psOutput;
85
+ if (platform() === "win32") {
86
+ psOutput = execSync("wmic process get ProcessId,ParentProcessId,CommandLine /format:csv", {
87
+ encoding: "utf8",
88
+ timeout: 5e3
89
+ });
90
+ } else {
91
+ psOutput = execSync("ps -eao pid,ppid,args", {
92
+ encoding: "utf8",
93
+ timeout: 5e3
94
+ });
95
+ }
96
+ const processMap = /* @__PURE__ */ new Map();
97
+ const processes = psOutput.trim().split("\n");
98
+ for (const processLine of processes) {
99
+ if (!processLine.trim()) continue;
100
+ let pid;
101
+ let ppid;
102
+ let commandLine;
103
+ if (platform() === "win32") {
104
+ const parts = processLine.split(",");
105
+ if (parts.length < 4) continue;
106
+ commandLine = parts[1] || "";
107
+ ppid = parts[2] || "";
108
+ pid = 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
+ parseCommandLine(commandLine) {
300
+ const tokens = [];
301
+ let current = "";
302
+ let inQuotes = false;
303
+ let quoteChar = "";
304
+ for (let i = 0; i < commandLine.length; i++) {
305
+ const char = commandLine[i];
306
+ if (!inQuotes && (char === '"' || char === "'")) {
307
+ inQuotes = true;
308
+ quoteChar = char;
309
+ } else if (inQuotes && char === quoteChar) {
310
+ inQuotes = false;
311
+ quoteChar = "";
312
+ } else if (!inQuotes && char === " ") {
313
+ if (current.trim()) {
314
+ tokens.push(current.trim());
315
+ current = "";
316
+ }
317
+ } else {
318
+ current += char;
319
+ }
320
+ }
321
+ if (current.trim()) {
322
+ tokens.push(current.trim());
323
+ }
324
+ return tokens;
325
+ }
326
+ /*
327
+ example to match:
328
+ ```
329
+ "command": "npx",
330
+ "args": [
331
+ "-y",
332
+ "@modelcontextprotocol/server-postgres",
333
+ "postgresql://localhost/mydb"
334
+ ]
335
+ }
336
+ ```
337
+
338
+ with a process command like:
339
+ ```
340
+ npm exec @modelcontextprotocol/server-postgres postgresql://localhost/mydb
341
+ ```
342
+ */
343
+ matchNpxProcess(commandTokens) {
344
+ if (commandTokens.length < 3) return false;
345
+ if (commandTokens[1] !== "exec") return false;
346
+ let argsToMatch = [];
347
+ const yIndex = this.args.indexOf("-y");
348
+ if (yIndex !== -1 && yIndex + 1 < this.args.length) {
349
+ argsToMatch = this.args.slice(yIndex + 1);
350
+ } else {
351
+ argsToMatch = this.args;
352
+ }
353
+ if (commandTokens.length - 2 !== argsToMatch.length) {
354
+ return false;
355
+ }
356
+ for (let i = 0; i < argsToMatch.length; i++) {
357
+ const commandToken = commandTokens[i + 2];
358
+ const expectedArg = argsToMatch[i];
359
+ if (commandToken !== expectedArg) {
360
+ return false;
361
+ }
362
+ }
363
+ return true;
364
+ }
365
+ };
366
+
367
+ // src/main.ts
10
368
  var MCPFiles = class {
11
369
  static {
12
370
  __name(this, "MCPFiles");
13
371
  }
14
- mcpFilePaths = [
15
- "~/Library/Application Support/Claude/claude_desktop_config.json",
16
- ".cursor/mcp.json",
17
- "~/.cursor/mcp.json"
18
- ];
19
- constructor(mcpFilePaths) {
20
- if (mcpFilePaths) {
21
- this.mcpFilePaths = mcpFilePaths;
372
+ mcpFilePathGroups = {
373
+ claude: {
374
+ name: "claude-desktop",
375
+ friendlyName: "Claude Desktop",
376
+ paths: [
377
+ { filePath: "~/Library/Application Support/Claude/claude_desktop_config.json", type: "global" }
378
+ ]
379
+ },
380
+ cursor: {
381
+ name: "cursor",
382
+ friendlyName: "Cursor",
383
+ paths: [
384
+ { filePath: "~/.cursor/mcp.json", type: "global" },
385
+ { filePath: ".cursor/mcp.json", type: "local" }
386
+ ]
22
387
  }
388
+ };
389
+ constructor(mcpFilePathGroups) {
390
+ this.mcpFilePathGroups = mcpFilePathGroups || this.mcpFilePathGroups;
23
391
  }
24
392
  async findFiles() {
25
- const files = [];
26
- for (const path of this.mcpFilePaths) {
27
- try {
28
- const resolvedPath = path.replace("~", process.env.HOME || "");
29
- await fs.access(resolvedPath);
30
- files.push(resolvedPath);
31
- } catch (error) {
393
+ const mcpFilesPathsData = {};
394
+ for (const groupName of Object.keys(this.mcpFilePathGroups)) {
395
+ const clientsGroup = this.mcpFilePathGroups[groupName];
396
+ mcpFilesPathsData[groupName] = {
397
+ name: clientsGroup.name,
398
+ friendlyName: clientsGroup.friendlyName,
399
+ paths: [],
400
+ stats: {}
401
+ };
402
+ for (const filePathData of clientsGroup.paths) {
403
+ const resolvedPath = filePathData.filePath.replace("~", process.env.HOME || "");
404
+ try {
405
+ await fs2.access(resolvedPath);
406
+ const MCPConfigLinter = new MCPConfigLinterService(resolvedPath);
407
+ const parsable = await MCPConfigLinter.isValidSyntax();
408
+ filePathData.parsable = parsable;
409
+ const mcpServersData = [];
410
+ const mcpServersFromConfig = await MCPConfigLinter.getMCPServers();
411
+ for (const serverName of Object.keys(mcpServersFromConfig)) {
412
+ const serverConfigRaw = mcpServersFromConfig[serverName];
413
+ const serverConfig = {
414
+ name: serverName,
415
+ command: serverConfigRaw.command || "",
416
+ args: serverConfigRaw.args,
417
+ transport: serverConfigRaw.transport,
418
+ env: serverConfigRaw.env
419
+ };
420
+ const MCPServerManager = new MCPServerManagerService(serverConfig);
421
+ const mcpServerProcessDetection = MCPServerManager.isRunning();
422
+ let mcpServerProcess = false;
423
+ if (mcpServerProcessDetection) {
424
+ if (typeof mcpServerProcessDetection === "object" && mcpServerProcessDetection.estimatedProduct === clientsGroup.name) {
425
+ mcpServerProcess = true;
426
+ }
427
+ }
428
+ mcpServersData.push({
429
+ name: MCPServerManager.getName(),
430
+ command: MCPServerManager.getCmd(),
431
+ args: MCPServerManager.getArgs(),
432
+ transport: MCPServerManager.getTransport(),
433
+ env: MCPServerManager.getEnv(),
434
+ status: mcpServerProcess ? "running" : "stopped"
435
+ });
436
+ }
437
+ filePathData.servers = mcpServersData;
438
+ mcpFilesPathsData[groupName]["stats"]["serversCount"] = await MCPConfigLinter.countMCPServers();
439
+ mcpFilesPathsData[groupName].paths.push(filePathData);
440
+ } catch (error) {
441
+ }
442
+ }
443
+ }
444
+ return mcpFilesPathsData;
445
+ }
446
+ };
447
+
448
+ // src/services/render-service.ts
449
+ import { styleText as styleText7 } from "util";
450
+
451
+ // src/components/transport.ts
452
+ import { styleText } from "util";
453
+ function render(text) {
454
+ const formattedText = text.toUpperCase();
455
+ let data = "";
456
+ if (formattedText === "STDIO") {
457
+ data = styleText(["magenta"], formattedText);
458
+ }
459
+ if (formattedText === "SSE") {
460
+ data = styleText(["blue"], formattedText);
461
+ }
462
+ return data;
463
+ }
464
+ __name(render, "render");
465
+
466
+ // src/components/column-name.ts
467
+ import { styleText as styleText2 } from "util";
468
+ function render2(text) {
469
+ const formattedText = String(text).toUpperCase();
470
+ const data = styleText2(["dim"], formattedText);
471
+ return data;
472
+ }
473
+ __name(render2, "render");
474
+
475
+ // src/components/mcp-server-status.ts
476
+ import { styleText as styleText3 } from "util";
477
+ function render3(text) {
478
+ const formattedText = text.toLowerCase();
479
+ let data = "";
480
+ if (formattedText === "running") {
481
+ data = styleText3(["green"], "\u25CF");
482
+ } else {
483
+ data = styleText3(["red"], "\u25CF");
484
+ }
485
+ return data;
486
+ }
487
+ __name(render3, "render");
488
+
489
+ // src/components/mcp-server-name.ts
490
+ import { styleText as styleText4 } from "util";
491
+ function render4(text) {
492
+ const formattedText = text.toLowerCase();
493
+ const data = styleText4(["bold", "white"], formattedText);
494
+ return data;
495
+ }
496
+ __name(render4, "render");
497
+
498
+ // src/components/file-path.ts
499
+ import { styleText as styleText5 } from "util";
500
+ function render5(text) {
501
+ const formattedText = text;
502
+ const data = styleText5(["underline"], formattedText);
503
+ return data;
504
+ }
505
+ __name(render5, "render");
506
+
507
+ // src/components/mcp-servers-config-parsable.ts
508
+ import { styleText as styleText6 } from "util";
509
+ function render6(text) {
510
+ const formattedText = text.toUpperCase().replace(/_/g, " ");
511
+ let data = formattedText;
512
+ if (formattedText === "VALID") {
513
+ data = styleText6(["green"], "\u25CF");
514
+ } else {
515
+ data = styleText6(["red"], "\u25CF");
516
+ }
517
+ return data;
518
+ }
519
+ __name(render6, "render");
520
+
521
+ // src/services/render-service.ts
522
+ var RenderService = class {
523
+ static {
524
+ __name(this, "RenderService");
525
+ }
526
+ // Example mocked data for rendering the servers information
527
+ // const mcpServersDataMock = [
528
+ // { status: '●', name: 'logging-server', type: 'SSE', version: '2.3.0', tools: '6', resources: '2' },
529
+ // { status: '●', name: 'git-logging-server', type: 'SSE', version: '2.3.0', tools: '6', resources: '2' },
530
+ // { status: '○', name: 'mcp-server', type: 'STDIO', version: '2.3.0', tools: '62', resources: '0' }
531
+ // ]
532
+ static getVisibleLength(text) {
533
+ return text.replace(/\u001b\[[0-9;]*m/g, "").length;
534
+ }
535
+ static printMcpServers(data) {
536
+ if (data.length === 0) return;
537
+ const headers = ["STATUS", "NAME", "TRANSPORT"];
538
+ const keys = ["status", "name", "transport"];
539
+ const centerColumns = [0, 2];
540
+ const leftPadding = " ";
541
+ const columnWidths = headers.map((header, index) => {
542
+ const headerWidth = this.getVisibleLength(render2(header));
543
+ const dataWidth = Math.max(...data.map((row) => {
544
+ let text = String(row[keys[index]]);
545
+ if (keys[index] === "transport") {
546
+ text = render(text);
547
+ }
548
+ if (keys[index] === "status") {
549
+ text = render3(text);
550
+ }
551
+ if (keys[index] === "name") {
552
+ text = render4(text);
553
+ }
554
+ return this.getVisibleLength(text);
555
+ }));
556
+ return Math.max(headerWidth, dataWidth);
557
+ });
558
+ const centerText = /* @__PURE__ */ __name((text, width) => {
559
+ const visibleLength = this.getVisibleLength(text);
560
+ const padding = width - visibleLength;
561
+ const leftPad = Math.floor(padding / 2);
562
+ const rightPad = padding - leftPad;
563
+ return " ".repeat(leftPad) + text + " ".repeat(rightPad);
564
+ }, "centerText");
565
+ const padRight = /* @__PURE__ */ __name((text, width) => {
566
+ const visibleLength = this.getVisibleLength(text);
567
+ const padding = Math.max(0, width - visibleLength);
568
+ return text + " ".repeat(padding);
569
+ }, "padRight");
570
+ const totalWidth = columnWidths.reduce((sum, width) => sum + width, 0) + (columnWidths.length - 1) * 2;
571
+ const separator = "\u2500".repeat(totalWidth);
572
+ console.log("\n" + leftPadding + separator);
573
+ const headerRow = headers.map((header, index) => {
574
+ const headerText = render2(header);
575
+ if (centerColumns.includes(index)) {
576
+ return centerText(headerText, columnWidths[index]);
32
577
  }
578
+ return padRight(headerText, columnWidths[index]);
579
+ }).join(" ");
580
+ console.log(leftPadding + headerRow);
581
+ console.log(leftPadding + separator);
582
+ for (const row of data) {
583
+ const dataRow = keys.map((key, index) => {
584
+ let text = String(row[key]);
585
+ if (key === "transport") {
586
+ text = render(text);
587
+ }
588
+ if (key === "status") {
589
+ text = render3(text);
590
+ }
591
+ if (key === "name") {
592
+ text = render4(text);
593
+ }
594
+ if (centerColumns.includes(index)) {
595
+ return centerText(text, columnWidths[index]);
596
+ }
597
+ return padRight(text, columnWidths[index]);
598
+ }).join(" ");
599
+ console.log(leftPadding + dataRow);
33
600
  }
34
- return files;
601
+ console.log("\n");
602
+ console.log(`${leftPadding}\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584\u2584`);
603
+ }
604
+ // Example mocked data for rendering the group information
605
+ // const mcpGroupDataMock = [
606
+ // { key: 'PROVIDER', value: 'Claude Desktop', },
607
+ // { key: 'FILE', value: '~/Library/Application Support/Claude/claude_desktop_config.json' },
608
+ // { key: 'STATUS', value: '[✓ VALID] [GLOBAL] [5 MCP SERVERS]' }
609
+ // ]
610
+ static printMcpGroup(id, data, groupMetadata = {}) {
611
+ if (data.length === 0) return;
612
+ console.log("\n");
613
+ const headers = ["KEY", "VALUE"];
614
+ const keys = ["key", "value"];
615
+ const indexText = `[${id}]`;
616
+ const leftPaddingGroupLead = indexText + " ".repeat(6 - indexText.length);
617
+ const leftPaddingGroupData = " ".repeat(6);
618
+ if (Object.keys(groupMetadata).length > 0) {
619
+ const runningCount = groupMetadata.mcpServersRunning || 0;
620
+ const totalCount = groupMetadata.mcpServersTotal || 0;
621
+ const metadataRow = this.renderProgressBar(runningCount, totalCount, "Running");
622
+ data.push({ key: "MCP SERVERS", value: metadataRow });
623
+ }
624
+ const columnWidths = headers.map((header, index) => {
625
+ const dataWidth = Math.max(...data.map((row) => {
626
+ const columnText = render2(row[keys[index]]);
627
+ const columnTextLength = this.getVisibleLength(columnText);
628
+ return columnTextLength;
629
+ }));
630
+ return Math.max(header.length, dataWidth);
631
+ });
632
+ for (const [index, row] of data.entries()) {
633
+ const dataRow = keys.map((key, index2) => {
634
+ const paddingNormalizer = render2(row[key]).length - row[key].length;
635
+ if (key === "key") {
636
+ return render2(row[key]).padEnd(columnWidths[index2] + paddingNormalizer);
637
+ }
638
+ if (row["key"] === "FILE") {
639
+ return render5(row[key]).padEnd(columnWidths[index2] + paddingNormalizer);
640
+ }
641
+ if (row["key"] === "PARSABLE") {
642
+ return render6(row[key]).padEnd(columnWidths[index2] + paddingNormalizer);
643
+ }
644
+ return String(row[key]).padEnd(columnWidths[index2] + paddingNormalizer);
645
+ }).join(" ");
646
+ const leftPadding = index === 0 ? leftPaddingGroupLead : leftPaddingGroupData;
647
+ console.log(leftPadding + dataRow);
648
+ }
649
+ }
650
+ // draws progress bar components like this
651
+ // "███████░░░░░░░░░░░░░ 3 / 9 Running"
652
+ static renderProgressBar(count, total, label, width = 20) {
653
+ if (total === 0) {
654
+ const emptyBar = "\u2591".repeat(width);
655
+ return `${emptyBar} 0 / 0 ${label}`;
656
+ }
657
+ const progress = Math.min(count / total, 1);
658
+ const filledWidth = Math.round(progress * width);
659
+ const emptyWidth = width - filledWidth;
660
+ let filled;
661
+ let empty;
662
+ if (count > 0) {
663
+ filled = styleText7(["greenBright"], "\u2588".repeat(filledWidth));
664
+ empty = styleText7(["green"], "\u2591".repeat(emptyWidth));
665
+ } else {
666
+ filled = "\u2588".repeat(filledWidth);
667
+ empty = "\u2591".repeat(emptyWidth);
668
+ }
669
+ return `${filled}${empty} ${count} / ${total} ${label}`;
35
670
  }
36
671
  };
37
672
 
38
673
  // src/bin/cli.ts
39
- var debug = debuglog("ls-mcp");
674
+ console.log();
40
675
  async function init() {
41
676
  const mcpFilesManager = new MCPFiles();
42
677
  const mcpFilesList = await mcpFilesManager.findFiles();
43
- if (mcpFilesList.length > 0) {
44
- console.log("MCP files found:");
45
- mcpFilesList.forEach((file) => {
46
- console.log(`- ${file}`);
47
- });
48
- } else {
678
+ if (Object.keys(mcpFilesList).length === 0) {
49
679
  console.log("No MCP files found.");
680
+ return;
681
+ }
682
+ let pathIndex = 0;
683
+ for (const groupName of Object.keys(mcpFilesList)) {
684
+ const group = mcpFilesList[groupName];
685
+ if (group.paths.length >= 0) {
686
+ for (const filePathData of group.paths) {
687
+ pathIndex++;
688
+ const filePath = filePathData.filePath.replace("~", process.env.HOME || "");
689
+ const filePathValid = filePathData.parsable ? "VALID" : "INVALID";
690
+ const filePathDataType = filePathData.type.toUpperCase();
691
+ const mcpServers = filePathData.servers || [];
692
+ const totalMCPServers = filePathData.servers ? filePathData.servers.length : 0;
693
+ const totalMCPServersRunning = mcpServers.filter((server) => server.status === "running").length;
694
+ const mcpGroupData = [
695
+ { key: "PROVIDER", value: group.friendlyName },
696
+ { key: "FILE", value: filePath },
697
+ { key: "TYPE", value: filePathDataType },
698
+ { key: "PARSABLE", value: filePathValid }
699
+ ];
700
+ const groupMetadata = {
701
+ mcpServersTotal: totalMCPServers,
702
+ mcpServersRunning: totalMCPServersRunning
703
+ };
704
+ RenderService.printMcpGroup(pathIndex, mcpGroupData, groupMetadata);
705
+ RenderService.printMcpServers(mcpServers);
706
+ }
707
+ } else {
708
+ console.log("No files found in this group.");
709
+ }
50
710
  }
51
711
  }
52
712
  __name(init, "init");
53
- init();
713
+ init().then(() => {
714
+ console.log("\n");
715
+ });