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.cjs +689 -27
- package/dist/bin/cli.mjs +689 -27
- package/dist/main.cjs +429 -16
- package/dist/main.d.cts +35 -3
- package/dist/main.d.ts +35 -3
- package/dist/main.mjs +429 -16
- package/package.json +12 -9
- package/src/bin/cli.ts +62 -12
- package/src/components/column-name.ts +8 -0
- package/src/components/file-path.ts +8 -0
- package/src/components/mcp-server-name.ts +9 -0
- package/src/components/mcp-server-status.ts +13 -0
- package/src/components/mcp-servers-config-parsable.ts +13 -0
- package/src/components/transport.ts +15 -0
- package/src/main.ts +118 -22
- package/src/services/mcp-config-linter-service.ts +43 -0
- package/src/services/mcp-server-manager-service.ts +460 -0
- package/src/services/render-service.ts +213 -0
- package/src/utils/formatter-service.ts +7 -0
package/dist/bin/cli.cjs
CHANGED
|
@@ -24,52 +24,714 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
mod
|
|
25
25
|
));
|
|
26
26
|
|
|
27
|
-
// src/bin/cli.ts
|
|
28
|
-
var import_node_util = require("util");
|
|
29
|
-
|
|
30
27
|
// src/main.ts
|
|
28
|
+
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
29
|
+
|
|
30
|
+
// src/services/mcp-config-linter-service.ts
|
|
31
31
|
var import_promises = __toESM(require("fs/promises"), 1);
|
|
32
|
+
var MCPConfigLinterService = class {
|
|
33
|
+
static {
|
|
34
|
+
__name(this, "MCPConfigLinterService");
|
|
35
|
+
}
|
|
36
|
+
filePath;
|
|
37
|
+
fileContents = null;
|
|
38
|
+
constructor(filePath) {
|
|
39
|
+
this.filePath = filePath;
|
|
40
|
+
}
|
|
41
|
+
async isValidSyntax() {
|
|
42
|
+
try {
|
|
43
|
+
const fileContent = await this.getFileContent();
|
|
44
|
+
JSON.parse(fileContent);
|
|
45
|
+
return true;
|
|
46
|
+
} catch (error) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async countMCPServers() {
|
|
51
|
+
const mcpServers = await this.getMCPServers();
|
|
52
|
+
return Object.keys(mcpServers).length;
|
|
53
|
+
}
|
|
54
|
+
async getMCPServers() {
|
|
55
|
+
const fileContentRaw = await this.getFileContent();
|
|
56
|
+
const fileContentsData = JSON.parse(fileContentRaw);
|
|
57
|
+
const mcpServers = fileContentsData?.mcpServers;
|
|
58
|
+
return mcpServers;
|
|
59
|
+
}
|
|
60
|
+
async getFileContent() {
|
|
61
|
+
if (this.fileContents) {
|
|
62
|
+
return this.fileContents;
|
|
63
|
+
}
|
|
64
|
+
this.fileContents = await import_promises.default.readFile(this.filePath, "utf-8");
|
|
65
|
+
return this.fileContents;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// src/services/mcp-server-manager-service.ts
|
|
70
|
+
var import_node_child_process = require("child_process");
|
|
71
|
+
var import_node_os = require("os");
|
|
72
|
+
var MCPServerManagerService = class {
|
|
73
|
+
static {
|
|
74
|
+
__name(this, "MCPServerManagerService");
|
|
75
|
+
}
|
|
76
|
+
name;
|
|
77
|
+
command;
|
|
78
|
+
args;
|
|
79
|
+
transport;
|
|
80
|
+
env;
|
|
81
|
+
running = false;
|
|
82
|
+
constructor(serverConfig) {
|
|
83
|
+
this.name = serverConfig.name;
|
|
84
|
+
this.command = serverConfig.command;
|
|
85
|
+
this.args = serverConfig.args || [];
|
|
86
|
+
this.transport = serverConfig.transport || "stdio";
|
|
87
|
+
this.env = serverConfig.env || {};
|
|
88
|
+
}
|
|
89
|
+
getName() {
|
|
90
|
+
return this.name;
|
|
91
|
+
}
|
|
92
|
+
getCmd() {
|
|
93
|
+
return this.command;
|
|
94
|
+
}
|
|
95
|
+
getArgs() {
|
|
96
|
+
return this.args;
|
|
97
|
+
}
|
|
98
|
+
getTransport() {
|
|
99
|
+
return this.transport;
|
|
100
|
+
}
|
|
101
|
+
getEnv() {
|
|
102
|
+
return this.env;
|
|
103
|
+
}
|
|
104
|
+
isRunning() {
|
|
105
|
+
try {
|
|
106
|
+
let psOutput;
|
|
107
|
+
if ((0, import_node_os.platform)() === "win32") {
|
|
108
|
+
psOutput = (0, import_node_child_process.execSync)("wmic process get ProcessId,ParentProcessId,CommandLine /format:csv", {
|
|
109
|
+
encoding: "utf8",
|
|
110
|
+
timeout: 5e3
|
|
111
|
+
});
|
|
112
|
+
} else {
|
|
113
|
+
psOutput = (0, import_node_child_process.execSync)("ps -eao pid,ppid,args", {
|
|
114
|
+
encoding: "utf8",
|
|
115
|
+
timeout: 5e3
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
const processMap = /* @__PURE__ */ new Map();
|
|
119
|
+
const processes = psOutput.trim().split("\n");
|
|
120
|
+
for (const processLine of processes) {
|
|
121
|
+
if (!processLine.trim()) continue;
|
|
122
|
+
let pid;
|
|
123
|
+
let ppid;
|
|
124
|
+
let commandLine;
|
|
125
|
+
if ((0, import_node_os.platform)() === "win32") {
|
|
126
|
+
const parts = processLine.split(",");
|
|
127
|
+
if (parts.length < 4) continue;
|
|
128
|
+
commandLine = parts[1] || "";
|
|
129
|
+
ppid = parts[2] || "";
|
|
130
|
+
pid = parts[3] || "";
|
|
131
|
+
} else {
|
|
132
|
+
const match = processLine.trim().match(/^\s*(\d+)\s+(\d+)\s+(.+)$/);
|
|
133
|
+
if (!match) continue;
|
|
134
|
+
pid = match[1];
|
|
135
|
+
ppid = match[2];
|
|
136
|
+
commandLine = match[3];
|
|
137
|
+
}
|
|
138
|
+
const commandTokens = this.parseCommandLine(commandLine);
|
|
139
|
+
if (commandTokens.length > 0) {
|
|
140
|
+
processMap.set(pid, { ppid, commandTokens });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
let mcpServerDetection;
|
|
144
|
+
for (const [pid, processData] of processMap) {
|
|
145
|
+
if (this.isCommandMatch(processData.commandTokens, pid, processData.ppid)) {
|
|
146
|
+
mcpServerDetection = {
|
|
147
|
+
pid,
|
|
148
|
+
commandLine: processData.commandTokens.join(" "),
|
|
149
|
+
ppid: processData.ppid
|
|
150
|
+
};
|
|
151
|
+
const parentProcess = processMap.get(processData.ppid);
|
|
152
|
+
if (parentProcess) {
|
|
153
|
+
const { estimatedVendor, estimatedProduct } = this.getVendorFromCommand(parentProcess.commandTokens) || {};
|
|
154
|
+
if (estimatedProduct || estimatedVendor) {
|
|
155
|
+
mcpServerDetection = {
|
|
156
|
+
...mcpServerDetection,
|
|
157
|
+
parentCommandLine: parentProcess.commandTokens.join(" "),
|
|
158
|
+
estimatedVendor,
|
|
159
|
+
estimatedProduct
|
|
160
|
+
};
|
|
161
|
+
return mcpServerDetection;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (mcpServerDetection) {
|
|
167
|
+
return mcpServerDetection;
|
|
168
|
+
}
|
|
169
|
+
return false;
|
|
170
|
+
} catch (error) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
getVendorFromCommand(commandTokens) {
|
|
175
|
+
const commandString = commandTokens.join(" ").toLowerCase();
|
|
176
|
+
if (commandString.includes("claude.app")) {
|
|
177
|
+
return {
|
|
178
|
+
estimatedVendor: "anthropic",
|
|
179
|
+
estimatedProduct: "claude-desktop"
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
if (commandString.includes("claude")) {
|
|
183
|
+
return {
|
|
184
|
+
estimatedVendor: "anthropic",
|
|
185
|
+
estimatedProduct: "claude-desktop"
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
isCommandMatch(commandTokens, pid, ppid) {
|
|
190
|
+
if (commandTokens.length === 0) return false;
|
|
191
|
+
const baseCommand = this.getBaseCommand(commandTokens[0]);
|
|
192
|
+
if (this.command === "uvx" && baseCommand === "uv") {
|
|
193
|
+
return this.matchUvxProcess(commandTokens);
|
|
194
|
+
}
|
|
195
|
+
if (this.command === "npx" && baseCommand === "npm") {
|
|
196
|
+
return this.matchNpxProcess(commandTokens);
|
|
197
|
+
}
|
|
198
|
+
if (this.command === "uv" && baseCommand === "uv") {
|
|
199
|
+
return this.matchGenericArgsToArgs(commandTokens);
|
|
200
|
+
}
|
|
201
|
+
const commandConfigPythonBase = this.getBaseCommand(this.command);
|
|
202
|
+
const commandAliasesPython = ["python3", "python", "python3.10", "python3.11", "python3.12", "cpython3", "cpython", "python3", "python2"];
|
|
203
|
+
if (commandAliasesPython.includes(commandConfigPythonBase) && commandAliasesPython.includes(baseCommand)) {
|
|
204
|
+
return this.matchGenericArgsToArgs(commandTokens);
|
|
205
|
+
}
|
|
206
|
+
const commandGenericBase = this.getBaseCommand(this.command);
|
|
207
|
+
const commandGenericProcessBase = this.getBaseCommand(commandTokens[0]);
|
|
208
|
+
if (commandGenericBase === commandGenericProcessBase) {
|
|
209
|
+
return this.matchGenericArgsToArgs(commandTokens);
|
|
210
|
+
}
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
matchGenericArgsToArgs(commandTokens) {
|
|
214
|
+
if (this.args.length === 0) {
|
|
215
|
+
return commandTokens[0] === this.command;
|
|
216
|
+
}
|
|
217
|
+
if (commandTokens.length < 2) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
const commandWithoutArgs = commandTokens.slice(1);
|
|
221
|
+
for (let i = 0; i < this.args.length; i++) {
|
|
222
|
+
if (i >= commandWithoutArgs.length) return false;
|
|
223
|
+
const arg = this.args[i];
|
|
224
|
+
const token = commandWithoutArgs[i];
|
|
225
|
+
if (arg !== token && !token.includes(arg)) {
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return true;
|
|
230
|
+
}
|
|
231
|
+
// @TODO refactor this to use path.basename or similar
|
|
232
|
+
// to extract the base command from the full command path
|
|
233
|
+
getBaseCommand(fullCommandPath) {
|
|
234
|
+
const parts = fullCommandPath.split(/[/\\]/);
|
|
235
|
+
return parts[parts.length - 1];
|
|
236
|
+
}
|
|
237
|
+
/*
|
|
238
|
+
example1:
|
|
239
|
+
```
|
|
240
|
+
"command": "uvx",
|
|
241
|
+
"args": ["--from", "mcp-alchemy==2025.5.2.210242", "--with", "oracledb",
|
|
242
|
+
"--refresh-package", "mcp-alchemy", "mcp-alchemy"],
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
example 2:
|
|
246
|
+
```
|
|
247
|
+
"command": "uvx",
|
|
248
|
+
"args": [
|
|
249
|
+
"mcp-neo4j-memory@0.1.4",
|
|
250
|
+
"--db-url",
|
|
251
|
+
"neo4j+s://xxxx.databases.neo4j.io",
|
|
252
|
+
"--username",
|
|
253
|
+
"<your-username>",
|
|
254
|
+
"--password",
|
|
255
|
+
"<your-password>"
|
|
256
|
+
]
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
example 3:
|
|
260
|
+
```
|
|
261
|
+
"vefaas": {
|
|
262
|
+
"command": "uvx",
|
|
263
|
+
"args": [
|
|
264
|
+
"--from",
|
|
265
|
+
"git+https://github.com/volcengine/mcp-server#subdirectory=server/mcp_server_vefaas_function",
|
|
266
|
+
"mcp-server-vefaas-function"
|
|
267
|
+
],
|
|
268
|
+
"env": {
|
|
269
|
+
"VOLC_ACCESSKEY": "xxx",
|
|
270
|
+
"VOLC_SECRETKEY": "xxx"
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
example 4:
|
|
277
|
+
```
|
|
278
|
+
"time": {
|
|
279
|
+
"command": "uvx",
|
|
280
|
+
"args": ["mcp-server-time", "--local-timezone=America/New_York"]
|
|
281
|
+
}
|
|
282
|
+
```
|
|
283
|
+
*/
|
|
284
|
+
getUvxMcpServerNameFromArgs() {
|
|
285
|
+
if (this.args.length === 0) return void 0;
|
|
286
|
+
let mcpServerName;
|
|
287
|
+
if (this.args.length === 1) {
|
|
288
|
+
mcpServerName = this.args[0];
|
|
289
|
+
return mcpServerName;
|
|
290
|
+
}
|
|
291
|
+
for (let i = 0; i < this.args.length; i++) {
|
|
292
|
+
if (this.args[i] === "--from" && i + 1 < this.args.length) {
|
|
293
|
+
mcpServerName = this.args[i + 1];
|
|
294
|
+
return mcpServerName;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
const firstArg = this.args[0];
|
|
298
|
+
if (firstArg.startsWith("-") || firstArg.startsWith("--")) {
|
|
299
|
+
const lastArg = this.args[this.args.length - 1];
|
|
300
|
+
mcpServerName = lastArg;
|
|
301
|
+
return mcpServerName;
|
|
302
|
+
}
|
|
303
|
+
mcpServerName = firstArg;
|
|
304
|
+
return mcpServerName;
|
|
305
|
+
}
|
|
306
|
+
matchUvxProcess(commandTokens) {
|
|
307
|
+
if (commandTokens.length === 0) return false;
|
|
308
|
+
const mcpServerName = this.getUvxMcpServerNameFromArgs();
|
|
309
|
+
if (!mcpServerName) return false;
|
|
310
|
+
return this.findMcpServerNameInProcessArguments(commandTokens, mcpServerName);
|
|
311
|
+
}
|
|
312
|
+
findMcpServerNameInProcessArguments(commandTokens, mcpServerName) {
|
|
313
|
+
for (let i = 0; i < commandTokens.length; i++) {
|
|
314
|
+
const token = commandTokens[i];
|
|
315
|
+
if (mcpServerName === token || token.includes(mcpServerName)) {
|
|
316
|
+
return true;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
321
|
+
parseCommandLine(commandLine) {
|
|
322
|
+
const tokens = [];
|
|
323
|
+
let current = "";
|
|
324
|
+
let inQuotes = false;
|
|
325
|
+
let quoteChar = "";
|
|
326
|
+
for (let i = 0; i < commandLine.length; i++) {
|
|
327
|
+
const char = commandLine[i];
|
|
328
|
+
if (!inQuotes && (char === '"' || char === "'")) {
|
|
329
|
+
inQuotes = true;
|
|
330
|
+
quoteChar = char;
|
|
331
|
+
} else if (inQuotes && char === quoteChar) {
|
|
332
|
+
inQuotes = false;
|
|
333
|
+
quoteChar = "";
|
|
334
|
+
} else if (!inQuotes && char === " ") {
|
|
335
|
+
if (current.trim()) {
|
|
336
|
+
tokens.push(current.trim());
|
|
337
|
+
current = "";
|
|
338
|
+
}
|
|
339
|
+
} else {
|
|
340
|
+
current += char;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (current.trim()) {
|
|
344
|
+
tokens.push(current.trim());
|
|
345
|
+
}
|
|
346
|
+
return tokens;
|
|
347
|
+
}
|
|
348
|
+
/*
|
|
349
|
+
example to match:
|
|
350
|
+
```
|
|
351
|
+
"command": "npx",
|
|
352
|
+
"args": [
|
|
353
|
+
"-y",
|
|
354
|
+
"@modelcontextprotocol/server-postgres",
|
|
355
|
+
"postgresql://localhost/mydb"
|
|
356
|
+
]
|
|
357
|
+
}
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
with a process command like:
|
|
361
|
+
```
|
|
362
|
+
npm exec @modelcontextprotocol/server-postgres postgresql://localhost/mydb
|
|
363
|
+
```
|
|
364
|
+
*/
|
|
365
|
+
matchNpxProcess(commandTokens) {
|
|
366
|
+
if (commandTokens.length < 3) return false;
|
|
367
|
+
if (commandTokens[1] !== "exec") return false;
|
|
368
|
+
let argsToMatch = [];
|
|
369
|
+
const yIndex = this.args.indexOf("-y");
|
|
370
|
+
if (yIndex !== -1 && yIndex + 1 < this.args.length) {
|
|
371
|
+
argsToMatch = this.args.slice(yIndex + 1);
|
|
372
|
+
} else {
|
|
373
|
+
argsToMatch = this.args;
|
|
374
|
+
}
|
|
375
|
+
if (commandTokens.length - 2 !== argsToMatch.length) {
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
for (let i = 0; i < argsToMatch.length; i++) {
|
|
379
|
+
const commandToken = commandTokens[i + 2];
|
|
380
|
+
const expectedArg = argsToMatch[i];
|
|
381
|
+
if (commandToken !== expectedArg) {
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
return true;
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
// src/main.ts
|
|
32
390
|
var MCPFiles = class {
|
|
33
391
|
static {
|
|
34
392
|
__name(this, "MCPFiles");
|
|
35
393
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
394
|
+
mcpFilePathGroups = {
|
|
395
|
+
claude: {
|
|
396
|
+
name: "claude-desktop",
|
|
397
|
+
friendlyName: "Claude Desktop",
|
|
398
|
+
paths: [
|
|
399
|
+
{ filePath: "~/Library/Application Support/Claude/claude_desktop_config.json", type: "global" }
|
|
400
|
+
]
|
|
401
|
+
},
|
|
402
|
+
cursor: {
|
|
403
|
+
name: "cursor",
|
|
404
|
+
friendlyName: "Cursor",
|
|
405
|
+
paths: [
|
|
406
|
+
{ filePath: "~/.cursor/mcp.json", type: "global" },
|
|
407
|
+
{ filePath: ".cursor/mcp.json", type: "local" }
|
|
408
|
+
]
|
|
44
409
|
}
|
|
410
|
+
};
|
|
411
|
+
constructor(mcpFilePathGroups) {
|
|
412
|
+
this.mcpFilePathGroups = mcpFilePathGroups || this.mcpFilePathGroups;
|
|
45
413
|
}
|
|
46
414
|
async findFiles() {
|
|
47
|
-
const
|
|
48
|
-
for (const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
415
|
+
const mcpFilesPathsData = {};
|
|
416
|
+
for (const groupName of Object.keys(this.mcpFilePathGroups)) {
|
|
417
|
+
const clientsGroup = this.mcpFilePathGroups[groupName];
|
|
418
|
+
mcpFilesPathsData[groupName] = {
|
|
419
|
+
name: clientsGroup.name,
|
|
420
|
+
friendlyName: clientsGroup.friendlyName,
|
|
421
|
+
paths: [],
|
|
422
|
+
stats: {}
|
|
423
|
+
};
|
|
424
|
+
for (const filePathData of clientsGroup.paths) {
|
|
425
|
+
const resolvedPath = filePathData.filePath.replace("~", process.env.HOME || "");
|
|
426
|
+
try {
|
|
427
|
+
await import_promises2.default.access(resolvedPath);
|
|
428
|
+
const MCPConfigLinter = new MCPConfigLinterService(resolvedPath);
|
|
429
|
+
const parsable = await MCPConfigLinter.isValidSyntax();
|
|
430
|
+
filePathData.parsable = parsable;
|
|
431
|
+
const mcpServersData = [];
|
|
432
|
+
const mcpServersFromConfig = await MCPConfigLinter.getMCPServers();
|
|
433
|
+
for (const serverName of Object.keys(mcpServersFromConfig)) {
|
|
434
|
+
const serverConfigRaw = mcpServersFromConfig[serverName];
|
|
435
|
+
const serverConfig = {
|
|
436
|
+
name: serverName,
|
|
437
|
+
command: serverConfigRaw.command || "",
|
|
438
|
+
args: serverConfigRaw.args,
|
|
439
|
+
transport: serverConfigRaw.transport,
|
|
440
|
+
env: serverConfigRaw.env
|
|
441
|
+
};
|
|
442
|
+
const MCPServerManager = new MCPServerManagerService(serverConfig);
|
|
443
|
+
const mcpServerProcessDetection = MCPServerManager.isRunning();
|
|
444
|
+
let mcpServerProcess = false;
|
|
445
|
+
if (mcpServerProcessDetection) {
|
|
446
|
+
if (typeof mcpServerProcessDetection === "object" && mcpServerProcessDetection.estimatedProduct === clientsGroup.name) {
|
|
447
|
+
mcpServerProcess = true;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
mcpServersData.push({
|
|
451
|
+
name: MCPServerManager.getName(),
|
|
452
|
+
command: MCPServerManager.getCmd(),
|
|
453
|
+
args: MCPServerManager.getArgs(),
|
|
454
|
+
transport: MCPServerManager.getTransport(),
|
|
455
|
+
env: MCPServerManager.getEnv(),
|
|
456
|
+
status: mcpServerProcess ? "running" : "stopped"
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
filePathData.servers = mcpServersData;
|
|
460
|
+
mcpFilesPathsData[groupName]["stats"]["serversCount"] = await MCPConfigLinter.countMCPServers();
|
|
461
|
+
mcpFilesPathsData[groupName].paths.push(filePathData);
|
|
462
|
+
} catch (error) {
|
|
463
|
+
}
|
|
54
464
|
}
|
|
55
465
|
}
|
|
56
|
-
return
|
|
466
|
+
return mcpFilesPathsData;
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
// src/services/render-service.ts
|
|
471
|
+
var import_node_util7 = require("util");
|
|
472
|
+
|
|
473
|
+
// src/components/transport.ts
|
|
474
|
+
var import_node_util = require("util");
|
|
475
|
+
function render(text) {
|
|
476
|
+
const formattedText = text.toUpperCase();
|
|
477
|
+
let data = "";
|
|
478
|
+
if (formattedText === "STDIO") {
|
|
479
|
+
data = (0, import_node_util.styleText)(["magenta"], formattedText);
|
|
480
|
+
}
|
|
481
|
+
if (formattedText === "SSE") {
|
|
482
|
+
data = (0, import_node_util.styleText)(["blue"], formattedText);
|
|
483
|
+
}
|
|
484
|
+
return data;
|
|
485
|
+
}
|
|
486
|
+
__name(render, "render");
|
|
487
|
+
|
|
488
|
+
// src/components/column-name.ts
|
|
489
|
+
var import_node_util2 = require("util");
|
|
490
|
+
function render2(text) {
|
|
491
|
+
const formattedText = String(text).toUpperCase();
|
|
492
|
+
const data = (0, import_node_util2.styleText)(["dim"], formattedText);
|
|
493
|
+
return data;
|
|
494
|
+
}
|
|
495
|
+
__name(render2, "render");
|
|
496
|
+
|
|
497
|
+
// src/components/mcp-server-status.ts
|
|
498
|
+
var import_node_util3 = require("util");
|
|
499
|
+
function render3(text) {
|
|
500
|
+
const formattedText = text.toLowerCase();
|
|
501
|
+
let data = "";
|
|
502
|
+
if (formattedText === "running") {
|
|
503
|
+
data = (0, import_node_util3.styleText)(["green"], "\u25CF");
|
|
504
|
+
} else {
|
|
505
|
+
data = (0, import_node_util3.styleText)(["red"], "\u25CF");
|
|
506
|
+
}
|
|
507
|
+
return data;
|
|
508
|
+
}
|
|
509
|
+
__name(render3, "render");
|
|
510
|
+
|
|
511
|
+
// src/components/mcp-server-name.ts
|
|
512
|
+
var import_node_util4 = require("util");
|
|
513
|
+
function render4(text) {
|
|
514
|
+
const formattedText = text.toLowerCase();
|
|
515
|
+
const data = (0, import_node_util4.styleText)(["bold", "white"], formattedText);
|
|
516
|
+
return data;
|
|
517
|
+
}
|
|
518
|
+
__name(render4, "render");
|
|
519
|
+
|
|
520
|
+
// src/components/file-path.ts
|
|
521
|
+
var import_node_util5 = require("util");
|
|
522
|
+
function render5(text) {
|
|
523
|
+
const formattedText = text;
|
|
524
|
+
const data = (0, import_node_util5.styleText)(["underline"], formattedText);
|
|
525
|
+
return data;
|
|
526
|
+
}
|
|
527
|
+
__name(render5, "render");
|
|
528
|
+
|
|
529
|
+
// src/components/mcp-servers-config-parsable.ts
|
|
530
|
+
var import_node_util6 = require("util");
|
|
531
|
+
function render6(text) {
|
|
532
|
+
const formattedText = text.toUpperCase().replace(/_/g, " ");
|
|
533
|
+
let data = formattedText;
|
|
534
|
+
if (formattedText === "VALID") {
|
|
535
|
+
data = (0, import_node_util6.styleText)(["green"], "\u25CF");
|
|
536
|
+
} else {
|
|
537
|
+
data = (0, import_node_util6.styleText)(["red"], "\u25CF");
|
|
538
|
+
}
|
|
539
|
+
return data;
|
|
540
|
+
}
|
|
541
|
+
__name(render6, "render");
|
|
542
|
+
|
|
543
|
+
// src/services/render-service.ts
|
|
544
|
+
var RenderService = class {
|
|
545
|
+
static {
|
|
546
|
+
__name(this, "RenderService");
|
|
547
|
+
}
|
|
548
|
+
// Example mocked data for rendering the servers information
|
|
549
|
+
// const mcpServersDataMock = [
|
|
550
|
+
// { status: '●', name: 'logging-server', type: 'SSE', version: '2.3.0', tools: '6', resources: '2' },
|
|
551
|
+
// { status: '●', name: 'git-logging-server', type: 'SSE', version: '2.3.0', tools: '6', resources: '2' },
|
|
552
|
+
// { status: '○', name: 'mcp-server', type: 'STDIO', version: '2.3.0', tools: '62', resources: '0' }
|
|
553
|
+
// ]
|
|
554
|
+
static getVisibleLength(text) {
|
|
555
|
+
return text.replace(/\u001b\[[0-9;]*m/g, "").length;
|
|
556
|
+
}
|
|
557
|
+
static printMcpServers(data) {
|
|
558
|
+
if (data.length === 0) return;
|
|
559
|
+
const headers = ["STATUS", "NAME", "TRANSPORT"];
|
|
560
|
+
const keys = ["status", "name", "transport"];
|
|
561
|
+
const centerColumns = [0, 2];
|
|
562
|
+
const leftPadding = " ";
|
|
563
|
+
const columnWidths = headers.map((header, index) => {
|
|
564
|
+
const headerWidth = this.getVisibleLength(render2(header));
|
|
565
|
+
const dataWidth = Math.max(...data.map((row) => {
|
|
566
|
+
let text = String(row[keys[index]]);
|
|
567
|
+
if (keys[index] === "transport") {
|
|
568
|
+
text = render(text);
|
|
569
|
+
}
|
|
570
|
+
if (keys[index] === "status") {
|
|
571
|
+
text = render3(text);
|
|
572
|
+
}
|
|
573
|
+
if (keys[index] === "name") {
|
|
574
|
+
text = render4(text);
|
|
575
|
+
}
|
|
576
|
+
return this.getVisibleLength(text);
|
|
577
|
+
}));
|
|
578
|
+
return Math.max(headerWidth, dataWidth);
|
|
579
|
+
});
|
|
580
|
+
const centerText = /* @__PURE__ */ __name((text, width) => {
|
|
581
|
+
const visibleLength = this.getVisibleLength(text);
|
|
582
|
+
const padding = width - visibleLength;
|
|
583
|
+
const leftPad = Math.floor(padding / 2);
|
|
584
|
+
const rightPad = padding - leftPad;
|
|
585
|
+
return " ".repeat(leftPad) + text + " ".repeat(rightPad);
|
|
586
|
+
}, "centerText");
|
|
587
|
+
const padRight = /* @__PURE__ */ __name((text, width) => {
|
|
588
|
+
const visibleLength = this.getVisibleLength(text);
|
|
589
|
+
const padding = Math.max(0, width - visibleLength);
|
|
590
|
+
return text + " ".repeat(padding);
|
|
591
|
+
}, "padRight");
|
|
592
|
+
const totalWidth = columnWidths.reduce((sum, width) => sum + width, 0) + (columnWidths.length - 1) * 2;
|
|
593
|
+
const separator = "\u2500".repeat(totalWidth);
|
|
594
|
+
console.log("\n" + leftPadding + separator);
|
|
595
|
+
const headerRow = headers.map((header, index) => {
|
|
596
|
+
const headerText = render2(header);
|
|
597
|
+
if (centerColumns.includes(index)) {
|
|
598
|
+
return centerText(headerText, columnWidths[index]);
|
|
599
|
+
}
|
|
600
|
+
return padRight(headerText, columnWidths[index]);
|
|
601
|
+
}).join(" ");
|
|
602
|
+
console.log(leftPadding + headerRow);
|
|
603
|
+
console.log(leftPadding + separator);
|
|
604
|
+
for (const row of data) {
|
|
605
|
+
const dataRow = keys.map((key, index) => {
|
|
606
|
+
let text = String(row[key]);
|
|
607
|
+
if (key === "transport") {
|
|
608
|
+
text = render(text);
|
|
609
|
+
}
|
|
610
|
+
if (key === "status") {
|
|
611
|
+
text = render3(text);
|
|
612
|
+
}
|
|
613
|
+
if (key === "name") {
|
|
614
|
+
text = render4(text);
|
|
615
|
+
}
|
|
616
|
+
if (centerColumns.includes(index)) {
|
|
617
|
+
return centerText(text, columnWidths[index]);
|
|
618
|
+
}
|
|
619
|
+
return padRight(text, columnWidths[index]);
|
|
620
|
+
}).join(" ");
|
|
621
|
+
console.log(leftPadding + dataRow);
|
|
622
|
+
}
|
|
623
|
+
console.log("\n");
|
|
624
|
+
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`);
|
|
625
|
+
}
|
|
626
|
+
// Example mocked data for rendering the group information
|
|
627
|
+
// const mcpGroupDataMock = [
|
|
628
|
+
// { key: 'PROVIDER', value: 'Claude Desktop', },
|
|
629
|
+
// { key: 'FILE', value: '~/Library/Application Support/Claude/claude_desktop_config.json' },
|
|
630
|
+
// { key: 'STATUS', value: '[✓ VALID] [GLOBAL] [5 MCP SERVERS]' }
|
|
631
|
+
// ]
|
|
632
|
+
static printMcpGroup(id, data, groupMetadata = {}) {
|
|
633
|
+
if (data.length === 0) return;
|
|
634
|
+
console.log("\n");
|
|
635
|
+
const headers = ["KEY", "VALUE"];
|
|
636
|
+
const keys = ["key", "value"];
|
|
637
|
+
const indexText = `[${id}]`;
|
|
638
|
+
const leftPaddingGroupLead = indexText + " ".repeat(6 - indexText.length);
|
|
639
|
+
const leftPaddingGroupData = " ".repeat(6);
|
|
640
|
+
if (Object.keys(groupMetadata).length > 0) {
|
|
641
|
+
const runningCount = groupMetadata.mcpServersRunning || 0;
|
|
642
|
+
const totalCount = groupMetadata.mcpServersTotal || 0;
|
|
643
|
+
const metadataRow = this.renderProgressBar(runningCount, totalCount, "Running");
|
|
644
|
+
data.push({ key: "MCP SERVERS", value: metadataRow });
|
|
645
|
+
}
|
|
646
|
+
const columnWidths = headers.map((header, index) => {
|
|
647
|
+
const dataWidth = Math.max(...data.map((row) => {
|
|
648
|
+
const columnText = render2(row[keys[index]]);
|
|
649
|
+
const columnTextLength = this.getVisibleLength(columnText);
|
|
650
|
+
return columnTextLength;
|
|
651
|
+
}));
|
|
652
|
+
return Math.max(header.length, dataWidth);
|
|
653
|
+
});
|
|
654
|
+
for (const [index, row] of data.entries()) {
|
|
655
|
+
const dataRow = keys.map((key, index2) => {
|
|
656
|
+
const paddingNormalizer = render2(row[key]).length - row[key].length;
|
|
657
|
+
if (key === "key") {
|
|
658
|
+
return render2(row[key]).padEnd(columnWidths[index2] + paddingNormalizer);
|
|
659
|
+
}
|
|
660
|
+
if (row["key"] === "FILE") {
|
|
661
|
+
return render5(row[key]).padEnd(columnWidths[index2] + paddingNormalizer);
|
|
662
|
+
}
|
|
663
|
+
if (row["key"] === "PARSABLE") {
|
|
664
|
+
return render6(row[key]).padEnd(columnWidths[index2] + paddingNormalizer);
|
|
665
|
+
}
|
|
666
|
+
return String(row[key]).padEnd(columnWidths[index2] + paddingNormalizer);
|
|
667
|
+
}).join(" ");
|
|
668
|
+
const leftPadding = index === 0 ? leftPaddingGroupLead : leftPaddingGroupData;
|
|
669
|
+
console.log(leftPadding + dataRow);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
// draws progress bar components like this
|
|
673
|
+
// "███████░░░░░░░░░░░░░ 3 / 9 Running"
|
|
674
|
+
static renderProgressBar(count, total, label, width = 20) {
|
|
675
|
+
if (total === 0) {
|
|
676
|
+
const emptyBar = "\u2591".repeat(width);
|
|
677
|
+
return `${emptyBar} 0 / 0 ${label}`;
|
|
678
|
+
}
|
|
679
|
+
const progress = Math.min(count / total, 1);
|
|
680
|
+
const filledWidth = Math.round(progress * width);
|
|
681
|
+
const emptyWidth = width - filledWidth;
|
|
682
|
+
let filled;
|
|
683
|
+
let empty;
|
|
684
|
+
if (count > 0) {
|
|
685
|
+
filled = (0, import_node_util7.styleText)(["greenBright"], "\u2588".repeat(filledWidth));
|
|
686
|
+
empty = (0, import_node_util7.styleText)(["green"], "\u2591".repeat(emptyWidth));
|
|
687
|
+
} else {
|
|
688
|
+
filled = "\u2588".repeat(filledWidth);
|
|
689
|
+
empty = "\u2591".repeat(emptyWidth);
|
|
690
|
+
}
|
|
691
|
+
return `${filled}${empty} ${count} / ${total} ${label}`;
|
|
57
692
|
}
|
|
58
693
|
};
|
|
59
694
|
|
|
60
695
|
// src/bin/cli.ts
|
|
61
|
-
|
|
696
|
+
console.log();
|
|
62
697
|
async function init() {
|
|
63
698
|
const mcpFilesManager = new MCPFiles();
|
|
64
699
|
const mcpFilesList = await mcpFilesManager.findFiles();
|
|
65
|
-
if (mcpFilesList.length
|
|
66
|
-
console.log("MCP files found:");
|
|
67
|
-
mcpFilesList.forEach((file) => {
|
|
68
|
-
console.log(`- ${file}`);
|
|
69
|
-
});
|
|
70
|
-
} else {
|
|
700
|
+
if (Object.keys(mcpFilesList).length === 0) {
|
|
71
701
|
console.log("No MCP files found.");
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
let pathIndex = 0;
|
|
705
|
+
for (const groupName of Object.keys(mcpFilesList)) {
|
|
706
|
+
const group = mcpFilesList[groupName];
|
|
707
|
+
if (group.paths.length >= 0) {
|
|
708
|
+
for (const filePathData of group.paths) {
|
|
709
|
+
pathIndex++;
|
|
710
|
+
const filePath = filePathData.filePath.replace("~", process.env.HOME || "");
|
|
711
|
+
const filePathValid = filePathData.parsable ? "VALID" : "INVALID";
|
|
712
|
+
const filePathDataType = filePathData.type.toUpperCase();
|
|
713
|
+
const mcpServers = filePathData.servers || [];
|
|
714
|
+
const totalMCPServers = filePathData.servers ? filePathData.servers.length : 0;
|
|
715
|
+
const totalMCPServersRunning = mcpServers.filter((server) => server.status === "running").length;
|
|
716
|
+
const mcpGroupData = [
|
|
717
|
+
{ key: "PROVIDER", value: group.friendlyName },
|
|
718
|
+
{ key: "FILE", value: filePath },
|
|
719
|
+
{ key: "TYPE", value: filePathDataType },
|
|
720
|
+
{ key: "PARSABLE", value: filePathValid }
|
|
721
|
+
];
|
|
722
|
+
const groupMetadata = {
|
|
723
|
+
mcpServersTotal: totalMCPServers,
|
|
724
|
+
mcpServersRunning: totalMCPServersRunning
|
|
725
|
+
};
|
|
726
|
+
RenderService.printMcpGroup(pathIndex, mcpGroupData, groupMetadata);
|
|
727
|
+
RenderService.printMcpServers(mcpServers);
|
|
728
|
+
}
|
|
729
|
+
} else {
|
|
730
|
+
console.log("No files found in this group.");
|
|
731
|
+
}
|
|
72
732
|
}
|
|
73
733
|
}
|
|
74
734
|
__name(init, "init");
|
|
75
|
-
init()
|
|
735
|
+
init().then(() => {
|
|
736
|
+
console.log("\n");
|
|
737
|
+
});
|