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/main.mjs
CHANGED
|
@@ -2,32 +2,445 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
4
|
// src/main.ts
|
|
5
|
+
import fs2 from "fs/promises";
|
|
6
|
+
|
|
7
|
+
// src/services/mcp-config-linter-service.ts
|
|
5
8
|
import fs from "fs/promises";
|
|
9
|
+
var MCPConfigLinterService = class {
|
|
10
|
+
static {
|
|
11
|
+
__name(this, "MCPConfigLinterService");
|
|
12
|
+
}
|
|
13
|
+
filePath;
|
|
14
|
+
fileContents = null;
|
|
15
|
+
constructor(filePath) {
|
|
16
|
+
this.filePath = filePath;
|
|
17
|
+
}
|
|
18
|
+
async isValidSyntax() {
|
|
19
|
+
try {
|
|
20
|
+
const fileContent = await this.getFileContent();
|
|
21
|
+
JSON.parse(fileContent);
|
|
22
|
+
return true;
|
|
23
|
+
} catch (error) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async countMCPServers() {
|
|
28
|
+
const mcpServers = await this.getMCPServers();
|
|
29
|
+
return Object.keys(mcpServers).length;
|
|
30
|
+
}
|
|
31
|
+
async getMCPServers() {
|
|
32
|
+
const fileContentRaw = await this.getFileContent();
|
|
33
|
+
const fileContentsData = JSON.parse(fileContentRaw);
|
|
34
|
+
const mcpServers = fileContentsData?.mcpServers;
|
|
35
|
+
return mcpServers;
|
|
36
|
+
}
|
|
37
|
+
async getFileContent() {
|
|
38
|
+
if (this.fileContents) {
|
|
39
|
+
return this.fileContents;
|
|
40
|
+
}
|
|
41
|
+
this.fileContents = await fs.readFile(this.filePath, "utf-8");
|
|
42
|
+
return this.fileContents;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// src/services/mcp-server-manager-service.ts
|
|
47
|
+
import { execSync } from "child_process";
|
|
48
|
+
import { platform } from "os";
|
|
49
|
+
var MCPServerManagerService = class {
|
|
50
|
+
static {
|
|
51
|
+
__name(this, "MCPServerManagerService");
|
|
52
|
+
}
|
|
53
|
+
name;
|
|
54
|
+
command;
|
|
55
|
+
args;
|
|
56
|
+
transport;
|
|
57
|
+
env;
|
|
58
|
+
running = false;
|
|
59
|
+
constructor(serverConfig) {
|
|
60
|
+
this.name = serverConfig.name;
|
|
61
|
+
this.command = serverConfig.command;
|
|
62
|
+
this.args = serverConfig.args || [];
|
|
63
|
+
this.transport = serverConfig.transport || "stdio";
|
|
64
|
+
this.env = serverConfig.env || {};
|
|
65
|
+
}
|
|
66
|
+
getName() {
|
|
67
|
+
return this.name;
|
|
68
|
+
}
|
|
69
|
+
getCmd() {
|
|
70
|
+
return this.command;
|
|
71
|
+
}
|
|
72
|
+
getArgs() {
|
|
73
|
+
return this.args;
|
|
74
|
+
}
|
|
75
|
+
getTransport() {
|
|
76
|
+
return this.transport;
|
|
77
|
+
}
|
|
78
|
+
getEnv() {
|
|
79
|
+
return this.env;
|
|
80
|
+
}
|
|
81
|
+
isRunning() {
|
|
82
|
+
try {
|
|
83
|
+
let psOutput;
|
|
84
|
+
if (platform() === "win32") {
|
|
85
|
+
psOutput = execSync("wmic process get ProcessId,ParentProcessId,CommandLine /format:csv", {
|
|
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
|
+
const parts = processLine.split(",");
|
|
104
|
+
if (parts.length < 4) continue;
|
|
105
|
+
commandLine = parts[1] || "";
|
|
106
|
+
ppid = parts[2] || "";
|
|
107
|
+
pid = parts[3] || "";
|
|
108
|
+
} else {
|
|
109
|
+
const match = processLine.trim().match(/^\s*(\d+)\s+(\d+)\s+(.+)$/);
|
|
110
|
+
if (!match) continue;
|
|
111
|
+
pid = match[1];
|
|
112
|
+
ppid = match[2];
|
|
113
|
+
commandLine = match[3];
|
|
114
|
+
}
|
|
115
|
+
const commandTokens = this.parseCommandLine(commandLine);
|
|
116
|
+
if (commandTokens.length > 0) {
|
|
117
|
+
processMap.set(pid, { ppid, commandTokens });
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
let mcpServerDetection;
|
|
121
|
+
for (const [pid, processData] of processMap) {
|
|
122
|
+
if (this.isCommandMatch(processData.commandTokens, pid, processData.ppid)) {
|
|
123
|
+
mcpServerDetection = {
|
|
124
|
+
pid,
|
|
125
|
+
commandLine: processData.commandTokens.join(" "),
|
|
126
|
+
ppid: processData.ppid
|
|
127
|
+
};
|
|
128
|
+
const parentProcess = processMap.get(processData.ppid);
|
|
129
|
+
if (parentProcess) {
|
|
130
|
+
const { estimatedVendor, estimatedProduct } = this.getVendorFromCommand(parentProcess.commandTokens) || {};
|
|
131
|
+
if (estimatedProduct || estimatedVendor) {
|
|
132
|
+
mcpServerDetection = {
|
|
133
|
+
...mcpServerDetection,
|
|
134
|
+
parentCommandLine: parentProcess.commandTokens.join(" "),
|
|
135
|
+
estimatedVendor,
|
|
136
|
+
estimatedProduct
|
|
137
|
+
};
|
|
138
|
+
return mcpServerDetection;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (mcpServerDetection) {
|
|
144
|
+
return mcpServerDetection;
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
} catch (error) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
getVendorFromCommand(commandTokens) {
|
|
152
|
+
const commandString = commandTokens.join(" ").toLowerCase();
|
|
153
|
+
if (commandString.includes("claude.app")) {
|
|
154
|
+
return {
|
|
155
|
+
estimatedVendor: "anthropic",
|
|
156
|
+
estimatedProduct: "claude-desktop"
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
if (commandString.includes("claude")) {
|
|
160
|
+
return {
|
|
161
|
+
estimatedVendor: "anthropic",
|
|
162
|
+
estimatedProduct: "claude-desktop"
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
isCommandMatch(commandTokens, pid, ppid) {
|
|
167
|
+
if (commandTokens.length === 0) return false;
|
|
168
|
+
const baseCommand = this.getBaseCommand(commandTokens[0]);
|
|
169
|
+
if (this.command === "uvx" && baseCommand === "uv") {
|
|
170
|
+
return this.matchUvxProcess(commandTokens);
|
|
171
|
+
}
|
|
172
|
+
if (this.command === "npx" && baseCommand === "npm") {
|
|
173
|
+
return this.matchNpxProcess(commandTokens);
|
|
174
|
+
}
|
|
175
|
+
if (this.command === "uv" && baseCommand === "uv") {
|
|
176
|
+
return this.matchGenericArgsToArgs(commandTokens);
|
|
177
|
+
}
|
|
178
|
+
const commandConfigPythonBase = this.getBaseCommand(this.command);
|
|
179
|
+
const commandAliasesPython = ["python3", "python", "python3.10", "python3.11", "python3.12", "cpython3", "cpython", "python3", "python2"];
|
|
180
|
+
if (commandAliasesPython.includes(commandConfigPythonBase) && commandAliasesPython.includes(baseCommand)) {
|
|
181
|
+
return this.matchGenericArgsToArgs(commandTokens);
|
|
182
|
+
}
|
|
183
|
+
const commandGenericBase = this.getBaseCommand(this.command);
|
|
184
|
+
const commandGenericProcessBase = this.getBaseCommand(commandTokens[0]);
|
|
185
|
+
if (commandGenericBase === commandGenericProcessBase) {
|
|
186
|
+
return this.matchGenericArgsToArgs(commandTokens);
|
|
187
|
+
}
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
matchGenericArgsToArgs(commandTokens) {
|
|
191
|
+
if (this.args.length === 0) {
|
|
192
|
+
return commandTokens[0] === this.command;
|
|
193
|
+
}
|
|
194
|
+
if (commandTokens.length < 2) {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
const commandWithoutArgs = commandTokens.slice(1);
|
|
198
|
+
for (let i = 0; i < this.args.length; i++) {
|
|
199
|
+
if (i >= commandWithoutArgs.length) return false;
|
|
200
|
+
const arg = this.args[i];
|
|
201
|
+
const token = commandWithoutArgs[i];
|
|
202
|
+
if (arg !== token && !token.includes(arg)) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
// @TODO refactor this to use path.basename or similar
|
|
209
|
+
// to extract the base command from the full command path
|
|
210
|
+
getBaseCommand(fullCommandPath) {
|
|
211
|
+
const parts = fullCommandPath.split(/[/\\]/);
|
|
212
|
+
return parts[parts.length - 1];
|
|
213
|
+
}
|
|
214
|
+
/*
|
|
215
|
+
example1:
|
|
216
|
+
```
|
|
217
|
+
"command": "uvx",
|
|
218
|
+
"args": ["--from", "mcp-alchemy==2025.5.2.210242", "--with", "oracledb",
|
|
219
|
+
"--refresh-package", "mcp-alchemy", "mcp-alchemy"],
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
example 2:
|
|
223
|
+
```
|
|
224
|
+
"command": "uvx",
|
|
225
|
+
"args": [
|
|
226
|
+
"mcp-neo4j-memory@0.1.4",
|
|
227
|
+
"--db-url",
|
|
228
|
+
"neo4j+s://xxxx.databases.neo4j.io",
|
|
229
|
+
"--username",
|
|
230
|
+
"<your-username>",
|
|
231
|
+
"--password",
|
|
232
|
+
"<your-password>"
|
|
233
|
+
]
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
example 3:
|
|
237
|
+
```
|
|
238
|
+
"vefaas": {
|
|
239
|
+
"command": "uvx",
|
|
240
|
+
"args": [
|
|
241
|
+
"--from",
|
|
242
|
+
"git+https://github.com/volcengine/mcp-server#subdirectory=server/mcp_server_vefaas_function",
|
|
243
|
+
"mcp-server-vefaas-function"
|
|
244
|
+
],
|
|
245
|
+
"env": {
|
|
246
|
+
"VOLC_ACCESSKEY": "xxx",
|
|
247
|
+
"VOLC_SECRETKEY": "xxx"
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
example 4:
|
|
254
|
+
```
|
|
255
|
+
"time": {
|
|
256
|
+
"command": "uvx",
|
|
257
|
+
"args": ["mcp-server-time", "--local-timezone=America/New_York"]
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
*/
|
|
261
|
+
getUvxMcpServerNameFromArgs() {
|
|
262
|
+
if (this.args.length === 0) return void 0;
|
|
263
|
+
let mcpServerName;
|
|
264
|
+
if (this.args.length === 1) {
|
|
265
|
+
mcpServerName = this.args[0];
|
|
266
|
+
return mcpServerName;
|
|
267
|
+
}
|
|
268
|
+
for (let i = 0; i < this.args.length; i++) {
|
|
269
|
+
if (this.args[i] === "--from" && i + 1 < this.args.length) {
|
|
270
|
+
mcpServerName = this.args[i + 1];
|
|
271
|
+
return mcpServerName;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
const firstArg = this.args[0];
|
|
275
|
+
if (firstArg.startsWith("-") || firstArg.startsWith("--")) {
|
|
276
|
+
const lastArg = this.args[this.args.length - 1];
|
|
277
|
+
mcpServerName = lastArg;
|
|
278
|
+
return mcpServerName;
|
|
279
|
+
}
|
|
280
|
+
mcpServerName = firstArg;
|
|
281
|
+
return mcpServerName;
|
|
282
|
+
}
|
|
283
|
+
matchUvxProcess(commandTokens) {
|
|
284
|
+
if (commandTokens.length === 0) return false;
|
|
285
|
+
const mcpServerName = this.getUvxMcpServerNameFromArgs();
|
|
286
|
+
if (!mcpServerName) return false;
|
|
287
|
+
return this.findMcpServerNameInProcessArguments(commandTokens, mcpServerName);
|
|
288
|
+
}
|
|
289
|
+
findMcpServerNameInProcessArguments(commandTokens, mcpServerName) {
|
|
290
|
+
for (let i = 0; i < commandTokens.length; i++) {
|
|
291
|
+
const token = commandTokens[i];
|
|
292
|
+
if (mcpServerName === token || token.includes(mcpServerName)) {
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
parseCommandLine(commandLine) {
|
|
299
|
+
const tokens = [];
|
|
300
|
+
let current = "";
|
|
301
|
+
let inQuotes = false;
|
|
302
|
+
let quoteChar = "";
|
|
303
|
+
for (let i = 0; i < commandLine.length; i++) {
|
|
304
|
+
const char = commandLine[i];
|
|
305
|
+
if (!inQuotes && (char === '"' || char === "'")) {
|
|
306
|
+
inQuotes = true;
|
|
307
|
+
quoteChar = char;
|
|
308
|
+
} else if (inQuotes && char === quoteChar) {
|
|
309
|
+
inQuotes = false;
|
|
310
|
+
quoteChar = "";
|
|
311
|
+
} else if (!inQuotes && char === " ") {
|
|
312
|
+
if (current.trim()) {
|
|
313
|
+
tokens.push(current.trim());
|
|
314
|
+
current = "";
|
|
315
|
+
}
|
|
316
|
+
} else {
|
|
317
|
+
current += char;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
if (current.trim()) {
|
|
321
|
+
tokens.push(current.trim());
|
|
322
|
+
}
|
|
323
|
+
return tokens;
|
|
324
|
+
}
|
|
325
|
+
/*
|
|
326
|
+
example to match:
|
|
327
|
+
```
|
|
328
|
+
"command": "npx",
|
|
329
|
+
"args": [
|
|
330
|
+
"-y",
|
|
331
|
+
"@modelcontextprotocol/server-postgres",
|
|
332
|
+
"postgresql://localhost/mydb"
|
|
333
|
+
]
|
|
334
|
+
}
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
with a process command like:
|
|
338
|
+
```
|
|
339
|
+
npm exec @modelcontextprotocol/server-postgres postgresql://localhost/mydb
|
|
340
|
+
```
|
|
341
|
+
*/
|
|
342
|
+
matchNpxProcess(commandTokens) {
|
|
343
|
+
if (commandTokens.length < 3) return false;
|
|
344
|
+
if (commandTokens[1] !== "exec") return false;
|
|
345
|
+
let argsToMatch = [];
|
|
346
|
+
const yIndex = this.args.indexOf("-y");
|
|
347
|
+
if (yIndex !== -1 && yIndex + 1 < this.args.length) {
|
|
348
|
+
argsToMatch = this.args.slice(yIndex + 1);
|
|
349
|
+
} else {
|
|
350
|
+
argsToMatch = this.args;
|
|
351
|
+
}
|
|
352
|
+
if (commandTokens.length - 2 !== argsToMatch.length) {
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
for (let i = 0; i < argsToMatch.length; i++) {
|
|
356
|
+
const commandToken = commandTokens[i + 2];
|
|
357
|
+
const expectedArg = argsToMatch[i];
|
|
358
|
+
if (commandToken !== expectedArg) {
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return true;
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
// src/main.ts
|
|
6
367
|
var MCPFiles = class {
|
|
7
368
|
static {
|
|
8
369
|
__name(this, "MCPFiles");
|
|
9
370
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
371
|
+
mcpFilePathGroups = {
|
|
372
|
+
claude: {
|
|
373
|
+
name: "claude-desktop",
|
|
374
|
+
friendlyName: "Claude Desktop",
|
|
375
|
+
paths: [
|
|
376
|
+
{ filePath: "~/Library/Application Support/Claude/claude_desktop_config.json", type: "global" }
|
|
377
|
+
]
|
|
378
|
+
},
|
|
379
|
+
cursor: {
|
|
380
|
+
name: "cursor",
|
|
381
|
+
friendlyName: "Cursor",
|
|
382
|
+
paths: [
|
|
383
|
+
{ filePath: "~/.cursor/mcp.json", type: "global" },
|
|
384
|
+
{ filePath: ".cursor/mcp.json", type: "local" }
|
|
385
|
+
]
|
|
18
386
|
}
|
|
387
|
+
};
|
|
388
|
+
constructor(mcpFilePathGroups) {
|
|
389
|
+
this.mcpFilePathGroups = mcpFilePathGroups || this.mcpFilePathGroups;
|
|
19
390
|
}
|
|
20
391
|
async findFiles() {
|
|
21
|
-
const
|
|
22
|
-
for (const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
392
|
+
const mcpFilesPathsData = {};
|
|
393
|
+
for (const groupName of Object.keys(this.mcpFilePathGroups)) {
|
|
394
|
+
const clientsGroup = this.mcpFilePathGroups[groupName];
|
|
395
|
+
mcpFilesPathsData[groupName] = {
|
|
396
|
+
name: clientsGroup.name,
|
|
397
|
+
friendlyName: clientsGroup.friendlyName,
|
|
398
|
+
paths: [],
|
|
399
|
+
stats: {}
|
|
400
|
+
};
|
|
401
|
+
for (const filePathData of clientsGroup.paths) {
|
|
402
|
+
const resolvedPath = filePathData.filePath.replace("~", process.env.HOME || "");
|
|
403
|
+
try {
|
|
404
|
+
await fs2.access(resolvedPath);
|
|
405
|
+
const MCPConfigLinter = new MCPConfigLinterService(resolvedPath);
|
|
406
|
+
const parsable = await MCPConfigLinter.isValidSyntax();
|
|
407
|
+
filePathData.parsable = parsable;
|
|
408
|
+
const mcpServersData = [];
|
|
409
|
+
const mcpServersFromConfig = await MCPConfigLinter.getMCPServers();
|
|
410
|
+
for (const serverName of Object.keys(mcpServersFromConfig)) {
|
|
411
|
+
const serverConfigRaw = mcpServersFromConfig[serverName];
|
|
412
|
+
const serverConfig = {
|
|
413
|
+
name: serverName,
|
|
414
|
+
command: serverConfigRaw.command || "",
|
|
415
|
+
args: serverConfigRaw.args,
|
|
416
|
+
transport: serverConfigRaw.transport,
|
|
417
|
+
env: serverConfigRaw.env
|
|
418
|
+
};
|
|
419
|
+
const MCPServerManager = new MCPServerManagerService(serverConfig);
|
|
420
|
+
const mcpServerProcessDetection = MCPServerManager.isRunning();
|
|
421
|
+
let mcpServerProcess = false;
|
|
422
|
+
if (mcpServerProcessDetection) {
|
|
423
|
+
if (typeof mcpServerProcessDetection === "object" && mcpServerProcessDetection.estimatedProduct === clientsGroup.name) {
|
|
424
|
+
mcpServerProcess = true;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
mcpServersData.push({
|
|
428
|
+
name: MCPServerManager.getName(),
|
|
429
|
+
command: MCPServerManager.getCmd(),
|
|
430
|
+
args: MCPServerManager.getArgs(),
|
|
431
|
+
transport: MCPServerManager.getTransport(),
|
|
432
|
+
env: MCPServerManager.getEnv(),
|
|
433
|
+
status: mcpServerProcess ? "running" : "stopped"
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
filePathData.servers = mcpServersData;
|
|
437
|
+
mcpFilesPathsData[groupName]["stats"]["serversCount"] = await MCPConfigLinter.countMCPServers();
|
|
438
|
+
mcpFilesPathsData[groupName].paths.push(filePathData);
|
|
439
|
+
} catch (error) {
|
|
440
|
+
}
|
|
28
441
|
}
|
|
29
442
|
}
|
|
30
|
-
return
|
|
443
|
+
return mcpFilesPathsData;
|
|
31
444
|
}
|
|
32
445
|
};
|
|
33
446
|
export {
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ls-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "list and detect MCP servers and configurations",
|
|
5
5
|
"types": "dist/main.d.ts",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"bin":
|
|
7
|
+
"bin": {
|
|
8
|
+
"ls-mcp": "./dist/bin/cli.cjs"
|
|
9
|
+
},
|
|
8
10
|
"exports": {
|
|
9
11
|
".": {
|
|
10
12
|
"import": {
|
|
@@ -33,12 +35,13 @@
|
|
|
33
35
|
"bin"
|
|
34
36
|
],
|
|
35
37
|
"scripts": {
|
|
38
|
+
"start": "npm run build && node --import tsx src/bin/cli.ts",
|
|
36
39
|
"build": "tsc && tsup",
|
|
37
40
|
"lint": "eslint . && npm run lint:lockfile",
|
|
38
41
|
"lint:fix": "eslint . --fix",
|
|
39
42
|
"lint:lockfile": "lockfile-lint --path package-lock.json --validate-https --allowed-hosts npm yarn",
|
|
40
|
-
"test": "c8 node --
|
|
41
|
-
"test:watch": "c8 node --
|
|
43
|
+
"test": "c8 node --import tsx --test __tests__/**/*.test.ts",
|
|
44
|
+
"test:watch": "c8 node --import tsx --test --watch __tests__/**/*.test.ts",
|
|
42
45
|
"coverage:view": "open coverage/lcov-report/index.html",
|
|
43
46
|
"version": "changeset version",
|
|
44
47
|
"release": "changeset publish"
|
|
@@ -73,16 +76,16 @@
|
|
|
73
76
|
"devDependencies": {
|
|
74
77
|
"@changesets/changelog-github": "^0.5.0",
|
|
75
78
|
"@changesets/cli": "^2.27.7",
|
|
76
|
-
"@types/node": "^
|
|
79
|
+
"@types/node": "^22.15.21",
|
|
77
80
|
"c8": "^10.1.2",
|
|
78
81
|
"eslint": "^9.6.0",
|
|
79
82
|
"eslint-plugin-security": "^3.0.1",
|
|
80
83
|
"husky": "^9.0.11",
|
|
81
|
-
"lint-staged": "^
|
|
84
|
+
"lint-staged": "^16.0.0",
|
|
82
85
|
"lockfile-lint": "^4.14.0",
|
|
83
|
-
"neostandard": "^0.
|
|
84
|
-
"ts-node": "^10.9.2",
|
|
86
|
+
"neostandard": "^0.12.1",
|
|
85
87
|
"tsup": "^8.1.0",
|
|
88
|
+
"tsx": "^4.19.4",
|
|
86
89
|
"typescript": "^5.5.3",
|
|
87
90
|
"validate-conventional-commit": "^1.0.4"
|
|
88
91
|
},
|
|
@@ -91,4 +94,4 @@
|
|
|
91
94
|
"npm run lint:fix"
|
|
92
95
|
]
|
|
93
96
|
}
|
|
94
|
-
}
|
|
97
|
+
}
|
package/src/bin/cli.ts
CHANGED
|
@@ -1,21 +1,71 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
// import { debuglog } from 'node:util'
|
|
3
4
|
import { MCPFiles } from '../main.ts'
|
|
5
|
+
import { RenderService } from '../services/render-service.ts'
|
|
6
|
+
|
|
7
|
+
interface MCPServerInfo {
|
|
8
|
+
name: string
|
|
9
|
+
command: string
|
|
10
|
+
args?: string[]
|
|
11
|
+
transport?: 'stdio' | 'sse'
|
|
12
|
+
env?: Record<string, string>
|
|
13
|
+
status?: 'running' | 'stopped'
|
|
14
|
+
}
|
|
4
15
|
|
|
5
|
-
|
|
16
|
+
// Start the CLI with a new line for better readability
|
|
17
|
+
console.log()
|
|
18
|
+
|
|
19
|
+
// @TODO add debug logging
|
|
20
|
+
// const debug = debuglog('ls-mcp')
|
|
6
21
|
|
|
7
22
|
async function init () {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
23
|
+
const mcpFilesManager = new MCPFiles()
|
|
24
|
+
const mcpFilesList = await mcpFilesManager.findFiles()
|
|
25
|
+
|
|
26
|
+
if (Object.keys(mcpFilesList).length === 0) {
|
|
27
|
+
console.log('No MCP files found.')
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let pathIndex = 0
|
|
32
|
+
for (const groupName of Object.keys(mcpFilesList)) {
|
|
33
|
+
const group = mcpFilesList[groupName]
|
|
34
|
+
|
|
35
|
+
if (group.paths.length >= 0) {
|
|
36
|
+
// handle file path list of MCP Servers
|
|
37
|
+
for (const filePathData of group.paths) {
|
|
38
|
+
pathIndex++
|
|
39
|
+
|
|
40
|
+
const filePath = filePathData.filePath.replace('~', process.env.HOME || '')
|
|
41
|
+
const filePathValid = filePathData.parsable ? 'VALID' : 'INVALID'
|
|
42
|
+
const filePathDataType = filePathData.type.toUpperCase()
|
|
43
|
+
const mcpServers = filePathData.servers || []
|
|
44
|
+
|
|
45
|
+
const totalMCPServers = filePathData.servers ? filePathData.servers.length : 0
|
|
46
|
+
const totalMCPServersRunning = mcpServers.filter((server: MCPServerInfo) => server.status === 'running').length
|
|
47
|
+
|
|
48
|
+
const mcpGroupData = [
|
|
49
|
+
{ key: 'PROVIDER', value: group.friendlyName },
|
|
50
|
+
{ key: 'FILE', value: filePath },
|
|
51
|
+
{ key: 'TYPE', value: filePathDataType },
|
|
52
|
+
{ key: 'PARSABLE', value: filePathValid },
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
const groupMetadata = {
|
|
56
|
+
mcpServersTotal: totalMCPServers,
|
|
57
|
+
mcpServersRunning: totalMCPServersRunning,
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
RenderService.printMcpGroup(pathIndex, mcpGroupData, groupMetadata)
|
|
61
|
+
RenderService.printMcpServers(mcpServers)
|
|
62
|
+
}
|
|
16
63
|
} else {
|
|
17
|
-
|
|
64
|
+
console.log('No files found in this group.')
|
|
18
65
|
}
|
|
66
|
+
}
|
|
19
67
|
}
|
|
20
68
|
|
|
21
|
-
init()
|
|
69
|
+
init().then(() => {
|
|
70
|
+
console.log('\n')
|
|
71
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { styleText } from 'node:util'
|
|
2
|
+
|
|
3
|
+
export default function render (text: string) {
|
|
4
|
+
const formattedText = text.toLowerCase()
|
|
5
|
+
let data = ''
|
|
6
|
+
if (formattedText === 'running') {
|
|
7
|
+
data = styleText(['green'], '●')
|
|
8
|
+
} else {
|
|
9
|
+
data = styleText(['red'], '●')
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return data
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { styleText } from 'node:util'
|
|
2
|
+
|
|
3
|
+
export default function render (text: string) {
|
|
4
|
+
const formattedText = text.toUpperCase().replace(/_/g, ' ')
|
|
5
|
+
let data = formattedText
|
|
6
|
+
if (formattedText === 'VALID') {
|
|
7
|
+
data = styleText(['green'], '●')
|
|
8
|
+
} else {
|
|
9
|
+
data = styleText(['red'], '●')
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return data
|
|
13
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { styleText } from 'node:util'
|
|
2
|
+
|
|
3
|
+
export default function render (text: string) {
|
|
4
|
+
const formattedText = text.toUpperCase()
|
|
5
|
+
let data = ''
|
|
6
|
+
if (formattedText === 'STDIO') {
|
|
7
|
+
data = styleText(['magenta'], formattedText)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (formattedText === 'SSE') {
|
|
11
|
+
data = styleText(['blue'], formattedText)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return data
|
|
15
|
+
}
|