ls-mcp 1.15.1 → 1.15.3
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/README.md +16 -8
- package/dist/bin/cli.cjs +1359 -1749
- package/dist/bin/cli.cjs.map +1 -0
- package/dist/bin/cli.d.cts +1 -1
- package/dist/bin/cli.d.ts +1 -1
- package/dist/bin/cli.mjs +1341 -1735
- package/dist/main.cjs +1002 -1267
- package/dist/main.d.cts +74 -69
- package/dist/main.d.ts +74 -69
- package/dist/main.mjs +985 -1240
- package/package.json +29 -35
- package/src/bin/cli.ts +1 -1
- package/src/components/mcp-server-status.ts +1 -1
- package/src/components/mcp-servers-config-parsable.ts +1 -1
- package/src/main.ts +1 -1
- package/src/services/mcp-config-service.ts +20 -11
- package/src/services/mcp-server-manager-service.ts +5 -5
- package/src/services/render-service.ts +9 -11
- package/src/utils/url-utils.ts +1 -1
package/dist/bin/cli.mjs
CHANGED
|
@@ -1,1791 +1,1397 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
// src/services/mcp-config-service.ts
|
|
9
|
-
import { platform } from "os";
|
|
10
|
-
import path from "path";
|
|
11
|
-
import fs from "fs/promises";
|
|
12
|
-
import util from "util";
|
|
13
|
-
import { MCPPathRegistry, MCPConfigParser, DirectoryBubbleService } from "agent-files";
|
|
14
|
-
|
|
2
|
+
import util, { styleText } from "node:util";
|
|
3
|
+
import { platform } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import fs from "node:fs/promises";
|
|
6
|
+
import { DirectoryBubbleService, MCPConfigParser, MCPPathRegistry } from "agent-files";
|
|
7
|
+
import { execSync } from "node:child_process";
|
|
15
8
|
// src/services/credential-detection-service.ts
|
|
16
9
|
var CredentialDetectionService = class {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
name,
|
|
243
|
-
value: this.maskValue(value),
|
|
244
|
-
riskLevel: this.assessRiskLevel(name),
|
|
245
|
-
source: "env"
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
const hasCredentials = credentialVars.length > 0;
|
|
250
|
-
const riskLevel = this.calculateOverallRiskLevel(credentialVars);
|
|
251
|
-
return {
|
|
252
|
-
hasCredentials,
|
|
253
|
-
credentialVars,
|
|
254
|
-
riskLevel
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Mask sensitive values for display (show only first and last character)
|
|
259
|
-
*/
|
|
260
|
-
static maskValue(value) {
|
|
261
|
-
if (!value || value.length <= 2) {
|
|
262
|
-
return value;
|
|
263
|
-
}
|
|
264
|
-
const first = value.charAt(0);
|
|
265
|
-
const last = value.charAt(value.length - 1);
|
|
266
|
-
const maskedLength = Math.min(value.length - 2, 8);
|
|
267
|
-
return `${first}${"*".repeat(maskedLength)}${last}`;
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Assess risk level for a specific credential variable
|
|
271
|
-
*/
|
|
272
|
-
static assessRiskLevel(name) {
|
|
273
|
-
if (this.CREDENTIAL_PATTERNS.high.some((pattern) => pattern.test(name))) {
|
|
274
|
-
return "high";
|
|
275
|
-
}
|
|
276
|
-
if (this.CREDENTIAL_PATTERNS.low.some((pattern) => pattern.test(name))) {
|
|
277
|
-
return "low";
|
|
278
|
-
}
|
|
279
|
-
return "high";
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Calculate overall risk level based on all credential variables
|
|
283
|
-
*/
|
|
284
|
-
static calculateOverallRiskLevel(credentialVars) {
|
|
285
|
-
if (credentialVars.length === 0) {
|
|
286
|
-
return "none";
|
|
287
|
-
}
|
|
288
|
-
const hasHighRisk = credentialVars.some((v) => v.riskLevel === "high");
|
|
289
|
-
if (hasHighRisk) {
|
|
290
|
-
return "high";
|
|
291
|
-
}
|
|
292
|
-
return "low";
|
|
293
|
-
}
|
|
10
|
+
/**
|
|
11
|
+
* Credential patterns grouped by risk level for easier maintenance
|
|
12
|
+
*/
|
|
13
|
+
static CREDENTIAL_PATTERNS = {
|
|
14
|
+
high: [
|
|
15
|
+
/.*key.*/i,
|
|
16
|
+
/.*token.*/i,
|
|
17
|
+
/.*password.*/i,
|
|
18
|
+
/.*passwd.*/i,
|
|
19
|
+
/.*pwd.*/i,
|
|
20
|
+
/.*credential.*/i,
|
|
21
|
+
/.*creds.*/i,
|
|
22
|
+
/.*secret.*/i
|
|
23
|
+
],
|
|
24
|
+
low: [
|
|
25
|
+
/org[_-]?id/i,
|
|
26
|
+
/organization[_-]?id/i,
|
|
27
|
+
/account[_-]?id/i,
|
|
28
|
+
/user[_-]?id/i,
|
|
29
|
+
/openai[_-]?org[_-]?id/i
|
|
30
|
+
]
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Argument patterns for detecting credentials in command-line arguments
|
|
34
|
+
*/
|
|
35
|
+
static ARGUMENT_PATTERNS = {
|
|
36
|
+
high: [
|
|
37
|
+
/--api-key/i,
|
|
38
|
+
/--apikey/i,
|
|
39
|
+
/--key/i,
|
|
40
|
+
/--token/i,
|
|
41
|
+
/--access-token/i,
|
|
42
|
+
/--auth-token/i,
|
|
43
|
+
/--bearer-token/i,
|
|
44
|
+
/--password/i,
|
|
45
|
+
/--passwd/i,
|
|
46
|
+
/--pwd/i,
|
|
47
|
+
/--secret/i,
|
|
48
|
+
/--client-secret/i,
|
|
49
|
+
/--auth/i,
|
|
50
|
+
/--authorization/i,
|
|
51
|
+
/--credentials/i,
|
|
52
|
+
/--creds/i
|
|
53
|
+
],
|
|
54
|
+
low: [
|
|
55
|
+
/--org-id/i,
|
|
56
|
+
/--organization-id/i,
|
|
57
|
+
/--account-id/i,
|
|
58
|
+
/--user-id/i
|
|
59
|
+
]
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Header patterns for detecting credentials in HTTP headers
|
|
63
|
+
*/
|
|
64
|
+
static HEADER_PATTERNS = {
|
|
65
|
+
high: [
|
|
66
|
+
/authorization/i,
|
|
67
|
+
/auth/i,
|
|
68
|
+
/x-api-key/i,
|
|
69
|
+
/api-key/i,
|
|
70
|
+
/apikey/i,
|
|
71
|
+
/x-access-token/i,
|
|
72
|
+
/access-token/i,
|
|
73
|
+
/bearer-token/i,
|
|
74
|
+
/x-auth-token/i,
|
|
75
|
+
/auth-token/i,
|
|
76
|
+
/x-.*-key/i,
|
|
77
|
+
/x-.*-token/i,
|
|
78
|
+
/x-.*-secret/i,
|
|
79
|
+
/x-github-token/i,
|
|
80
|
+
/x-openai-key/i,
|
|
81
|
+
/x-anthropic-key/i
|
|
82
|
+
],
|
|
83
|
+
low: [
|
|
84
|
+
/x-user-id/i,
|
|
85
|
+
/x-org-id/i,
|
|
86
|
+
/x-organization-id/i,
|
|
87
|
+
/x-account-id/i
|
|
88
|
+
]
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Variable substitution pattern to detect safe variable references
|
|
92
|
+
*/
|
|
93
|
+
static VARIABLE_SUBSTITUTION_PATTERN = /^\$\{[^}]+\}$/;
|
|
94
|
+
/**
|
|
95
|
+
* Check if a value is a variable substitution pattern (e.g., ${input:token})
|
|
96
|
+
*/
|
|
97
|
+
static isVariableSubstitution(value) {
|
|
98
|
+
return this.VARIABLE_SUBSTITUTION_PATTERN.test(value);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Analyze command-line arguments for potential credentials
|
|
102
|
+
*/
|
|
103
|
+
static analyzeArguments(args) {
|
|
104
|
+
if (!args || !Array.isArray(args) || args.length === 0) return {
|
|
105
|
+
hasCredentials: false,
|
|
106
|
+
credentialVars: [],
|
|
107
|
+
riskLevel: "none"
|
|
108
|
+
};
|
|
109
|
+
const credentialVars = [];
|
|
110
|
+
for (let i = 0; i < args.length - 1; i++) {
|
|
111
|
+
const arg = args[i];
|
|
112
|
+
const nextArg = args[i + 1];
|
|
113
|
+
const isHighRiskArg = this.ARGUMENT_PATTERNS.high.some((pattern) => pattern.test(arg));
|
|
114
|
+
const isLowRiskArg = this.ARGUMENT_PATTERNS.low.some((pattern) => pattern.test(arg));
|
|
115
|
+
if (isHighRiskArg || isLowRiskArg) {
|
|
116
|
+
if (nextArg && !nextArg.startsWith("-")) {
|
|
117
|
+
credentialVars.push({
|
|
118
|
+
name: arg,
|
|
119
|
+
value: this.maskValue(nextArg),
|
|
120
|
+
riskLevel: isHighRiskArg ? "high" : "low",
|
|
121
|
+
source: "args"
|
|
122
|
+
});
|
|
123
|
+
i++;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
hasCredentials: credentialVars.length > 0,
|
|
129
|
+
credentialVars,
|
|
130
|
+
riskLevel: this.calculateOverallRiskLevel(credentialVars)
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Analyze HTTP headers for potential credentials
|
|
135
|
+
*/
|
|
136
|
+
static analyzeHeaders(headers) {
|
|
137
|
+
if (!headers || typeof headers !== "object") return {
|
|
138
|
+
hasCredentials: false,
|
|
139
|
+
credentialVars: [],
|
|
140
|
+
riskLevel: "none"
|
|
141
|
+
};
|
|
142
|
+
const credentialVars = [];
|
|
143
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
144
|
+
if (this.isVariableSubstitution(value)) continue;
|
|
145
|
+
const isHighRiskHeader = this.HEADER_PATTERNS.high.some((pattern) => pattern.test(name));
|
|
146
|
+
const isLowRiskHeader = this.HEADER_PATTERNS.low.some((pattern) => pattern.test(name));
|
|
147
|
+
if (isHighRiskHeader || isLowRiskHeader) credentialVars.push({
|
|
148
|
+
name,
|
|
149
|
+
value: this.maskValue(value),
|
|
150
|
+
riskLevel: isHighRiskHeader ? "high" : "low",
|
|
151
|
+
source: "headers"
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
hasCredentials: credentialVars.length > 0,
|
|
156
|
+
credentialVars,
|
|
157
|
+
riskLevel: this.calculateOverallRiskLevel(credentialVars)
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Comprehensive analysis of server configuration for credentials
|
|
162
|
+
*/
|
|
163
|
+
static analyzeServerConfig(config) {
|
|
164
|
+
const envResult = this.analyzeEnvironmentVariables(config.env);
|
|
165
|
+
const argsResult = this.analyzeArguments(config.args);
|
|
166
|
+
const headersResult = this.analyzeHeaders(config.headers);
|
|
167
|
+
const allCredentialVars = [
|
|
168
|
+
...envResult.credentialVars,
|
|
169
|
+
...argsResult.credentialVars,
|
|
170
|
+
...headersResult.credentialVars
|
|
171
|
+
];
|
|
172
|
+
return {
|
|
173
|
+
hasCredentials: allCredentialVars.length > 0,
|
|
174
|
+
credentialVars: allCredentialVars,
|
|
175
|
+
riskLevel: this.calculateOverallRiskLevel(allCredentialVars)
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Check if an environment variable name suggests it might contain credentials
|
|
180
|
+
*/
|
|
181
|
+
static isPotentialCredential(envVarName) {
|
|
182
|
+
return this.CREDENTIAL_PATTERNS.high.some((pattern) => pattern.test(envVarName)) || this.CREDENTIAL_PATTERNS.low.some((pattern) => pattern.test(envVarName));
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Analyze environment variables and return credential detection results
|
|
186
|
+
*/
|
|
187
|
+
static analyzeEnvironmentVariables(env) {
|
|
188
|
+
if (!env || typeof env !== "object") return {
|
|
189
|
+
hasCredentials: false,
|
|
190
|
+
credentialVars: [],
|
|
191
|
+
riskLevel: "none"
|
|
192
|
+
};
|
|
193
|
+
const credentialVars = [];
|
|
194
|
+
for (const [name, value] of Object.entries(env)) {
|
|
195
|
+
if (this.isVariableSubstitution(value)) continue;
|
|
196
|
+
if (this.isPotentialCredential(name)) credentialVars.push({
|
|
197
|
+
name,
|
|
198
|
+
value: this.maskValue(value),
|
|
199
|
+
riskLevel: this.assessRiskLevel(name),
|
|
200
|
+
source: "env"
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
hasCredentials: credentialVars.length > 0,
|
|
205
|
+
credentialVars,
|
|
206
|
+
riskLevel: this.calculateOverallRiskLevel(credentialVars)
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Mask sensitive values for display (show only first and last character)
|
|
211
|
+
*/
|
|
212
|
+
static maskValue(value) {
|
|
213
|
+
if (!value || value.length <= 2) return value;
|
|
214
|
+
const first = value.charAt(0);
|
|
215
|
+
const last = value.charAt(value.length - 1);
|
|
216
|
+
const maskedLength = Math.min(value.length - 2, 8);
|
|
217
|
+
return `${first}${"*".repeat(maskedLength)}${last}`;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Assess risk level for a specific credential variable
|
|
221
|
+
*/
|
|
222
|
+
static assessRiskLevel(name) {
|
|
223
|
+
if (this.CREDENTIAL_PATTERNS.high.some((pattern) => pattern.test(name))) return "high";
|
|
224
|
+
if (this.CREDENTIAL_PATTERNS.low.some((pattern) => pattern.test(name))) return "low";
|
|
225
|
+
return "high";
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Calculate overall risk level based on all credential variables
|
|
229
|
+
*/
|
|
230
|
+
static calculateOverallRiskLevel(credentialVars) {
|
|
231
|
+
if (credentialVars.length === 0) return "none";
|
|
232
|
+
if (credentialVars.some((v) => v.riskLevel === "high")) return "high";
|
|
233
|
+
return "low";
|
|
234
|
+
}
|
|
294
235
|
};
|
|
295
|
-
|
|
296
236
|
// src/services/mcp-version-detection-service.ts
|
|
237
|
+
/**
|
|
238
|
+
* Service for detecting version information from MCP server configurations
|
|
239
|
+
* Specifically handles npx-based server commands to determine if they use
|
|
240
|
+
* pinned versions or implicit latest versions
|
|
241
|
+
*/
|
|
297
242
|
var MCPVersionDetectionService = class {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
const atIndex = packageSpec.lastIndexOf("@");
|
|
423
|
-
if (atIndex > 0) {
|
|
424
|
-
return {
|
|
425
|
-
name: packageSpec.substring(0, atIndex),
|
|
426
|
-
version: packageSpec.substring(atIndex + 1)
|
|
427
|
-
};
|
|
428
|
-
}
|
|
429
|
-
return { name: packageSpec, version: void 0 };
|
|
430
|
-
}
|
|
431
|
-
/**
|
|
432
|
-
* Determine if a version represents a pinned version
|
|
433
|
-
* @param version - The version string to check
|
|
434
|
-
* @returns true if the version is pinned, false if it's latest/implicit
|
|
435
|
-
*/
|
|
436
|
-
isPinnedVersion(version) {
|
|
437
|
-
if (!version) {
|
|
438
|
-
return false;
|
|
439
|
-
}
|
|
440
|
-
if (version === "latest") {
|
|
441
|
-
return false;
|
|
442
|
-
}
|
|
443
|
-
return true;
|
|
444
|
-
}
|
|
243
|
+
/**
|
|
244
|
+
* Analyze a server configuration to extract version information
|
|
245
|
+
* @param command - The command used to run the server
|
|
246
|
+
* @param args - Array of arguments passed to the command
|
|
247
|
+
* @returns PackageVersionInfo if analysis is possible, null otherwise
|
|
248
|
+
*/
|
|
249
|
+
analyzeServerVersion(command, args) {
|
|
250
|
+
if (![
|
|
251
|
+
"npx",
|
|
252
|
+
"uvx",
|
|
253
|
+
"uv"
|
|
254
|
+
].includes(command)) return null;
|
|
255
|
+
if (!args || args.length === 0) return null;
|
|
256
|
+
const packageName = this.extractPackageName(command, args);
|
|
257
|
+
if (!packageName) return null;
|
|
258
|
+
const { name, version } = this.parsePackageVersion(packageName);
|
|
259
|
+
const isPinned = this.isPinnedVersion(version);
|
|
260
|
+
return {
|
|
261
|
+
packageName: name,
|
|
262
|
+
version,
|
|
263
|
+
isPinned,
|
|
264
|
+
isLatest: !isPinned
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Extract the package name based on the command type
|
|
269
|
+
* @param command - The command used to run the server
|
|
270
|
+
* @param args - Array of arguments passed to the command
|
|
271
|
+
* @returns The package name/spec or null if not found
|
|
272
|
+
*/
|
|
273
|
+
extractPackageName(command, args) {
|
|
274
|
+
switch (command) {
|
|
275
|
+
case "npx": return this.extractNpxPackageName(args);
|
|
276
|
+
case "uvx": return this.extractUvxPackageName(args);
|
|
277
|
+
case "uv": return this.extractUvPackageName(args);
|
|
278
|
+
default: return null;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Extract the package name from npx arguments
|
|
283
|
+
* @param args - Array of arguments passed to npx
|
|
284
|
+
* @returns The package name/spec or null if not found
|
|
285
|
+
*/
|
|
286
|
+
extractNpxPackageName(args) {
|
|
287
|
+
if (!args || args.length === 0) return null;
|
|
288
|
+
const yIndex = args.indexOf("-y");
|
|
289
|
+
if (yIndex !== -1 && yIndex + 1 < args.length) return args[yIndex + 1];
|
|
290
|
+
const yesIndex = args.indexOf("--yes");
|
|
291
|
+
if (yesIndex !== -1 && yesIndex + 1 < args.length) return args[yesIndex + 1];
|
|
292
|
+
for (let i = 0; i < args.length; i++) {
|
|
293
|
+
const arg = args[i];
|
|
294
|
+
if (!arg.startsWith("-")) {
|
|
295
|
+
if (i > 0) {
|
|
296
|
+
const prevArg = args[i - 1];
|
|
297
|
+
if (prevArg === "--registry" || prevArg === "-r" || prevArg === "--package" || prevArg === "-p") continue;
|
|
298
|
+
}
|
|
299
|
+
return arg;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Extract the package name from uvx arguments
|
|
306
|
+
* @param args - Array of arguments passed to uvx
|
|
307
|
+
* @returns The package name/spec or null if not found
|
|
308
|
+
*/
|
|
309
|
+
extractUvxPackageName(args) {
|
|
310
|
+
if (!args || args.length === 0) return null;
|
|
311
|
+
return args[0];
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Extract the package name from uv arguments
|
|
315
|
+
* @param args - Array of arguments passed to uv
|
|
316
|
+
* @returns The package name/spec or null if not found
|
|
317
|
+
*/
|
|
318
|
+
extractUvPackageName(args) {
|
|
319
|
+
if (!args || args.length === 0) return null;
|
|
320
|
+
const runIndex = args.indexOf("run");
|
|
321
|
+
if (runIndex !== -1 && runIndex + 1 < args.length) return args[runIndex + 1];
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Parse a package specification to extract name and version
|
|
326
|
+
* @param packageSpec - Package specification (e.g., "package@1.0.0" or "package")
|
|
327
|
+
* @returns Object with name and optional version
|
|
328
|
+
*/
|
|
329
|
+
parsePackageVersion(packageSpec) {
|
|
330
|
+
if (!packageSpec) return {
|
|
331
|
+
name: "",
|
|
332
|
+
version: void 0
|
|
333
|
+
};
|
|
334
|
+
if (packageSpec.startsWith("@")) {
|
|
335
|
+
const parts = packageSpec.split("@");
|
|
336
|
+
if (parts.length === 2) return {
|
|
337
|
+
name: packageSpec,
|
|
338
|
+
version: void 0
|
|
339
|
+
};
|
|
340
|
+
else if (parts.length === 3) return {
|
|
341
|
+
name: `@${parts[1]}`,
|
|
342
|
+
version: parts[2]
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
const atIndex = packageSpec.lastIndexOf("@");
|
|
346
|
+
if (atIndex > 0) return {
|
|
347
|
+
name: packageSpec.substring(0, atIndex),
|
|
348
|
+
version: packageSpec.substring(atIndex + 1)
|
|
349
|
+
};
|
|
350
|
+
return {
|
|
351
|
+
name: packageSpec,
|
|
352
|
+
version: void 0
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Determine if a version represents a pinned version
|
|
357
|
+
* @param version - The version string to check
|
|
358
|
+
* @returns true if the version is pinned, false if it's latest/implicit
|
|
359
|
+
*/
|
|
360
|
+
isPinnedVersion(version) {
|
|
361
|
+
if (!version) return false;
|
|
362
|
+
if (version === "latest") return false;
|
|
363
|
+
return true;
|
|
364
|
+
}
|
|
445
365
|
};
|
|
446
|
-
|
|
447
366
|
// src/utils/url-utils.ts
|
|
367
|
+
/**
|
|
368
|
+
* Utility functions for URL operations
|
|
369
|
+
*/
|
|
370
|
+
/**
|
|
371
|
+
* Extract hostname from a URL string
|
|
372
|
+
* @param urlString - The URL string to extract hostname from
|
|
373
|
+
* @returns The hostname if valid URL, or the original string if parsing fails
|
|
374
|
+
*/
|
|
448
375
|
function extractHostname(urlString) {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
} catch (error) {
|
|
457
|
-
return urlString;
|
|
458
|
-
}
|
|
376
|
+
try {
|
|
377
|
+
let urlToParse = urlString;
|
|
378
|
+
if (!urlToParse.includes("://")) urlToParse = `http://${urlToParse}`;
|
|
379
|
+
return new URL(urlToParse).hostname;
|
|
380
|
+
} catch {
|
|
381
|
+
return urlString;
|
|
382
|
+
}
|
|
459
383
|
}
|
|
460
|
-
__name(extractHostname, "extractHostname");
|
|
461
|
-
|
|
462
384
|
// src/services/mcp-config-service.ts
|
|
463
385
|
var MCPConfigService = class {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
// Default status, will be updated by server manager
|
|
747
|
-
versionInfo: versionInfo || void 0,
|
|
748
|
-
credentials: CredentialDetectionService.analyzeServerConfig({
|
|
749
|
-
env: serverConfig.env,
|
|
750
|
-
args: serverConfig.args,
|
|
751
|
-
headers: serverConfig.headers
|
|
752
|
-
})
|
|
753
|
-
});
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
return serverInfos;
|
|
757
|
-
}
|
|
758
|
-
/**
|
|
759
|
-
* Get friendly name for an app
|
|
760
|
-
*/
|
|
761
|
-
getFriendlyName(appName) {
|
|
762
|
-
const friendlyNames = {
|
|
763
|
-
claude: "Claude Desktop",
|
|
764
|
-
claude_code: "Claude Code",
|
|
765
|
-
cursor: "Cursor",
|
|
766
|
-
vscode: "VS Code",
|
|
767
|
-
cline: "Cline",
|
|
768
|
-
windsurf: "Windsurf",
|
|
769
|
-
roo: "Roo",
|
|
770
|
-
"intellij-github-copilot": "IntelliJ GitHub Copilot",
|
|
771
|
-
junie: "IntelliJ Junie",
|
|
772
|
-
zed: "Zed",
|
|
773
|
-
gemini: "Gemini CLI"
|
|
774
|
-
};
|
|
775
|
-
return friendlyNames[appName] || appName;
|
|
776
|
-
}
|
|
386
|
+
pathRegistry;
|
|
387
|
+
currentOS;
|
|
388
|
+
debug;
|
|
389
|
+
directoryBubbleService;
|
|
390
|
+
versionDetectionService;
|
|
391
|
+
enableDirectoryBubbling;
|
|
392
|
+
constructor(options = {}) {
|
|
393
|
+
this.pathRegistry = new MCPPathRegistry();
|
|
394
|
+
this.currentOS = platform();
|
|
395
|
+
this.debug = util.debuglog("ls-mcp");
|
|
396
|
+
this.directoryBubbleService = new DirectoryBubbleService();
|
|
397
|
+
this.versionDetectionService = new MCPVersionDetectionService();
|
|
398
|
+
this.enableDirectoryBubbling = options.enableDirectoryBubbling ?? false;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Get MCP configuration files for a specific AI application on the current OS
|
|
402
|
+
*/
|
|
403
|
+
getConfigFilesPerApp(appName) {
|
|
404
|
+
try {
|
|
405
|
+
return this.pathRegistry.getPathsForApp(this.currentOS, appName);
|
|
406
|
+
} catch (error) {
|
|
407
|
+
throw new Error(`Failed to get config files for app '${appName}': ${error instanceof Error ? error.message : "Unknown error"}`, { cause: error });
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Get MCP configuration files for all AI applications on the current OS
|
|
412
|
+
*/
|
|
413
|
+
getAllConfigFiles() {
|
|
414
|
+
try {
|
|
415
|
+
return this.pathRegistry.getPathsForOS(this.currentOS);
|
|
416
|
+
} catch (error) {
|
|
417
|
+
throw new Error(`Failed to get all config files: ${error instanceof Error ? error.message : "Unknown error"}`, { cause: error });
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Get MCP servers configured for a specific AI application on the current OS
|
|
422
|
+
*/
|
|
423
|
+
async getMCPServersPerApp(appName) {
|
|
424
|
+
try {
|
|
425
|
+
const appPaths = this.getConfigFilesPerApp(appName);
|
|
426
|
+
const allServers = [];
|
|
427
|
+
for (const filePath of appPaths) {
|
|
428
|
+
const servers = await this.parseConfigFileForServers(filePath.filePath);
|
|
429
|
+
allServers.push(...servers);
|
|
430
|
+
}
|
|
431
|
+
return allServers;
|
|
432
|
+
} catch (error) {
|
|
433
|
+
throw new Error(`Failed to get MCP servers for app '${appName}': ${error instanceof Error ? error.message : "Unknown error"}`, { cause: error });
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Get MCP servers configured for all AI applications on the current OS
|
|
438
|
+
*/
|
|
439
|
+
async getAllMCPServers() {
|
|
440
|
+
try {
|
|
441
|
+
const allApps = this.pathRegistry.getSupportedApps(this.currentOS);
|
|
442
|
+
const allServers = {};
|
|
443
|
+
for (const appName of allApps) try {
|
|
444
|
+
allServers[appName] = await this.getMCPServersPerApp(appName);
|
|
445
|
+
} catch (error) {
|
|
446
|
+
this.debug(`Failed to get servers for app '${appName}': ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
447
|
+
allServers[appName] = [];
|
|
448
|
+
}
|
|
449
|
+
return allServers;
|
|
450
|
+
} catch (error) {
|
|
451
|
+
throw new Error(`Failed to get all MCP servers: ${error instanceof Error ? error.message : "Unknown error"}`, { cause: error });
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Get metadata for all supported AI applications on the current OS
|
|
456
|
+
*/
|
|
457
|
+
getSupportedApps() {
|
|
458
|
+
try {
|
|
459
|
+
const appNames = this.pathRegistry.getSupportedApps(this.currentOS);
|
|
460
|
+
const appPaths = this.pathRegistry.getPathsForOS(this.currentOS);
|
|
461
|
+
return appNames.map((appName) => ({
|
|
462
|
+
name: appName,
|
|
463
|
+
friendlyName: this.getFriendlyName(appName),
|
|
464
|
+
paths: appPaths[appName] || []
|
|
465
|
+
}));
|
|
466
|
+
} catch (error) {
|
|
467
|
+
throw new Error(`Failed to get supported apps: ${error instanceof Error ? error.message : "Unknown error"}`, { cause: error });
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Get all supported operating systems
|
|
472
|
+
*/
|
|
473
|
+
getSupportedOperatingSystems() {
|
|
474
|
+
return this.pathRegistry.getSupportedOperatingSystems();
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Validate if a configuration file exists and is parsable
|
|
478
|
+
*/
|
|
479
|
+
async validateConfigFile(filePath) {
|
|
480
|
+
try {
|
|
481
|
+
await fs.access(filePath);
|
|
482
|
+
return await this.createParser(filePath).isValidSyntax();
|
|
483
|
+
} catch {
|
|
484
|
+
return false;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Create a parser instance (can be overridden for testing)
|
|
489
|
+
*/
|
|
490
|
+
createParser(filePath) {
|
|
491
|
+
return new MCPConfigParser(filePath);
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Get MCP file groups with resolved paths and server information
|
|
495
|
+
*/
|
|
496
|
+
async getMCPFileGroups() {
|
|
497
|
+
try {
|
|
498
|
+
const appPaths = this.getAllConfigFiles();
|
|
499
|
+
const mcpFilesPathsData = {};
|
|
500
|
+
for (const groupName of Object.keys(appPaths)) {
|
|
501
|
+
const paths = appPaths[groupName];
|
|
502
|
+
mcpFilesPathsData[groupName] = {
|
|
503
|
+
name: groupName,
|
|
504
|
+
friendlyName: this.getFriendlyName(groupName),
|
|
505
|
+
paths: [],
|
|
506
|
+
stats: { serversCount: 0 }
|
|
507
|
+
};
|
|
508
|
+
const uniqueFilePaths = /* @__PURE__ */ new Set();
|
|
509
|
+
let totalServersCount = 0;
|
|
510
|
+
for (const filePathData of paths) {
|
|
511
|
+
let resolvedPath = filePathData.filePath.replace("~", process.env.HOME || "");
|
|
512
|
+
let absolutePath = path.resolve(resolvedPath);
|
|
513
|
+
if (filePathData.type === "local" && this.enableDirectoryBubbling) try {
|
|
514
|
+
await fs.access(resolvedPath);
|
|
515
|
+
} catch {
|
|
516
|
+
const bubbledPath = await this.directoryBubbleService.findLocalConfigInParentDirectories(filePathData.filePath, process.cwd());
|
|
517
|
+
if (bubbledPath) {
|
|
518
|
+
resolvedPath = bubbledPath;
|
|
519
|
+
absolutePath = path.resolve(resolvedPath);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
if (uniqueFilePaths.has(absolutePath)) continue;
|
|
523
|
+
uniqueFilePaths.add(absolutePath);
|
|
524
|
+
try {
|
|
525
|
+
await fs.access(resolvedPath);
|
|
526
|
+
const parser = this.createParser(resolvedPath);
|
|
527
|
+
const parsable = await parser.isValidSyntax();
|
|
528
|
+
filePathData.parsable = parsable;
|
|
529
|
+
if (parsable) {
|
|
530
|
+
const configData = await parser.parseConfigFile();
|
|
531
|
+
const servers = await this.convertToMCPServerInfo(configData.servers || {});
|
|
532
|
+
filePathData.servers = servers;
|
|
533
|
+
totalServersCount += servers.length;
|
|
534
|
+
}
|
|
535
|
+
mcpFilesPathsData[groupName].paths.push(filePathData);
|
|
536
|
+
} catch (error) {
|
|
537
|
+
this.debug(`Skipping file ${resolvedPath}: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
if (mcpFilesPathsData[groupName] && mcpFilesPathsData[groupName].stats) mcpFilesPathsData[groupName].stats.serversCount = totalServersCount;
|
|
541
|
+
}
|
|
542
|
+
return mcpFilesPathsData;
|
|
543
|
+
} catch (error) {
|
|
544
|
+
throw new Error(`Failed to get MCP file groups: ${error instanceof Error ? error.message : "Unknown error"}`, { cause: error });
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Parse custom configuration files provided by the user
|
|
549
|
+
* This method processes files independently of standard app-based discovery
|
|
550
|
+
*/
|
|
551
|
+
async parseCustomFiles(filePaths) {
|
|
552
|
+
try {
|
|
553
|
+
const mcpFilesPathsData = { custom: {
|
|
554
|
+
name: "custom",
|
|
555
|
+
friendlyName: "Custom Files",
|
|
556
|
+
paths: [],
|
|
557
|
+
stats: { serversCount: 0 }
|
|
558
|
+
} };
|
|
559
|
+
let totalServersCount = 0;
|
|
560
|
+
for (const filePath of filePaths) {
|
|
561
|
+
const resolvedPath = filePath.replace("~", process.env.HOME || "");
|
|
562
|
+
const absolutePath = path.resolve(resolvedPath);
|
|
563
|
+
try {
|
|
564
|
+
await fs.access(absolutePath);
|
|
565
|
+
const parser = this.createParser(absolutePath);
|
|
566
|
+
const parsable = await parser.isValidSyntax();
|
|
567
|
+
const filePathData = {
|
|
568
|
+
filePath: absolutePath,
|
|
569
|
+
type: "local",
|
|
570
|
+
parsable
|
|
571
|
+
};
|
|
572
|
+
if (parsable) {
|
|
573
|
+
const configData = await parser.parseConfigFile();
|
|
574
|
+
const servers = await this.convertToMCPServerInfo(configData.servers || {});
|
|
575
|
+
filePathData.servers = servers;
|
|
576
|
+
totalServersCount += servers.length;
|
|
577
|
+
} else {
|
|
578
|
+
this.debug(`File ${absolutePath} has invalid syntax`);
|
|
579
|
+
filePathData.servers = [];
|
|
580
|
+
}
|
|
581
|
+
mcpFilesPathsData.custom.paths.push(filePathData);
|
|
582
|
+
} catch (error) {
|
|
583
|
+
this.debug(`Skipping file ${absolutePath}: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
584
|
+
mcpFilesPathsData.custom.paths.push({
|
|
585
|
+
filePath: absolutePath,
|
|
586
|
+
type: "local",
|
|
587
|
+
parsable: false,
|
|
588
|
+
servers: []
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
if (mcpFilesPathsData.custom.stats) mcpFilesPathsData.custom.stats.serversCount = totalServersCount;
|
|
593
|
+
return mcpFilesPathsData;
|
|
594
|
+
} catch (error) {
|
|
595
|
+
throw new Error(`Failed to parse custom files: ${error instanceof Error ? error.message : "Unknown error"}`, { cause: error });
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* Register a custom app with custom paths for the current OS
|
|
600
|
+
*/
|
|
601
|
+
registerCustomApp(appName, paths) {
|
|
602
|
+
try {
|
|
603
|
+
this.pathRegistry.registerCustomApp(this.currentOS, appName, paths);
|
|
604
|
+
} catch (error) {
|
|
605
|
+
throw new Error(`Failed to register custom app '${appName}': ${error instanceof Error ? error.message : "Unknown error"}`, { cause: error });
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Parse a configuration file and return server information
|
|
610
|
+
*/
|
|
611
|
+
async parseConfigFileForServers(filePath) {
|
|
612
|
+
try {
|
|
613
|
+
const configData = await this.createParser(filePath).parseConfigFile();
|
|
614
|
+
return await this.convertToMCPServerInfo(configData.servers || {});
|
|
615
|
+
} catch (error) {
|
|
616
|
+
this.debug(`Failed to parse config file ${filePath}: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
617
|
+
return [];
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* Convert parsed server configs to MCPServerInfo format
|
|
622
|
+
*/
|
|
623
|
+
async convertToMCPServerInfo(servers) {
|
|
624
|
+
const serverInfos = [];
|
|
625
|
+
for (const [serverName, serverConfig] of Object.entries(servers)) if (serverConfig && typeof serverConfig === "object") {
|
|
626
|
+
let source;
|
|
627
|
+
if (serverConfig.url) source = extractHostname(serverConfig.url);
|
|
628
|
+
else source = serverConfig.command || "";
|
|
629
|
+
const versionInfo = this.versionDetectionService.analyzeServerVersion(serverConfig.command || "", Array.isArray(serverConfig.args) ? serverConfig.args : void 0);
|
|
630
|
+
serverInfos.push({
|
|
631
|
+
name: serverName,
|
|
632
|
+
command: serverConfig.command || "",
|
|
633
|
+
args: Array.isArray(serverConfig.args) ? serverConfig.args : void 0,
|
|
634
|
+
transport: serverConfig.type === "streamable-http" ? "http" : serverConfig.type,
|
|
635
|
+
type: serverConfig.type,
|
|
636
|
+
source,
|
|
637
|
+
env: serverConfig.env,
|
|
638
|
+
headers: serverConfig.headers,
|
|
639
|
+
status: "stopped",
|
|
640
|
+
versionInfo: versionInfo || void 0,
|
|
641
|
+
credentials: CredentialDetectionService.analyzeServerConfig({
|
|
642
|
+
env: serverConfig.env,
|
|
643
|
+
args: serverConfig.args,
|
|
644
|
+
headers: serverConfig.headers
|
|
645
|
+
})
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
return serverInfos;
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Get friendly name for an app
|
|
652
|
+
*/
|
|
653
|
+
getFriendlyName(appName) {
|
|
654
|
+
return {
|
|
655
|
+
claude: "Claude Desktop",
|
|
656
|
+
claude_code: "Claude Code",
|
|
657
|
+
cursor: "Cursor",
|
|
658
|
+
vscode: "VS Code",
|
|
659
|
+
cline: "Cline",
|
|
660
|
+
windsurf: "Windsurf",
|
|
661
|
+
roo: "Roo",
|
|
662
|
+
"intellij-github-copilot": "IntelliJ GitHub Copilot",
|
|
663
|
+
junie: "IntelliJ Junie",
|
|
664
|
+
zed: "Zed",
|
|
665
|
+
gemini: "Gemini CLI"
|
|
666
|
+
}[appName] || appName;
|
|
667
|
+
}
|
|
777
668
|
};
|
|
778
|
-
|
|
779
669
|
// src/services/mcp-server-manager-service.ts
|
|
780
|
-
import path2 from "path";
|
|
781
|
-
import { execSync } from "child_process";
|
|
782
|
-
import { platform as platform2 } from "os";
|
|
783
670
|
var MCPServerManagerService = class {
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
return mcpServerName;
|
|
1050
|
-
}
|
|
1051
|
-
for (let i = 0; i < this.args.length; i++) {
|
|
1052
|
-
if (this.args[i] === "--from" && i + 1 < this.args.length) {
|
|
1053
|
-
mcpServerName = this.args[i + 1];
|
|
1054
|
-
return mcpServerName;
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
const firstArg = this.args[0];
|
|
1058
|
-
if (firstArg.startsWith("-") || firstArg.startsWith("--")) {
|
|
1059
|
-
const lastArg = this.args[this.args.length - 1];
|
|
1060
|
-
mcpServerName = lastArg;
|
|
1061
|
-
return mcpServerName;
|
|
1062
|
-
}
|
|
1063
|
-
mcpServerName = firstArg;
|
|
1064
|
-
return mcpServerName;
|
|
1065
|
-
}
|
|
1066
|
-
matchUvxProcess(commandTokens) {
|
|
1067
|
-
if (commandTokens.length === 0) return false;
|
|
1068
|
-
const mcpServerName = this.getUvxMcpServerNameFromArgs();
|
|
1069
|
-
if (!mcpServerName) return false;
|
|
1070
|
-
return this.findMcpServerNameInProcessArguments(commandTokens, mcpServerName);
|
|
1071
|
-
}
|
|
1072
|
-
findMcpServerNameInProcessArguments(commandTokens, mcpServerName) {
|
|
1073
|
-
for (let i = 0; i < commandTokens.length; i++) {
|
|
1074
|
-
const token = commandTokens[i].toLowerCase();
|
|
1075
|
-
const normalizedMcpServerName = mcpServerName.toLowerCase();
|
|
1076
|
-
if (normalizedMcpServerName === token || token.includes(normalizedMcpServerName)) {
|
|
1077
|
-
return true;
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
return false;
|
|
1081
|
-
}
|
|
1082
|
-
parseCSVLine(line) {
|
|
1083
|
-
const result = [];
|
|
1084
|
-
let current = "";
|
|
1085
|
-
let inQuotes = false;
|
|
1086
|
-
for (let i = 0; i < line.length; i++) {
|
|
1087
|
-
const char = line[i];
|
|
1088
|
-
if (char === '"') {
|
|
1089
|
-
if (inQuotes && line[i + 1] === '"') {
|
|
1090
|
-
current += '"';
|
|
1091
|
-
i++;
|
|
1092
|
-
} else {
|
|
1093
|
-
inQuotes = !inQuotes;
|
|
1094
|
-
}
|
|
1095
|
-
} else if (char === "," && !inQuotes) {
|
|
1096
|
-
result.push(current);
|
|
1097
|
-
current = "";
|
|
1098
|
-
} else {
|
|
1099
|
-
current += char;
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
result.push(current);
|
|
1103
|
-
return result;
|
|
1104
|
-
}
|
|
1105
|
-
parseCommandLine(commandLine) {
|
|
1106
|
-
const tokens = [];
|
|
1107
|
-
let current = "";
|
|
1108
|
-
let inQuotes = false;
|
|
1109
|
-
let quoteChar = "";
|
|
1110
|
-
for (let i = 0; i < commandLine.length; i++) {
|
|
1111
|
-
const char = commandLine[i];
|
|
1112
|
-
if (!inQuotes && (char === '"' || char === "'")) {
|
|
1113
|
-
inQuotes = true;
|
|
1114
|
-
quoteChar = char;
|
|
1115
|
-
} else if (inQuotes && char === quoteChar) {
|
|
1116
|
-
inQuotes = false;
|
|
1117
|
-
quoteChar = "";
|
|
1118
|
-
} else if (!inQuotes && char === " ") {
|
|
1119
|
-
if (current.trim()) {
|
|
1120
|
-
tokens.push(current.trim());
|
|
1121
|
-
current = "";
|
|
1122
|
-
}
|
|
1123
|
-
} else {
|
|
1124
|
-
current += char;
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
if (current.trim()) {
|
|
1128
|
-
tokens.push(current.trim());
|
|
1129
|
-
}
|
|
1130
|
-
return tokens;
|
|
1131
|
-
}
|
|
1132
|
-
/*
|
|
1133
|
-
example to match:
|
|
1134
|
-
```
|
|
1135
|
-
"command": "npx",
|
|
1136
|
-
"args": [
|
|
1137
|
-
"-y",
|
|
1138
|
-
"@modelcontextprotocol/server-postgres",
|
|
1139
|
-
"postgresql://localhost/mydb"
|
|
1140
|
-
]
|
|
1141
|
-
}
|
|
1142
|
-
```
|
|
1143
|
-
|
|
1144
|
-
with a process command like:
|
|
1145
|
-
```
|
|
1146
|
-
npm exec @modelcontextprotocol/server-postgres postgresql://localhost/mydb
|
|
1147
|
-
```
|
|
1148
|
-
*/
|
|
1149
|
-
matchNpxProcess(commandTokens) {
|
|
1150
|
-
if (commandTokens.length < 3) return false;
|
|
1151
|
-
if (commandTokens[1] !== "exec") return false;
|
|
1152
|
-
let argsToMatch = [];
|
|
1153
|
-
const yIndex = this.args.indexOf("-y");
|
|
1154
|
-
if (yIndex !== -1 && yIndex + 1 < this.args.length) {
|
|
1155
|
-
argsToMatch = this.args.slice(yIndex + 1);
|
|
1156
|
-
} else {
|
|
1157
|
-
argsToMatch = this.args;
|
|
1158
|
-
}
|
|
1159
|
-
if (commandTokens.length - 2 !== argsToMatch.length) {
|
|
1160
|
-
return false;
|
|
1161
|
-
}
|
|
1162
|
-
for (let i = 0; i < argsToMatch.length; i++) {
|
|
1163
|
-
const commandToken = commandTokens[i + 2].toLowerCase();
|
|
1164
|
-
const expectedArg = argsToMatch[i].toLowerCase();
|
|
1165
|
-
if (commandToken !== expectedArg) {
|
|
1166
|
-
return false;
|
|
1167
|
-
}
|
|
1168
|
-
}
|
|
1169
|
-
return true;
|
|
1170
|
-
}
|
|
671
|
+
name;
|
|
672
|
+
command;
|
|
673
|
+
args;
|
|
674
|
+
transport;
|
|
675
|
+
source;
|
|
676
|
+
env;
|
|
677
|
+
running = false;
|
|
678
|
+
constructor(serverConfig) {
|
|
679
|
+
this.name = serverConfig.name;
|
|
680
|
+
this.command = serverConfig.command;
|
|
681
|
+
this.args = serverConfig.args || [];
|
|
682
|
+
this.transport = serverConfig.transport || "stdio";
|
|
683
|
+
if (serverConfig?.type && serverConfig.type === "sse") this.transport = "sse";
|
|
684
|
+
if (serverConfig?.type && (serverConfig.type === "http" || serverConfig.type === "streamable-http")) this.transport = "http";
|
|
685
|
+
if (serverConfig?.type && serverConfig.type === "stdio") this.transport = "stdio";
|
|
686
|
+
if (serverConfig.url) {
|
|
687
|
+
this.source = extractHostname(serverConfig.url);
|
|
688
|
+
this.transport = "http";
|
|
689
|
+
} else {
|
|
690
|
+
const fullCommand = [serverConfig.command, ...serverConfig.args || []].join(" ");
|
|
691
|
+
this.source = fullCommand;
|
|
692
|
+
}
|
|
693
|
+
this.env = serverConfig.env || {};
|
|
694
|
+
}
|
|
695
|
+
getName() {
|
|
696
|
+
return this.name;
|
|
697
|
+
}
|
|
698
|
+
getCmd() {
|
|
699
|
+
return this.command;
|
|
700
|
+
}
|
|
701
|
+
getArgs() {
|
|
702
|
+
return this.args;
|
|
703
|
+
}
|
|
704
|
+
getTransport() {
|
|
705
|
+
return this.transport;
|
|
706
|
+
}
|
|
707
|
+
getSource() {
|
|
708
|
+
return this.source;
|
|
709
|
+
}
|
|
710
|
+
getEnv() {
|
|
711
|
+
return this.env;
|
|
712
|
+
}
|
|
713
|
+
isRunning() {
|
|
714
|
+
try {
|
|
715
|
+
let psOutput;
|
|
716
|
+
if (platform() === "win32") psOutput = execSync("powershell -Command \"Get-CimInstance -ClassName Win32_Process | Select-Object ProcessId,Name,CommandLine,ParentProcessId | ConvertTo-Csv -NoTypeInformation\"", {
|
|
717
|
+
encoding: "utf8",
|
|
718
|
+
timeout: 5e3
|
|
719
|
+
});
|
|
720
|
+
else psOutput = execSync("ps -eao pid,ppid,args", {
|
|
721
|
+
encoding: "utf8",
|
|
722
|
+
timeout: 5e3
|
|
723
|
+
});
|
|
724
|
+
const processMap = /* @__PURE__ */ new Map();
|
|
725
|
+
const processes = psOutput.trim().split("\n");
|
|
726
|
+
for (const processLine of processes) {
|
|
727
|
+
if (!processLine.trim()) continue;
|
|
728
|
+
let pid;
|
|
729
|
+
let ppid;
|
|
730
|
+
let commandLine;
|
|
731
|
+
if (platform() === "win32") {
|
|
732
|
+
if (processLine.startsWith("\"ProcessId\"") || processLine.startsWith("ProcessId")) continue;
|
|
733
|
+
const parts = this.parseCSVLine(processLine);
|
|
734
|
+
if (parts.length < 4) continue;
|
|
735
|
+
pid = parts[0].trim() || "";
|
|
736
|
+
commandLine = parts[2].trim() || "";
|
|
737
|
+
ppid = parts[3].trim() || "";
|
|
738
|
+
} else {
|
|
739
|
+
const match = processLine.trim().match(/^\s*(\d+)\s+(\d+)\s+(.+)$/);
|
|
740
|
+
if (!match) continue;
|
|
741
|
+
pid = match[1].trim() || "";
|
|
742
|
+
ppid = match[2].trim() || "";
|
|
743
|
+
commandLine = match[3].trim() || "";
|
|
744
|
+
}
|
|
745
|
+
const commandTokens = this.parseCommandLine(commandLine);
|
|
746
|
+
if (commandTokens.length > 0) processMap.set(pid, {
|
|
747
|
+
ppid,
|
|
748
|
+
commandTokens
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
let mcpServerDetection;
|
|
752
|
+
for (const [pid, processData] of processMap) {
|
|
753
|
+
const commandMatchLinux = this.isCommandMatch(processData.commandTokens);
|
|
754
|
+
let commandMatchWin32 = false;
|
|
755
|
+
if (platform() === "win32") {
|
|
756
|
+
let commandTokensOnWin32 = processData.commandTokens;
|
|
757
|
+
if (commandTokensOnWin32.length > 0 && commandTokensOnWin32[0].toLowerCase().startsWith("cmd")) {
|
|
758
|
+
commandTokensOnWin32 = commandTokensOnWin32.slice(1);
|
|
759
|
+
while (commandTokensOnWin32.length > 0 && commandTokensOnWin32[0].startsWith("/")) commandTokensOnWin32 = commandTokensOnWin32.slice(1);
|
|
760
|
+
}
|
|
761
|
+
commandMatchWin32 = this.isCommandMatch(commandTokensOnWin32);
|
|
762
|
+
}
|
|
763
|
+
if (commandMatchLinux || commandMatchWin32) {
|
|
764
|
+
mcpServerDetection = {
|
|
765
|
+
pid,
|
|
766
|
+
commandLine: processData.commandTokens.join(" "),
|
|
767
|
+
ppid: processData.ppid
|
|
768
|
+
};
|
|
769
|
+
const parentProcess = processMap.get(processData.ppid);
|
|
770
|
+
if (parentProcess) {
|
|
771
|
+
const { estimatedVendor, estimatedProduct } = this.getVendorFromCommand(parentProcess.commandTokens) || {};
|
|
772
|
+
if (estimatedProduct || estimatedVendor) {
|
|
773
|
+
mcpServerDetection = {
|
|
774
|
+
...mcpServerDetection,
|
|
775
|
+
parentCommandLine: parentProcess.commandTokens.join(" "),
|
|
776
|
+
estimatedVendor,
|
|
777
|
+
estimatedProduct
|
|
778
|
+
};
|
|
779
|
+
return mcpServerDetection;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
if (mcpServerDetection) return mcpServerDetection;
|
|
785
|
+
return false;
|
|
786
|
+
} catch {
|
|
787
|
+
return false;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
getVendorFromCommand(commandTokens) {
|
|
791
|
+
const commandString = commandTokens.join(" ").toLowerCase();
|
|
792
|
+
if (commandString.includes("claude.app")) return {
|
|
793
|
+
estimatedVendor: "anthropic",
|
|
794
|
+
estimatedProduct: "claude-desktop"
|
|
795
|
+
};
|
|
796
|
+
if (commandString.includes("claude")) return {
|
|
797
|
+
estimatedVendor: "anthropic",
|
|
798
|
+
estimatedProduct: "claude-desktop"
|
|
799
|
+
};
|
|
800
|
+
if (commandString.includes("cursor")) return {
|
|
801
|
+
estimatedVendor: "cursor",
|
|
802
|
+
estimatedProduct: "cursor"
|
|
803
|
+
};
|
|
804
|
+
if (commandString.includes("visual studio code") || commandString.includes("vscode")) return {
|
|
805
|
+
estimatedVendor: "vscode",
|
|
806
|
+
estimatedProduct: "vscode"
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
isCommandMatch(commandTokens) {
|
|
810
|
+
if (commandTokens.length === 0) return false;
|
|
811
|
+
const baseCommand = this.getBaseCommand(commandTokens[0]);
|
|
812
|
+
const commandInConfig = this.getBaseCommand(this.command);
|
|
813
|
+
if (commandInConfig === "uvx" && baseCommand === "uv") return this.matchUvxProcess(commandTokens);
|
|
814
|
+
if (commandInConfig === "npx" && baseCommand === "npm") return this.matchNpxProcess(commandTokens);
|
|
815
|
+
if (commandInConfig === "uv" && baseCommand === "uv") return this.matchGenericArgsToArgs(commandTokens);
|
|
816
|
+
const commandConfigPythonBase = this.getBaseCommand(this.command);
|
|
817
|
+
const commandAliasesPython = [
|
|
818
|
+
"python3",
|
|
819
|
+
"python",
|
|
820
|
+
"python3.10",
|
|
821
|
+
"python3.11",
|
|
822
|
+
"python3.12",
|
|
823
|
+
"cpython3",
|
|
824
|
+
"cpython",
|
|
825
|
+
"python3",
|
|
826
|
+
"python2"
|
|
827
|
+
];
|
|
828
|
+
if (commandAliasesPython.includes(commandConfigPythonBase) && commandAliasesPython.includes(baseCommand)) return this.matchGenericArgsToArgs(commandTokens);
|
|
829
|
+
if (this.getBaseCommand(this.command) === this.getBaseCommand(commandTokens[0])) return this.matchGenericArgsToArgs(commandTokens);
|
|
830
|
+
return false;
|
|
831
|
+
}
|
|
832
|
+
matchGenericArgsToArgs(commandTokens) {
|
|
833
|
+
if (this.args.length === 0) return commandTokens[0] === this.command;
|
|
834
|
+
if (commandTokens.length < 2) return false;
|
|
835
|
+
const commandWithoutArgs = commandTokens.slice(1);
|
|
836
|
+
for (let i = 0; i < this.args.length; i++) {
|
|
837
|
+
if (i >= commandWithoutArgs.length) return false;
|
|
838
|
+
const arg = this.args[i].toLowerCase();
|
|
839
|
+
const token = commandWithoutArgs[i].toLowerCase();
|
|
840
|
+
if (arg !== token && !token.includes(arg)) return false;
|
|
841
|
+
}
|
|
842
|
+
return true;
|
|
843
|
+
}
|
|
844
|
+
getBaseCommand(fullCommandPath) {
|
|
845
|
+
let baseCommand = path.basename(fullCommandPath);
|
|
846
|
+
if (platform() === "win32") baseCommand = path.basename(fullCommandPath, ".exe");
|
|
847
|
+
baseCommand = baseCommand.toLowerCase();
|
|
848
|
+
return baseCommand;
|
|
849
|
+
}
|
|
850
|
+
getUvxMcpServerNameFromArgs() {
|
|
851
|
+
if (this.args.length === 0) return void 0;
|
|
852
|
+
let mcpServerName;
|
|
853
|
+
if (this.args.length === 1) {
|
|
854
|
+
mcpServerName = this.args[0];
|
|
855
|
+
return mcpServerName;
|
|
856
|
+
}
|
|
857
|
+
for (let i = 0; i < this.args.length; i++) if (this.args[i] === "--from" && i + 1 < this.args.length) {
|
|
858
|
+
mcpServerName = this.args[i + 1];
|
|
859
|
+
return mcpServerName;
|
|
860
|
+
}
|
|
861
|
+
const firstArg = this.args[0];
|
|
862
|
+
if (firstArg.startsWith("-") || firstArg.startsWith("--")) {
|
|
863
|
+
mcpServerName = this.args[this.args.length - 1];
|
|
864
|
+
return mcpServerName;
|
|
865
|
+
}
|
|
866
|
+
mcpServerName = firstArg;
|
|
867
|
+
return mcpServerName;
|
|
868
|
+
}
|
|
869
|
+
matchUvxProcess(commandTokens) {
|
|
870
|
+
if (commandTokens.length === 0) return false;
|
|
871
|
+
const mcpServerName = this.getUvxMcpServerNameFromArgs();
|
|
872
|
+
if (!mcpServerName) return false;
|
|
873
|
+
return this.findMcpServerNameInProcessArguments(commandTokens, mcpServerName);
|
|
874
|
+
}
|
|
875
|
+
findMcpServerNameInProcessArguments(commandTokens, mcpServerName) {
|
|
876
|
+
for (let i = 0; i < commandTokens.length; i++) {
|
|
877
|
+
const token = commandTokens[i].toLowerCase();
|
|
878
|
+
const normalizedMcpServerName = mcpServerName.toLowerCase();
|
|
879
|
+
if (normalizedMcpServerName === token || token.includes(normalizedMcpServerName)) return true;
|
|
880
|
+
}
|
|
881
|
+
return false;
|
|
882
|
+
}
|
|
883
|
+
parseCSVLine(line) {
|
|
884
|
+
const result = [];
|
|
885
|
+
let current = "";
|
|
886
|
+
let inQuotes = false;
|
|
887
|
+
for (let i = 0; i < line.length; i++) {
|
|
888
|
+
const char = line[i];
|
|
889
|
+
if (char === "\"") {
|
|
890
|
+
if (inQuotes && line[i + 1] === "\"") {
|
|
891
|
+
current += "\"";
|
|
892
|
+
i++;
|
|
893
|
+
} else inQuotes = !inQuotes;
|
|
894
|
+
} else if (char === "," && !inQuotes) {
|
|
895
|
+
result.push(current);
|
|
896
|
+
current = "";
|
|
897
|
+
} else current += char;
|
|
898
|
+
}
|
|
899
|
+
result.push(current);
|
|
900
|
+
return result;
|
|
901
|
+
}
|
|
902
|
+
parseCommandLine(commandLine) {
|
|
903
|
+
const tokens = [];
|
|
904
|
+
let current = "";
|
|
905
|
+
let inQuotes = false;
|
|
906
|
+
let quoteChar = "";
|
|
907
|
+
for (let i = 0; i < commandLine.length; i++) {
|
|
908
|
+
const char = commandLine[i];
|
|
909
|
+
if (!inQuotes && (char === "\"" || char === "'")) {
|
|
910
|
+
inQuotes = true;
|
|
911
|
+
quoteChar = char;
|
|
912
|
+
} else if (inQuotes && char === quoteChar) {
|
|
913
|
+
inQuotes = false;
|
|
914
|
+
quoteChar = "";
|
|
915
|
+
} else if (!inQuotes && char === " ") {
|
|
916
|
+
if (current.trim()) {
|
|
917
|
+
tokens.push(current.trim());
|
|
918
|
+
current = "";
|
|
919
|
+
}
|
|
920
|
+
} else current += char;
|
|
921
|
+
}
|
|
922
|
+
if (current.trim()) tokens.push(current.trim());
|
|
923
|
+
return tokens;
|
|
924
|
+
}
|
|
925
|
+
matchNpxProcess(commandTokens) {
|
|
926
|
+
if (commandTokens.length < 3) return false;
|
|
927
|
+
if (commandTokens[1] !== "exec") return false;
|
|
928
|
+
let argsToMatch;
|
|
929
|
+
const yIndex = this.args.indexOf("-y");
|
|
930
|
+
if (yIndex !== -1 && yIndex + 1 < this.args.length) argsToMatch = this.args.slice(yIndex + 1);
|
|
931
|
+
else argsToMatch = this.args;
|
|
932
|
+
if (commandTokens.length - 2 !== argsToMatch.length) return false;
|
|
933
|
+
for (let i = 0; i < argsToMatch.length; i++) if (commandTokens[i + 2].toLowerCase() !== argsToMatch[i].toLowerCase()) return false;
|
|
934
|
+
return true;
|
|
935
|
+
}
|
|
1171
936
|
};
|
|
1172
|
-
|
|
1173
937
|
// src/main.ts
|
|
1174
938
|
var MCPFiles = class {
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
if (typeof processDetection === "object" && processDetection.estimatedProduct === group.name) {
|
|
1240
|
-
isRunning = true;
|
|
1241
|
-
}
|
|
1242
|
-
}
|
|
1243
|
-
server.status = isRunning ? "running" : "stopped";
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
return mcpFilesPathsData;
|
|
1249
|
-
} catch (error) {
|
|
1250
|
-
throw new Error(`Failed to find MCP files: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
/**
|
|
1254
|
-
* Get MCP configuration service instance for advanced operations
|
|
1255
|
-
*/
|
|
1256
|
-
getMCPConfigService() {
|
|
1257
|
-
return this.mcpConfigService;
|
|
1258
|
-
}
|
|
939
|
+
mcpConfigService;
|
|
940
|
+
customFiles;
|
|
941
|
+
constructor(customFiles) {
|
|
942
|
+
this.mcpConfigService = new MCPConfigService({ enableDirectoryBubbling: true });
|
|
943
|
+
this.customFiles = customFiles;
|
|
944
|
+
}
|
|
945
|
+
/**
|
|
946
|
+
* Find and process all MCP configuration files
|
|
947
|
+
* If customFiles are provided, only those files are processed (replaces automatic discovery)
|
|
948
|
+
*/
|
|
949
|
+
async findFiles() {
|
|
950
|
+
try {
|
|
951
|
+
if (this.customFiles && this.customFiles.length > 0) {
|
|
952
|
+
const mcpFilesPathsData = await this.mcpConfigService.parseCustomFiles(this.customFiles);
|
|
953
|
+
for (const groupName of Object.keys(mcpFilesPathsData)) {
|
|
954
|
+
const group = mcpFilesPathsData[groupName];
|
|
955
|
+
for (const filePathData of group.paths) if (filePathData.servers && filePathData.servers.length > 0) for (const server of filePathData.servers) {
|
|
956
|
+
const processDetection = new MCPServerManagerService({
|
|
957
|
+
name: server.name,
|
|
958
|
+
command: server.command,
|
|
959
|
+
args: server.args,
|
|
960
|
+
transport: server.transport,
|
|
961
|
+
type: server.type,
|
|
962
|
+
env: server.env
|
|
963
|
+
}).isRunning();
|
|
964
|
+
let isRunning = false;
|
|
965
|
+
if (processDetection) {
|
|
966
|
+
if (typeof processDetection === "object" && processDetection.estimatedProduct === group.name) isRunning = true;
|
|
967
|
+
}
|
|
968
|
+
server.status = isRunning ? "running" : "stopped";
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
return mcpFilesPathsData;
|
|
972
|
+
}
|
|
973
|
+
const mcpFilesPathsData = await this.mcpConfigService.getMCPFileGroups();
|
|
974
|
+
for (const groupName of Object.keys(mcpFilesPathsData)) {
|
|
975
|
+
const group = mcpFilesPathsData[groupName];
|
|
976
|
+
for (const filePathData of group.paths) if (filePathData.servers && filePathData.servers.length > 0) for (const server of filePathData.servers) {
|
|
977
|
+
const processDetection = new MCPServerManagerService({
|
|
978
|
+
name: server.name,
|
|
979
|
+
command: server.command,
|
|
980
|
+
args: server.args,
|
|
981
|
+
transport: server.transport,
|
|
982
|
+
type: server.type,
|
|
983
|
+
env: server.env
|
|
984
|
+
}).isRunning();
|
|
985
|
+
let isRunning = false;
|
|
986
|
+
if (processDetection) {
|
|
987
|
+
if (typeof processDetection === "object" && processDetection.estimatedProduct === group.name) isRunning = true;
|
|
988
|
+
}
|
|
989
|
+
server.status = isRunning ? "running" : "stopped";
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
return mcpFilesPathsData;
|
|
993
|
+
} catch (error) {
|
|
994
|
+
throw new Error(`Failed to find MCP files: ${error instanceof Error ? error.message : "Unknown error"}`, { cause: error });
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
/**
|
|
998
|
+
* Get MCP configuration service instance for advanced operations
|
|
999
|
+
*/
|
|
1000
|
+
getMCPConfigService() {
|
|
1001
|
+
return this.mcpConfigService;
|
|
1002
|
+
}
|
|
1259
1003
|
};
|
|
1260
|
-
|
|
1261
|
-
// src/services/render-service.ts
|
|
1262
|
-
import { styleText as styleText11 } from "util";
|
|
1263
|
-
|
|
1264
1004
|
// src/components/transport.ts
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
if (formattedText === "SSE") {
|
|
1273
|
-
data = styleText(["blue"], formattedText);
|
|
1274
|
-
}
|
|
1275
|
-
if (formattedText === "HTTP") {
|
|
1276
|
-
data = styleText(["blue"], formattedText);
|
|
1277
|
-
}
|
|
1278
|
-
return data;
|
|
1005
|
+
function render$7(text) {
|
|
1006
|
+
const formattedText = text.toUpperCase();
|
|
1007
|
+
let data = "";
|
|
1008
|
+
if (formattedText === "STDIO") data = styleText(["magenta"], formattedText);
|
|
1009
|
+
if (formattedText === "SSE") data = styleText(["blue"], formattedText);
|
|
1010
|
+
if (formattedText === "HTTP") data = styleText(["blue"], formattedText);
|
|
1011
|
+
return data;
|
|
1279
1012
|
}
|
|
1280
|
-
__name(render, "render");
|
|
1281
|
-
|
|
1282
1013
|
// src/components/column-name.ts
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
const data = styleText2(["dim"], formattedText);
|
|
1287
|
-
return data;
|
|
1014
|
+
function render$6(text) {
|
|
1015
|
+
const formattedText = String(text).toUpperCase();
|
|
1016
|
+
return styleText(["dim"], formattedText);
|
|
1288
1017
|
}
|
|
1289
|
-
__name(render2, "render");
|
|
1290
|
-
|
|
1291
1018
|
// src/components/mcp-server-status.ts
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
} else {
|
|
1299
|
-
data = styleText3(["red"], "\u25CF");
|
|
1300
|
-
}
|
|
1301
|
-
return data;
|
|
1019
|
+
function render$5(text) {
|
|
1020
|
+
const formattedText = text.toLowerCase();
|
|
1021
|
+
let data;
|
|
1022
|
+
if (formattedText === "running") data = styleText(["green"], "●");
|
|
1023
|
+
else data = styleText(["red"], "●");
|
|
1024
|
+
return data;
|
|
1302
1025
|
}
|
|
1303
|
-
__name(render3, "render");
|
|
1304
|
-
|
|
1305
1026
|
// src/components/mcp-server-name.ts
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
const data = styleText4(["bold", "white"], formattedText);
|
|
1310
|
-
return data;
|
|
1027
|
+
function render$4(text) {
|
|
1028
|
+
const formattedText = text.toLowerCase();
|
|
1029
|
+
return styleText(["bold", "white"], formattedText);
|
|
1311
1030
|
}
|
|
1312
|
-
__name(render4, "render");
|
|
1313
|
-
|
|
1314
1031
|
// src/components/mcp-server-source.ts
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
return styleText5(["gray"], formattedText);
|
|
1032
|
+
function render$3(text) {
|
|
1033
|
+
const formattedText = String(text).trim();
|
|
1034
|
+
return styleText(["gray"], formattedText);
|
|
1319
1035
|
}
|
|
1320
|
-
__name(render5, "render");
|
|
1321
|
-
|
|
1322
1036
|
// src/components/mcp-server-version.ts
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
const displayVersion = version === "latest" ? "LATEST" : version;
|
|
1330
|
-
if (versionInfo.isPinned) {
|
|
1331
|
-
return styleText6(["green"], "\u25CF") + " " + displayVersion;
|
|
1332
|
-
} else {
|
|
1333
|
-
return styleText6(["red"], "\u25CF") + " LATEST";
|
|
1334
|
-
}
|
|
1037
|
+
function render$2(versionInfo) {
|
|
1038
|
+
if (!versionInfo) return "";
|
|
1039
|
+
const version = versionInfo.version || "LATEST";
|
|
1040
|
+
const displayVersion = version === "latest" ? "LATEST" : version;
|
|
1041
|
+
if (versionInfo.isPinned) return styleText(["green"], "●") + " " + displayVersion;
|
|
1042
|
+
else return styleText(["red"], "●") + " LATEST";
|
|
1335
1043
|
}
|
|
1336
|
-
__name(render6, "render");
|
|
1337
|
-
|
|
1338
1044
|
// src/components/file-path.ts
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
const formattedText = text;
|
|
1342
|
-
const data = styleText7(["underline"], formattedText);
|
|
1343
|
-
return data;
|
|
1045
|
+
function render$1(text) {
|
|
1046
|
+
return styleText(["underline"], text);
|
|
1344
1047
|
}
|
|
1345
|
-
__name(render7, "render");
|
|
1346
|
-
|
|
1347
1048
|
// src/components/mcp-servers-config-parsable.ts
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
} else {
|
|
1355
|
-
data = styleText8(["red"], "\u25CF");
|
|
1356
|
-
}
|
|
1357
|
-
return data;
|
|
1049
|
+
function render(text) {
|
|
1050
|
+
const formattedText = text.toUpperCase().replace(/_/g, " ");
|
|
1051
|
+
let data;
|
|
1052
|
+
if (formattedText === "VALID") data = styleText(["green"], "●");
|
|
1053
|
+
else data = styleText(["red"], "●");
|
|
1054
|
+
return data;
|
|
1358
1055
|
}
|
|
1359
|
-
__name(render8, "render");
|
|
1360
|
-
|
|
1361
1056
|
// src/components/credential-warning.ts
|
|
1362
|
-
import { styleText as styleText9 } from "util";
|
|
1363
1057
|
function CredentialWarningComponent(credentials) {
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
const sourceSummaries = Object.entries(credsBySource).map(([source, creds]) => {
|
|
1393
|
-
const sourceIcon = getSourceIcon(source);
|
|
1394
|
-
const credList = creds.map((cv) => `${cv.name}=${cv.value}`).join(", ");
|
|
1395
|
-
return `${sourceIcon}${source}: ${credList}`;
|
|
1396
|
-
});
|
|
1397
|
-
const credentialSummary = sourceSummaries.join(" | ");
|
|
1398
|
-
return `${riskText} ${styleText9(["dim"], `(${credentialVars.length} creds: ${credentialSummary})`)}`;
|
|
1058
|
+
if (!credentials || !credentials.hasCredentials) return "";
|
|
1059
|
+
const { riskLevel, credentialVars } = credentials;
|
|
1060
|
+
let riskColor;
|
|
1061
|
+
let riskIcon;
|
|
1062
|
+
switch (riskLevel) {
|
|
1063
|
+
case "high":
|
|
1064
|
+
riskColor = "red";
|
|
1065
|
+
riskIcon = styleText(["red"], "●");
|
|
1066
|
+
break;
|
|
1067
|
+
case "low":
|
|
1068
|
+
riskColor = "blue";
|
|
1069
|
+
riskIcon = styleText(["blue"], "●");
|
|
1070
|
+
break;
|
|
1071
|
+
default:
|
|
1072
|
+
riskColor = "blue";
|
|
1073
|
+
riskIcon = styleText(["blue"], "●");
|
|
1074
|
+
}
|
|
1075
|
+
const riskText = styleText([riskColor], `${riskIcon} ${riskLevel.toUpperCase()} RISK`);
|
|
1076
|
+
const credsBySource = credentialVars.reduce((acc, cv) => {
|
|
1077
|
+
const source = cv.source || "env";
|
|
1078
|
+
if (!acc[source]) acc[source] = [];
|
|
1079
|
+
acc[source].push(cv);
|
|
1080
|
+
return acc;
|
|
1081
|
+
}, {});
|
|
1082
|
+
const credentialSummary = Object.entries(credsBySource).map(([source, creds]) => {
|
|
1083
|
+
return `${getSourceIcon(source)}${source}: ${creds.map((cv) => `${cv.name}=${cv.value}`).join(", ")}`;
|
|
1084
|
+
}).join(" | ");
|
|
1085
|
+
return `${riskText} ${styleText(["dim"], `(${credentialVars.length} creds: ${credentialSummary})`)}`;
|
|
1399
1086
|
}
|
|
1400
|
-
|
|
1087
|
+
/**
|
|
1088
|
+
* Get an icon/symbol for different credential sources
|
|
1089
|
+
*/
|
|
1401
1090
|
function getSourceIcon(source) {
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
// Command argument
|
|
1409
|
-
case "headers":
|
|
1410
|
-
return "\u{1F517} ";
|
|
1411
|
-
// HTTP header
|
|
1412
|
-
default:
|
|
1413
|
-
return "\u{1F4CB} ";
|
|
1414
|
-
}
|
|
1091
|
+
switch (source) {
|
|
1092
|
+
case "env": return "🌱 ";
|
|
1093
|
+
case "args": return "⚡ ";
|
|
1094
|
+
case "headers": return "🔗 ";
|
|
1095
|
+
default: return "📋 ";
|
|
1096
|
+
}
|
|
1415
1097
|
}
|
|
1416
|
-
__name(getSourceIcon, "getSourceIcon");
|
|
1417
|
-
|
|
1418
1098
|
// src/components/summary.ts
|
|
1419
|
-
import { styleText as styleText10 } from "util";
|
|
1420
1099
|
function SummaryComponent(stats) {
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
return lines.join("\n");
|
|
1100
|
+
const { totalServers, runningServers, highRiskCredentials, implicitLatestVersions, transportBreakdown } = stats;
|
|
1101
|
+
const runningBar = createProgressBar(runningServers, totalServers, 20, "green", false);
|
|
1102
|
+
const securityBar = createProgressBar(highRiskCredentials, totalServers, 20, "red", true);
|
|
1103
|
+
const versionBar = createProgressBar(implicitLatestVersions, totalServers, 20, "red", true);
|
|
1104
|
+
const transportText = `stdio: ${transportBreakdown.stdio} | SSE: ${transportBreakdown.sse} | HTTP: ${transportBreakdown.http}`;
|
|
1105
|
+
return [
|
|
1106
|
+
"SUMMARY",
|
|
1107
|
+
` SERVERS ${runningBar} ${runningServers} / ${totalServers} Running`,
|
|
1108
|
+
` SECURITY ${securityBar} ${highRiskCredentials} / ${totalServers} High Risk Credentials`,
|
|
1109
|
+
` VERSION ${versionBar} ${implicitLatestVersions} / ${totalServers} Implicit Latest`,
|
|
1110
|
+
` TRANSPORT ${transportText}`
|
|
1111
|
+
].join("\n");
|
|
1434
1112
|
}
|
|
1435
|
-
__name(SummaryComponent, "SummaryComponent");
|
|
1436
1113
|
function createProgressBar(count, total, width, color, emptyIsGood = false) {
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
empty = styleText10(["green"], "\u2591".repeat(emptyWidth));
|
|
1453
|
-
} else {
|
|
1454
|
-
empty = styleText10(["red"], "\u2591".repeat(emptyWidth));
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1457
|
-
return `${filled}${empty}`;
|
|
1114
|
+
if (total === 0) return "░".repeat(width);
|
|
1115
|
+
const progress = Math.min(count / total, 1);
|
|
1116
|
+
const filledWidth = Math.round(progress * width);
|
|
1117
|
+
const emptyWidth = width - filledWidth;
|
|
1118
|
+
let filled;
|
|
1119
|
+
let empty;
|
|
1120
|
+
if (color === "green") {
|
|
1121
|
+
filled = styleText(["greenBright"], "█".repeat(filledWidth));
|
|
1122
|
+
empty = styleText(["green"], "░".repeat(emptyWidth));
|
|
1123
|
+
} else {
|
|
1124
|
+
filled = styleText(["redBright"], "█".repeat(filledWidth));
|
|
1125
|
+
if (count === 0 && emptyIsGood) empty = styleText(["green"], "░".repeat(emptyWidth));
|
|
1126
|
+
else empty = styleText(["red"], "░".repeat(emptyWidth));
|
|
1127
|
+
}
|
|
1128
|
+
return `${filled}${empty}`;
|
|
1458
1129
|
}
|
|
1459
|
-
__name(createProgressBar, "createProgressBar");
|
|
1460
|
-
|
|
1461
1130
|
// src/services/render-service.ts
|
|
1462
|
-
var RenderService = class
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
const leftPadding = index === 0 ? leftPaddingGroupLead : leftPaddingGroupData;
|
|
1605
|
-
console.log(leftPadding + dataRow);
|
|
1606
|
-
}
|
|
1607
|
-
}
|
|
1608
|
-
// draws progress bar components like this
|
|
1609
|
-
// "███████░░░░░░░░░░░░░ 3 / 9 Running"
|
|
1610
|
-
static renderProgressBar(count, total, label, width = 20) {
|
|
1611
|
-
if (total === 0) {
|
|
1612
|
-
const emptyBar = "\u2591".repeat(width);
|
|
1613
|
-
return `${emptyBar} 0 / 0 ${label}`;
|
|
1614
|
-
}
|
|
1615
|
-
const progress = Math.min(count / total, 1);
|
|
1616
|
-
const filledWidth = Math.round(progress * width);
|
|
1617
|
-
const emptyWidth = width - filledWidth;
|
|
1618
|
-
let filled;
|
|
1619
|
-
let empty;
|
|
1620
|
-
if (count > 0) {
|
|
1621
|
-
filled = styleText11(["greenBright"], "\u2588".repeat(filledWidth));
|
|
1622
|
-
empty = styleText11(["green"], "\u2591".repeat(emptyWidth));
|
|
1623
|
-
} else {
|
|
1624
|
-
filled = "\u2588".repeat(filledWidth);
|
|
1625
|
-
empty = "\u2591".repeat(emptyWidth);
|
|
1626
|
-
}
|
|
1627
|
-
return `${filled}${empty} ${count} / ${total} ${label}`;
|
|
1628
|
-
}
|
|
1629
|
-
/**
|
|
1630
|
-
* Print summary statistics at the end of the output
|
|
1631
|
-
*/
|
|
1632
|
-
static printSummary(stats) {
|
|
1633
|
-
console.log("\n");
|
|
1634
|
-
console.log(" \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");
|
|
1635
|
-
console.log();
|
|
1636
|
-
const summaryOutput = SummaryComponent(stats);
|
|
1637
|
-
const lines = summaryOutput.split("\n");
|
|
1638
|
-
for (const line of lines) {
|
|
1639
|
-
if (line === "SUMMARY") {
|
|
1640
|
-
console.log(" " + line);
|
|
1641
|
-
} else {
|
|
1642
|
-
console.log(" " + line);
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
console.log();
|
|
1646
|
-
console.log(" \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");
|
|
1647
|
-
}
|
|
1131
|
+
var RenderService = class RenderService {
|
|
1132
|
+
static getVisibleLength(text) {
|
|
1133
|
+
return text.replace(/\u001b\[[0-9;]*m/g, "").length;
|
|
1134
|
+
}
|
|
1135
|
+
static printMcpServers(data) {
|
|
1136
|
+
if (data.length === 0) return;
|
|
1137
|
+
const headers = [
|
|
1138
|
+
"STATUS",
|
|
1139
|
+
"NAME",
|
|
1140
|
+
"VERSION",
|
|
1141
|
+
"SOURCE",
|
|
1142
|
+
"TRANSPORT",
|
|
1143
|
+
"CREDENTIALS"
|
|
1144
|
+
];
|
|
1145
|
+
const keys = [
|
|
1146
|
+
"status",
|
|
1147
|
+
"name",
|
|
1148
|
+
"versionInfo",
|
|
1149
|
+
"source",
|
|
1150
|
+
"transport",
|
|
1151
|
+
"credentials"
|
|
1152
|
+
];
|
|
1153
|
+
const centerColumns = [
|
|
1154
|
+
0,
|
|
1155
|
+
3,
|
|
1156
|
+
4
|
|
1157
|
+
];
|
|
1158
|
+
const leftPadding = " ";
|
|
1159
|
+
const columnWidths = headers.map((header, index) => {
|
|
1160
|
+
const headerWidth = RenderService.getVisibleLength(render$6(header));
|
|
1161
|
+
const dataWidth = Math.max(...data.map((row) => {
|
|
1162
|
+
let text = String(row[keys[index]]);
|
|
1163
|
+
if (keys[index] === "transport") text = render$7(text);
|
|
1164
|
+
if (keys[index] === "status") text = render$5(text);
|
|
1165
|
+
if (keys[index] === "source") text = render$3(text);
|
|
1166
|
+
if (keys[index] === "name") text = render$4(text);
|
|
1167
|
+
if (keys[index] === "versionInfo") text = render$2(row.versionInfo);
|
|
1168
|
+
if (keys[index] === "credentials") text = CredentialWarningComponent(row.credentials);
|
|
1169
|
+
return RenderService.getVisibleLength(text);
|
|
1170
|
+
}));
|
|
1171
|
+
return Math.max(headerWidth, dataWidth);
|
|
1172
|
+
});
|
|
1173
|
+
const centerText = (text, width) => {
|
|
1174
|
+
const padding = width - RenderService.getVisibleLength(text);
|
|
1175
|
+
const leftPad = Math.floor(padding / 2);
|
|
1176
|
+
const rightPad = padding - leftPad;
|
|
1177
|
+
return " ".repeat(leftPad) + text + " ".repeat(rightPad);
|
|
1178
|
+
};
|
|
1179
|
+
const padRight = (text, width) => {
|
|
1180
|
+
const visibleLength = RenderService.getVisibleLength(text);
|
|
1181
|
+
const padding = Math.max(0, width - visibleLength);
|
|
1182
|
+
return text + " ".repeat(padding);
|
|
1183
|
+
};
|
|
1184
|
+
const totalWidth = columnWidths.reduce((sum, width) => sum + width, 0) + (columnWidths.length - 1) * 2;
|
|
1185
|
+
const separator = "─".repeat(totalWidth);
|
|
1186
|
+
console.log("\n " + separator);
|
|
1187
|
+
const headerRow = headers.map((header, index) => {
|
|
1188
|
+
const headerText = render$6(header);
|
|
1189
|
+
if (centerColumns.includes(index)) return centerText(headerText, columnWidths[index]);
|
|
1190
|
+
return padRight(headerText, columnWidths[index]);
|
|
1191
|
+
}).join(" ");
|
|
1192
|
+
console.log(leftPadding + headerRow);
|
|
1193
|
+
console.log(leftPadding + separator);
|
|
1194
|
+
for (const row of data) {
|
|
1195
|
+
const dataRow = keys.map((key, index) => {
|
|
1196
|
+
let text = String(row[key]);
|
|
1197
|
+
if (key === "transport") text = render$7(text);
|
|
1198
|
+
if (key === "status") text = render$5(text);
|
|
1199
|
+
if (keys[index] === "source") text = render$3(text);
|
|
1200
|
+
if (key === "name") text = render$4(text);
|
|
1201
|
+
if (key === "versionInfo") text = render$2(row.versionInfo);
|
|
1202
|
+
if (key === "credentials") text = CredentialWarningComponent(row.credentials);
|
|
1203
|
+
if (centerColumns.includes(index)) return centerText(text, columnWidths[index]);
|
|
1204
|
+
return padRight(text, columnWidths[index]);
|
|
1205
|
+
}).join(" ");
|
|
1206
|
+
console.log(leftPadding + dataRow);
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
static printMcpGroup(id, data, groupMetadata = {}) {
|
|
1210
|
+
if (data.length === 0) return;
|
|
1211
|
+
console.log("\n");
|
|
1212
|
+
const headers = ["KEY", "VALUE"];
|
|
1213
|
+
const keys = ["key", "value"];
|
|
1214
|
+
const indexText = `[${id}]`;
|
|
1215
|
+
const leftPaddingGroupLead = indexText + " ".repeat(6 - indexText.length);
|
|
1216
|
+
const leftPaddingGroupData = " ".repeat(6);
|
|
1217
|
+
if (Object.keys(groupMetadata).length > 0) {
|
|
1218
|
+
const runningCount = groupMetadata.mcpServersRunning || 0;
|
|
1219
|
+
const totalCount = groupMetadata.mcpServersTotal || 0;
|
|
1220
|
+
const metadataRow = RenderService.renderProgressBar(runningCount, totalCount, "Running");
|
|
1221
|
+
data.push({
|
|
1222
|
+
key: "MCP SERVERS",
|
|
1223
|
+
value: metadataRow
|
|
1224
|
+
});
|
|
1225
|
+
}
|
|
1226
|
+
const columnWidths = headers.map((header, index) => {
|
|
1227
|
+
const dataWidth = Math.max(...data.map((row) => {
|
|
1228
|
+
const columnText = render$6(row[keys[index]]);
|
|
1229
|
+
return RenderService.getVisibleLength(columnText);
|
|
1230
|
+
}));
|
|
1231
|
+
return Math.max(header.length, dataWidth);
|
|
1232
|
+
});
|
|
1233
|
+
for (const [index, row] of data.entries()) {
|
|
1234
|
+
const dataRow = keys.map((key, index) => {
|
|
1235
|
+
const paddingNormalizer = render$6(row[key]).length - row[key].length;
|
|
1236
|
+
if (key === "key") return render$6(row[key]).padEnd(columnWidths[index] + paddingNormalizer);
|
|
1237
|
+
if (row["key"] === "FILE") return render$1(row[key]).padEnd(columnWidths[index] + paddingNormalizer);
|
|
1238
|
+
if (row["key"] === "PARSABLE") return render(row[key]).padEnd(columnWidths[index] + paddingNormalizer);
|
|
1239
|
+
return String(row[key]).padEnd(columnWidths[index] + paddingNormalizer);
|
|
1240
|
+
}).join(" ");
|
|
1241
|
+
console.log((index === 0 ? leftPaddingGroupLead : leftPaddingGroupData) + dataRow);
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
static renderProgressBar(count, total, label, width = 20) {
|
|
1245
|
+
if (total === 0) return `${"░".repeat(width)} 0 / 0 ${label}`;
|
|
1246
|
+
const progress = Math.min(count / total, 1);
|
|
1247
|
+
const filledWidth = Math.round(progress * width);
|
|
1248
|
+
const emptyWidth = width - filledWidth;
|
|
1249
|
+
let filled;
|
|
1250
|
+
let empty;
|
|
1251
|
+
if (count > 0) {
|
|
1252
|
+
filled = styleText(["greenBright"], "█".repeat(filledWidth));
|
|
1253
|
+
empty = styleText(["green"], "░".repeat(emptyWidth));
|
|
1254
|
+
} else {
|
|
1255
|
+
filled = "█".repeat(filledWidth);
|
|
1256
|
+
empty = "░".repeat(emptyWidth);
|
|
1257
|
+
}
|
|
1258
|
+
return `${filled}${empty} ${count} / ${total} ${label}`;
|
|
1259
|
+
}
|
|
1260
|
+
/**
|
|
1261
|
+
* Print summary statistics at the end of the output
|
|
1262
|
+
*/
|
|
1263
|
+
static printSummary(stats) {
|
|
1264
|
+
console.log("\n");
|
|
1265
|
+
console.log(" ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄");
|
|
1266
|
+
console.log();
|
|
1267
|
+
const lines = SummaryComponent(stats).split("\n");
|
|
1268
|
+
for (const line of lines) if (line === "SUMMARY") console.log(" " + line);
|
|
1269
|
+
else console.log(" " + line);
|
|
1270
|
+
console.log();
|
|
1271
|
+
console.log(" ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄");
|
|
1272
|
+
}
|
|
1648
1273
|
};
|
|
1649
|
-
|
|
1650
1274
|
// src/bin/cli.ts
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1275
|
+
const args = process.argv.slice(2);
|
|
1276
|
+
const jsonOutput = args.includes("--json");
|
|
1277
|
+
const showAll = args.includes("--all") || args.includes("-a");
|
|
1278
|
+
let customFiles;
|
|
1279
|
+
const filesIndex = args.findIndex((arg) => arg === "--files");
|
|
1656
1280
|
if (filesIndex !== -1 && filesIndex < args.length - 1) {
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
}
|
|
1664
|
-
customFiles = fileArgs.flatMap(
|
|
1665
|
-
(arg) => arg.includes(",") ? arg.split(",").map((f) => f.trim()) : [arg.trim()]
|
|
1666
|
-
).filter((f) => f.length > 0);
|
|
1281
|
+
const fileArgs = [];
|
|
1282
|
+
for (let i = filesIndex + 1; i < args.length; i++) {
|
|
1283
|
+
if (args[i].startsWith("--")) break;
|
|
1284
|
+
fileArgs.push(args[i]);
|
|
1285
|
+
}
|
|
1286
|
+
customFiles = fileArgs.flatMap((arg) => arg.includes(",") ? arg.split(",").map((f) => f.trim()) : [arg.trim()]).filter((f) => f.length > 0);
|
|
1667
1287
|
}
|
|
1668
1288
|
async function init() {
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
const [, group] = entry;
|
|
1770
|
-
return group.paths.length > 0;
|
|
1771
|
-
})
|
|
1772
|
-
);
|
|
1773
|
-
const output = {
|
|
1774
|
-
mcpFiles: filteredMcpFiles,
|
|
1775
|
-
summary: summaryStats
|
|
1776
|
-
};
|
|
1777
|
-
console.log(JSON.stringify(output, null, 2));
|
|
1778
|
-
} else {
|
|
1779
|
-
RenderService.printSummary(summaryStats);
|
|
1780
|
-
}
|
|
1289
|
+
if (!jsonOutput) {
|
|
1290
|
+
console.log();
|
|
1291
|
+
if (customFiles && customFiles.length > 0) console.log("[+] Analyzing specified MCP configuration files...");
|
|
1292
|
+
else console.log("[+] Detecting MCP Server configurations...");
|
|
1293
|
+
}
|
|
1294
|
+
const mcpFilesList = await new MCPFiles(customFiles).findFiles();
|
|
1295
|
+
if (Object.keys(mcpFilesList).length === 0) exitWithError("No configuration for MCP Server applications found.");
|
|
1296
|
+
let pathIndex = 0;
|
|
1297
|
+
let totalServers = 0;
|
|
1298
|
+
let totalRunning = 0;
|
|
1299
|
+
let totalHighRiskCredentials = 0;
|
|
1300
|
+
let totalImplicitLatestVersions = 0;
|
|
1301
|
+
const transportCounts = {
|
|
1302
|
+
stdio: 0,
|
|
1303
|
+
sse: 0,
|
|
1304
|
+
http: 0
|
|
1305
|
+
};
|
|
1306
|
+
for (const groupName of Object.keys(mcpFilesList)) {
|
|
1307
|
+
const group = mcpFilesList[groupName];
|
|
1308
|
+
const isCustomFilesMode = customFiles && customFiles.length > 0;
|
|
1309
|
+
if (!showAll && !isCustomFilesMode && group.stats?.serversCount === 0) continue;
|
|
1310
|
+
if (group.paths.length > 0) for (const filePathData of group.paths) {
|
|
1311
|
+
const totalMCPServers = filePathData.servers ? filePathData.servers.length : 0;
|
|
1312
|
+
if (!showAll && !isCustomFilesMode && totalMCPServers === 0) continue;
|
|
1313
|
+
pathIndex++;
|
|
1314
|
+
const filePath = filePathData.filePath.replace("~", process.env.HOME || "");
|
|
1315
|
+
const filePathValid = filePathData.parsable ? "VALID" : "INVALID";
|
|
1316
|
+
const filePathDataType = filePathData.type.toUpperCase();
|
|
1317
|
+
const mcpServers = filePathData.servers || [];
|
|
1318
|
+
const totalMCPServersRunning = mcpServers.filter((server) => server.status === "running").length;
|
|
1319
|
+
totalServers += totalMCPServers;
|
|
1320
|
+
totalRunning += totalMCPServersRunning;
|
|
1321
|
+
for (const server of mcpServers) {
|
|
1322
|
+
if (server.transport) {
|
|
1323
|
+
const transport = server.transport.toLowerCase();
|
|
1324
|
+
if (transport in transportCounts) transportCounts[transport]++;
|
|
1325
|
+
}
|
|
1326
|
+
if (server.credentials?.hasCredentials && server.credentials?.riskLevel === "high") totalHighRiskCredentials++;
|
|
1327
|
+
if (server.versionInfo?.isLatest) totalImplicitLatestVersions++;
|
|
1328
|
+
}
|
|
1329
|
+
if (!jsonOutput) {
|
|
1330
|
+
const mcpGroupData = [
|
|
1331
|
+
{
|
|
1332
|
+
key: "PROVIDER",
|
|
1333
|
+
value: group.friendlyName
|
|
1334
|
+
},
|
|
1335
|
+
{
|
|
1336
|
+
key: "FILE",
|
|
1337
|
+
value: filePath
|
|
1338
|
+
},
|
|
1339
|
+
{
|
|
1340
|
+
key: "TYPE",
|
|
1341
|
+
value: filePathDataType
|
|
1342
|
+
},
|
|
1343
|
+
{
|
|
1344
|
+
key: "PARSABLE",
|
|
1345
|
+
value: filePathValid
|
|
1346
|
+
}
|
|
1347
|
+
];
|
|
1348
|
+
const groupMetadata = {
|
|
1349
|
+
mcpServersTotal: totalMCPServers,
|
|
1350
|
+
mcpServersRunning: totalMCPServersRunning
|
|
1351
|
+
};
|
|
1352
|
+
RenderService.printMcpGroup(pathIndex, mcpGroupData, groupMetadata);
|
|
1353
|
+
RenderService.printMcpServers(mcpServers);
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
if (pathIndex === 0) {
|
|
1358
|
+
if (customFiles && customFiles.length > 0) exitWithError("No MCP servers found in specified configuration files.");
|
|
1359
|
+
else exitWithError("No MCP servers found in known configuration files.");
|
|
1360
|
+
}
|
|
1361
|
+
const summaryStats = {
|
|
1362
|
+
totalServers,
|
|
1363
|
+
runningServers: totalRunning,
|
|
1364
|
+
highRiskCredentials: totalHighRiskCredentials,
|
|
1365
|
+
implicitLatestVersions: totalImplicitLatestVersions,
|
|
1366
|
+
transportBreakdown: transportCounts
|
|
1367
|
+
};
|
|
1368
|
+
if (jsonOutput) {
|
|
1369
|
+
const isCustomFilesMode = customFiles && customFiles.length > 0;
|
|
1370
|
+
const output = {
|
|
1371
|
+
mcpFiles: Object.fromEntries(Object.entries(mcpFilesList).map(([groupName, group]) => {
|
|
1372
|
+
const filteredPaths = group.paths.filter((filePathData) => {
|
|
1373
|
+
const fileServerCount = filePathData.servers ? filePathData.servers.length : 0;
|
|
1374
|
+
if (showAll || isCustomFilesMode) return true;
|
|
1375
|
+
return fileServerCount > 0;
|
|
1376
|
+
});
|
|
1377
|
+
return [groupName, {
|
|
1378
|
+
...group,
|
|
1379
|
+
paths: filteredPaths
|
|
1380
|
+
}];
|
|
1381
|
+
}).filter((entry) => {
|
|
1382
|
+
const [, group] = entry;
|
|
1383
|
+
return group.paths.length > 0;
|
|
1384
|
+
})),
|
|
1385
|
+
summary: summaryStats
|
|
1386
|
+
};
|
|
1387
|
+
console.log(JSON.stringify(output, null, 2));
|
|
1388
|
+
} else RenderService.printSummary(summaryStats);
|
|
1781
1389
|
}
|
|
1782
|
-
__name(init, "init");
|
|
1783
1390
|
init().then(() => {
|
|
1784
|
-
|
|
1391
|
+
console.log("\n");
|
|
1785
1392
|
});
|
|
1786
1393
|
function exitWithError(message) {
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
process.exit(1);
|
|
1394
|
+
console.error(`${styleText(["red"], "●")} ${message}\n`);
|
|
1395
|
+
process.exit(1);
|
|
1790
1396
|
}
|
|
1791
|
-
|
|
1397
|
+
export {};
|