ls-mcp 1.1.0 → 1.2.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
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env node
2
1
  "use strict";
3
2
  var __create = Object.create;
4
3
  var __defProp = Object.defineProperty;
@@ -24,52 +23,402 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
23
  mod
25
24
  ));
26
25
 
27
- // src/bin/cli.ts
28
- var import_node_util = require("util");
29
-
30
26
  // src/main.ts
27
+ var import_promises2 = __toESM(require("fs/promises"), 1);
28
+
29
+ // src/services/mcp-config-linter-service.ts
31
30
  var import_promises = __toESM(require("fs/promises"), 1);
31
+ var MCPConfigLinterService = class {
32
+ static {
33
+ __name(this, "MCPConfigLinterService");
34
+ }
35
+ filePath;
36
+ fileContents = null;
37
+ constructor(filePath) {
38
+ this.filePath = filePath;
39
+ }
40
+ async isValidSyntax() {
41
+ try {
42
+ const fileContent = await this.getFileContent();
43
+ JSON.parse(fileContent);
44
+ return true;
45
+ } catch (error) {
46
+ return false;
47
+ }
48
+ }
49
+ async countMCPServers() {
50
+ const mcpServers = await this.getMCPServers();
51
+ return Object.keys(mcpServers).length;
52
+ }
53
+ async getMCPServers() {
54
+ const fileContentRaw = await this.getFileContent();
55
+ const fileContentsData = JSON.parse(fileContentRaw);
56
+ const mcpServers = fileContentsData?.mcpServers;
57
+ return mcpServers;
58
+ }
59
+ async getFileContent() {
60
+ if (this.fileContents) {
61
+ return this.fileContents;
62
+ }
63
+ this.fileContents = await import_promises.default.readFile(this.filePath, "utf-8");
64
+ return this.fileContents;
65
+ }
66
+ };
67
+
68
+ // src/services/mcp-server-manager-service.ts
69
+ var MCPServerManagerService = class {
70
+ static {
71
+ __name(this, "MCPServerManagerService");
72
+ }
73
+ name;
74
+ command;
75
+ args;
76
+ transport;
77
+ env;
78
+ running = false;
79
+ constructor(serverConfig) {
80
+ this.name = serverConfig.name;
81
+ this.command = serverConfig.command;
82
+ this.args = serverConfig.args || [];
83
+ this.transport = serverConfig.transport || "stdio";
84
+ this.env = serverConfig.env || {};
85
+ }
86
+ getName() {
87
+ return this.name;
88
+ }
89
+ getCmd() {
90
+ return this.command;
91
+ }
92
+ getArgs() {
93
+ return this.args;
94
+ }
95
+ getTransport() {
96
+ return this.transport;
97
+ }
98
+ getEnv() {
99
+ return this.env;
100
+ }
101
+ isRunning() {
102
+ return this.running;
103
+ }
104
+ };
105
+
106
+ // src/main.ts
32
107
  var MCPFiles = class {
33
108
  static {
34
109
  __name(this, "MCPFiles");
35
110
  }
36
- mcpFilePaths = [
37
- "~/Library/Application Support/Claude/claude_desktop_config.json",
38
- ".cursor/mcp.json",
39
- "~/.cursor/mcp.json"
40
- ];
41
- constructor(mcpFilePaths) {
42
- if (mcpFilePaths) {
43
- this.mcpFilePaths = mcpFilePaths;
111
+ mcpFilePathGroups = {
112
+ claude: {
113
+ name: "claude",
114
+ friendlyName: "Claude Desktop",
115
+ paths: [
116
+ { filePath: "~/Library/Application Support/Claude/claude_desktop_config.json", type: "global" }
117
+ ]
118
+ },
119
+ cursor: {
120
+ name: "cursor",
121
+ friendlyName: "Cursor",
122
+ paths: [
123
+ { filePath: ".cursor/mcp.json", type: "local" },
124
+ { filePath: "~/.cursor/mcp.json", type: "global" }
125
+ ]
44
126
  }
127
+ };
128
+ constructor(mcpFilePathGroups) {
129
+ this.mcpFilePathGroups = mcpFilePathGroups || this.mcpFilePathGroups;
45
130
  }
46
131
  async findFiles() {
47
- const files = [];
48
- for (const path of this.mcpFilePaths) {
49
- try {
50
- const resolvedPath = path.replace("~", process.env.HOME || "");
51
- await import_promises.default.access(resolvedPath);
52
- files.push(resolvedPath);
53
- } catch (error) {
132
+ const mcpFilesPathsData = {};
133
+ for (const groupName of Object.keys(this.mcpFilePathGroups)) {
134
+ const clientsGroup = this.mcpFilePathGroups[groupName];
135
+ mcpFilesPathsData[groupName] = {
136
+ name: clientsGroup.name,
137
+ friendlyName: clientsGroup.friendlyName,
138
+ paths: [],
139
+ stats: {}
140
+ };
141
+ for (const filePathData of clientsGroup.paths) {
142
+ const resolvedPath = filePathData.filePath.replace("~", process.env.HOME || "");
143
+ try {
144
+ await import_promises2.default.access(resolvedPath);
145
+ const MCPConfigLinter = new MCPConfigLinterService(resolvedPath);
146
+ const parsable = await MCPConfigLinter.isValidSyntax();
147
+ filePathData.parsable = parsable;
148
+ const mcpServersData = [];
149
+ const mcpServersFromConfig = await MCPConfigLinter.getMCPServers();
150
+ for (const serverName of Object.keys(mcpServersFromConfig)) {
151
+ const serverConfigRaw = mcpServersFromConfig[serverName];
152
+ const serverConfig = {
153
+ name: serverName,
154
+ command: serverConfigRaw.command || "",
155
+ args: serverConfigRaw.args,
156
+ transport: serverConfigRaw.transport,
157
+ env: serverConfigRaw.env
158
+ };
159
+ const MCPServerManager = new MCPServerManagerService(serverConfig);
160
+ mcpServersData.push({
161
+ name: MCPServerManager.getName(),
162
+ command: MCPServerManager.getCmd(),
163
+ args: MCPServerManager.getArgs(),
164
+ transport: MCPServerManager.getTransport(),
165
+ env: MCPServerManager.getEnv(),
166
+ status: MCPServerManager.isRunning() ? "running" : "stopped"
167
+ });
168
+ }
169
+ filePathData.servers = mcpServersData;
170
+ mcpFilesPathsData[groupName]["stats"]["serversCount"] = await MCPConfigLinter.countMCPServers();
171
+ mcpFilesPathsData[groupName].paths.push(filePathData);
172
+ } catch (error) {
173
+ }
54
174
  }
55
175
  }
56
- return files;
176
+ return mcpFilesPathsData;
177
+ }
178
+ };
179
+
180
+ // src/services/render-service.ts
181
+ var import_node_util7 = require("util");
182
+
183
+ // src/components/transport.ts
184
+ var import_node_util = require("util");
185
+ function render(text) {
186
+ const formattedText = text.toUpperCase();
187
+ let data = "";
188
+ if (formattedText === "STDIO") {
189
+ data = (0, import_node_util.styleText)(["magenta"], formattedText);
190
+ }
191
+ if (formattedText === "SSE") {
192
+ data = (0, import_node_util.styleText)(["blue"], formattedText);
193
+ }
194
+ return data;
195
+ }
196
+ __name(render, "render");
197
+
198
+ // src/components/column-name.ts
199
+ var import_node_util2 = require("util");
200
+ function render2(text) {
201
+ const formattedText = String(text).toUpperCase();
202
+ const data = (0, import_node_util2.styleText)(["dim"], formattedText);
203
+ return data;
204
+ }
205
+ __name(render2, "render");
206
+
207
+ // src/components/mcp-server-status.ts
208
+ var import_node_util3 = require("util");
209
+ function render3(text) {
210
+ const formattedText = text.toLowerCase();
211
+ let data = "";
212
+ if (formattedText === "running") {
213
+ data = (0, import_node_util3.styleText)(["green"], "\u25CF");
214
+ } else {
215
+ data = (0, import_node_util3.styleText)(["red"], "\u25CB");
216
+ }
217
+ return data;
218
+ }
219
+ __name(render3, "render");
220
+
221
+ // src/components/mcp-server-name.ts
222
+ var import_node_util4 = require("util");
223
+ function render4(text) {
224
+ const formattedText = text.toLowerCase();
225
+ const data = (0, import_node_util4.styleText)(["bold", "white"], formattedText);
226
+ return data;
227
+ }
228
+ __name(render4, "render");
229
+
230
+ // src/components/file-path.ts
231
+ var import_node_util5 = require("util");
232
+ function render5(text) {
233
+ const formattedText = text;
234
+ const data = (0, import_node_util5.styleText)(["underline"], formattedText);
235
+ return data;
236
+ }
237
+ __name(render5, "render");
238
+
239
+ // src/components/mcp-servers-config-parsable.ts
240
+ var import_node_util6 = require("util");
241
+ function render6(text) {
242
+ const formattedText = text.toUpperCase().replace(/_/g, " ");
243
+ let data = formattedText;
244
+ if (formattedText === "VALID") {
245
+ data = (0, import_node_util6.styleText)(["green"], formattedText);
246
+ } else {
247
+ data = (0, import_node_util6.styleText)(["red"], formattedText);
248
+ }
249
+ return data;
250
+ }
251
+ __name(render6, "render");
252
+
253
+ // src/services/render-service.ts
254
+ var RenderService = class {
255
+ static {
256
+ __name(this, "RenderService");
257
+ }
258
+ // Example mocked data for rendering the servers information
259
+ // const mcpServersDataMock = [
260
+ // { status: '●', name: 'logging-server', type: 'SSE', version: '2.3.0', tools: '6', resources: '2' },
261
+ // { status: '●', name: 'git-logging-server', type: 'SSE', version: '2.3.0', tools: '6', resources: '2' },
262
+ // { status: '○', name: 'mcp-server', type: 'STDIO', version: '2.3.0', tools: '62', resources: '0' }
263
+ // ]
264
+ static getVisibleLength(text) {
265
+ return text.replace(/\u001b\[[0-9;]*m/g, "").length;
266
+ }
267
+ static printMcpServers(data) {
268
+ if (data.length === 0) return;
269
+ const headers = ["STATUS", "NAME", "TRANSPORT"];
270
+ const keys = ["status", "name", "transport"];
271
+ const centerColumns = [0, 2, 4, 5];
272
+ const leftPadding = " ";
273
+ const columnWidths = headers.map((header, index) => {
274
+ const dataWidth = Math.max(...data.map((row) => String(row[keys[index]]).length));
275
+ return Math.max(header.length, dataWidth);
276
+ });
277
+ const centerText = /* @__PURE__ */ __name((text, width) => {
278
+ const padding = width - this.getVisibleLength(text);
279
+ const leftPad = Math.floor(padding / 2);
280
+ const rightPad = padding - leftPad;
281
+ return " ".repeat(leftPad) + text + " ".repeat(rightPad);
282
+ }, "centerText");
283
+ const totalWidth = columnWidths.reduce((sum, width) => sum + width, 0) + (columnWidths.length - 1) * 2;
284
+ const separator = "\u2500".repeat(totalWidth);
285
+ console.log("\n" + leftPadding + separator);
286
+ const headerRow = headers.map((header, index) => {
287
+ const headerText = render2(header);
288
+ if (centerColumns.includes(index)) {
289
+ return centerText(headerText, columnWidths[index]);
290
+ }
291
+ const padding = columnWidths[index] - this.getVisibleLength(headerText);
292
+ return headerText + " ".repeat(Math.max(0, padding));
293
+ }).join(" ");
294
+ console.log(leftPadding + headerRow);
295
+ console.log(leftPadding + separator);
296
+ for (const row of data) {
297
+ const dataRow = keys.map((key, index) => {
298
+ let text = String(row[key]);
299
+ if (key === "transport") {
300
+ text = render(text);
301
+ }
302
+ if (key === "status") {
303
+ text = render3(text);
304
+ }
305
+ if (key === "name") {
306
+ text = render4(text);
307
+ }
308
+ if (centerColumns.includes(index)) {
309
+ return centerText(text, columnWidths[index]);
310
+ }
311
+ return text.padEnd(columnWidths[index]);
312
+ }).join(" ");
313
+ console.log(leftPadding + dataRow);
314
+ }
315
+ console.log("\n");
316
+ 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`);
317
+ }
318
+ // Example mocked data for rendering the group information
319
+ // const mcpGroupDataMock = [
320
+ // { key: 'PROVIDER', value: 'Claude Desktop', },
321
+ // { key: 'FILE', value: '~/Library/Application Support/Claude/claude_desktop_config.json' },
322
+ // { key: 'STATUS', value: '[✓ VALID] [GLOBAL] [5 MCP SERVERS]' }
323
+ // ]
324
+ static printMcpGroup(id, data, groupMetadata = {}) {
325
+ if (data.length === 0) return;
326
+ console.log("\n");
327
+ const headers = ["KEY", "VALUE"];
328
+ const keys = ["key", "value"];
329
+ const indexText = `[${id}]`;
330
+ const leftPaddingGroupLead = indexText + " ".repeat(6 - indexText.length);
331
+ const leftPaddingGroupData = " ".repeat(6);
332
+ if (Object.keys(groupMetadata).length > 0) {
333
+ const runningCount = groupMetadata.mcpServersRunning || 0;
334
+ const totalCount = groupMetadata.mcpServersTotal || 0;
335
+ const metadataRow = this.renderProgressBar(runningCount, totalCount, "Running");
336
+ data.push({ key: "MCP SERVERS", value: metadataRow });
337
+ }
338
+ const columnWidths = headers.map((header, index) => {
339
+ const dataWidth = Math.max(...data.map((row) => {
340
+ const columnText = render2(row[keys[index]]);
341
+ const columnTextLength = this.getVisibleLength(columnText);
342
+ return columnTextLength;
343
+ }));
344
+ return Math.max(header.length, dataWidth);
345
+ });
346
+ for (const [index, row] of data.entries()) {
347
+ const dataRow = keys.map((key, index2) => {
348
+ const paddingNormalizer = render2(row[key]).length - row[key].length;
349
+ if (key === "key") {
350
+ return render2(row[key]).padEnd(columnWidths[index2] + paddingNormalizer);
351
+ }
352
+ if (row["key"] === "FILE") {
353
+ return render5(row[key]).padEnd(columnWidths[index2] + paddingNormalizer);
354
+ }
355
+ if (row["key"] === "PARSABLE") {
356
+ return render6(row[key]).padEnd(columnWidths[index2] + paddingNormalizer);
357
+ }
358
+ return String(row[key]).padEnd(columnWidths[index2] + paddingNormalizer);
359
+ }).join(" ");
360
+ const leftPadding = index === 0 ? leftPaddingGroupLead : leftPaddingGroupData;
361
+ console.log(leftPadding + dataRow);
362
+ }
363
+ }
364
+ // draws progress bar components like this
365
+ // "███████░░░░░░░░░░░░░ 3 / 9 Running"
366
+ static renderProgressBar(count, total, label, width = 20) {
367
+ if (total === 0) {
368
+ const emptyBar = "\u2591".repeat(width);
369
+ return `${emptyBar} 0 / 0 ${label}`;
370
+ }
371
+ const progress = Math.min(count / total, 1);
372
+ const filledWidth = Math.round(progress * width);
373
+ const emptyWidth = width - filledWidth;
374
+ const colorRunning = count > 0 ? "greenBright" : "red";
375
+ const colorEmpty = count > 0 ? "green" : "red";
376
+ const filled = (0, import_node_util7.styleText)([colorRunning], "\u2588".repeat(filledWidth));
377
+ const empty = (0, import_node_util7.styleText)([colorEmpty], "\u2591".repeat(emptyWidth));
378
+ return `${filled}${empty} ${count} / ${total} ${label}`;
57
379
  }
58
380
  };
59
381
 
60
382
  // src/bin/cli.ts
61
- var debug = (0, import_node_util.debuglog)("ls-mcp");
383
+ console.log();
62
384
  async function init() {
63
385
  const mcpFilesManager = new MCPFiles();
64
386
  const mcpFilesList = await mcpFilesManager.findFiles();
65
- if (mcpFilesList.length > 0) {
66
- console.log("MCP files found:");
67
- mcpFilesList.forEach((file) => {
68
- console.log(`- ${file}`);
69
- });
70
- } else {
387
+ if (Object.keys(mcpFilesList).length === 0) {
71
388
  console.log("No MCP files found.");
389
+ return;
390
+ }
391
+ let groupIndex = 0;
392
+ for (const groupName of Object.keys(mcpFilesList)) {
393
+ groupIndex++;
394
+ const group = mcpFilesList[groupName];
395
+ if (group.paths.length >= 0) {
396
+ for (const filePathData of group.paths) {
397
+ const filePath = filePathData.filePath.replace("~", process.env.HOME || "");
398
+ const filePathValid = filePathData.parsable ? "VALID" : "INVALID";
399
+ const filePathDataType = filePathData.type.toUpperCase();
400
+ const mcpServers = filePathData.servers || [];
401
+ const totalMCPServers = filePathData.servers ? filePathData.servers.length : 0;
402
+ const totalMCPServersRunning = mcpServers.filter((server) => server.status === "running").length;
403
+ const mcpGroupData = [
404
+ { key: "PROVIDER", value: group.friendlyName },
405
+ { key: "FILE", value: filePath },
406
+ { key: "PARSABLE", value: filePathValid },
407
+ { key: "TYPE", value: filePathDataType }
408
+ ];
409
+ const groupMetadata = {
410
+ mcpServersTotal: totalMCPServers,
411
+ mcpServersRunning: totalMCPServersRunning
412
+ };
413
+ RenderService.printMcpGroup(groupIndex, mcpGroupData, groupMetadata);
414
+ RenderService.printMcpServers(mcpServers);
415
+ }
416
+ } else {
417
+ console.log("No files found in this group.");
418
+ }
72
419
  }
73
420
  }
74
421
  __name(init, "init");
75
- init();
422
+ init().then(() => {
423
+ console.log("\n");
424
+ });
@@ -1 +1,2 @@
1
- #!/usr/bin/env node
1
+
2
+ export { }
package/dist/bin/cli.d.ts CHANGED
@@ -1 +1,2 @@
1
- #!/usr/bin/env node
1
+
2
+ export { }