ls-mcp 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/cli.cjs +337 -24
- package/dist/bin/cli.d.cts +1 -2
- package/dist/bin/cli.d.ts +1 -2
- package/dist/bin/cli.mjs +337 -24
- package/dist/main.cjs +294 -5
- package/dist/main.mjs +294 -5
- package/package.json +5 -3
- package/src/bin/cli.ts +7 -4
- package/src/components/mcp-server-status.ts +1 -1
- package/src/components/mcp-servers-config-parsable.ts +2 -2
- package/src/main.ts +11 -3
- package/src/services/mcp-server-manager-service.ts +414 -3
- package/src/services/render-service.ts +44 -19
package/src/bin/cli.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
1
3
|
// import { debuglog } from 'node:util'
|
|
2
4
|
import { MCPFiles } from '../main.ts'
|
|
3
5
|
import { RenderService } from '../services/render-service.ts'
|
|
@@ -26,14 +28,15 @@ async function init () {
|
|
|
26
28
|
return
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
let
|
|
31
|
+
let pathIndex = 0
|
|
30
32
|
for (const groupName of Object.keys(mcpFilesList)) {
|
|
31
|
-
groupIndex++
|
|
32
33
|
const group = mcpFilesList[groupName]
|
|
33
34
|
|
|
34
35
|
if (group.paths.length >= 0) {
|
|
35
36
|
// handle file path list of MCP Servers
|
|
36
37
|
for (const filePathData of group.paths) {
|
|
38
|
+
pathIndex++
|
|
39
|
+
|
|
37
40
|
const filePath = filePathData.filePath.replace('~', process.env.HOME || '')
|
|
38
41
|
const filePathValid = filePathData.parsable ? 'VALID' : 'INVALID'
|
|
39
42
|
const filePathDataType = filePathData.type.toUpperCase()
|
|
@@ -45,8 +48,8 @@ async function init () {
|
|
|
45
48
|
const mcpGroupData = [
|
|
46
49
|
{ key: 'PROVIDER', value: group.friendlyName },
|
|
47
50
|
{ key: 'FILE', value: filePath },
|
|
48
|
-
{ key: 'PARSABLE', value: filePathValid },
|
|
49
51
|
{ key: 'TYPE', value: filePathDataType },
|
|
52
|
+
{ key: 'PARSABLE', value: filePathValid },
|
|
50
53
|
]
|
|
51
54
|
|
|
52
55
|
const groupMetadata = {
|
|
@@ -54,7 +57,7 @@ async function init () {
|
|
|
54
57
|
mcpServersRunning: totalMCPServersRunning,
|
|
55
58
|
}
|
|
56
59
|
|
|
57
|
-
RenderService.printMcpGroup(
|
|
60
|
+
RenderService.printMcpGroup(pathIndex, mcpGroupData, groupMetadata)
|
|
58
61
|
RenderService.printMcpServers(mcpServers)
|
|
59
62
|
}
|
|
60
63
|
} else {
|
|
@@ -4,9 +4,9 @@ export default function render (text: string) {
|
|
|
4
4
|
const formattedText = text.toUpperCase().replace(/_/g, ' ')
|
|
5
5
|
let data = formattedText
|
|
6
6
|
if (formattedText === 'VALID') {
|
|
7
|
-
data = styleText(['green'],
|
|
7
|
+
data = styleText(['green'], '●')
|
|
8
8
|
} else {
|
|
9
|
-
data = styleText(['red'],
|
|
9
|
+
data = styleText(['red'], '●')
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
return data
|
package/src/main.ts
CHANGED
|
@@ -42,7 +42,7 @@ type MCPFileGroupsResultRecord = Record<string, MCPFileGroupsResult>
|
|
|
42
42
|
export class MCPFiles {
|
|
43
43
|
private mcpFilePathGroups: MCPFilePathGroupsRecord = {
|
|
44
44
|
claude: {
|
|
45
|
-
name: 'claude',
|
|
45
|
+
name: 'claude-desktop',
|
|
46
46
|
friendlyName: 'Claude Desktop',
|
|
47
47
|
paths: [
|
|
48
48
|
{ filePath: '~/Library/Application Support/Claude/claude_desktop_config.json', type: 'global' },
|
|
@@ -52,8 +52,8 @@ export class MCPFiles {
|
|
|
52
52
|
name: 'cursor',
|
|
53
53
|
friendlyName: 'Cursor',
|
|
54
54
|
paths: [
|
|
55
|
-
{ filePath: '.cursor/mcp.json', type: 'local' },
|
|
56
55
|
{ filePath: '~/.cursor/mcp.json', type: 'global' },
|
|
56
|
+
{ filePath: '.cursor/mcp.json', type: 'local' },
|
|
57
57
|
]
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -97,13 +97,21 @@ export class MCPFiles {
|
|
|
97
97
|
}
|
|
98
98
|
const MCPServerManager = new MCPServerManagerService(serverConfig)
|
|
99
99
|
|
|
100
|
+
const mcpServerProcessDetection = MCPServerManager.isRunning()
|
|
101
|
+
let mcpServerProcess = false
|
|
102
|
+
if (mcpServerProcessDetection) {
|
|
103
|
+
if (typeof mcpServerProcessDetection === 'object' && mcpServerProcessDetection.estimatedProduct === clientsGroup.name) {
|
|
104
|
+
mcpServerProcess = true
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
100
108
|
mcpServersData.push({
|
|
101
109
|
name: MCPServerManager.getName(),
|
|
102
110
|
command: MCPServerManager.getCmd(),
|
|
103
111
|
args: MCPServerManager.getArgs(),
|
|
104
112
|
transport: MCPServerManager.getTransport(),
|
|
105
113
|
env: MCPServerManager.getEnv(),
|
|
106
|
-
status:
|
|
114
|
+
status: mcpServerProcess ? 'running' : 'stopped'
|
|
107
115
|
})
|
|
108
116
|
}
|
|
109
117
|
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { execSync } from 'node:child_process'
|
|
2
|
+
import { platform } from 'node:os'
|
|
3
|
+
|
|
1
4
|
interface MCPServerConfig {
|
|
2
5
|
name: string
|
|
3
6
|
command: string
|
|
@@ -6,13 +9,21 @@ interface MCPServerConfig {
|
|
|
6
9
|
env?: Record<string, string>
|
|
7
10
|
}
|
|
8
11
|
|
|
12
|
+
interface MatchedProcess {
|
|
13
|
+
pid: string
|
|
14
|
+
commandLine: string
|
|
15
|
+
ppid?: string
|
|
16
|
+
parentCommandLine?: string
|
|
17
|
+
estimatedVendor?: string
|
|
18
|
+
estimatedProduct?: string
|
|
19
|
+
}
|
|
20
|
+
|
|
9
21
|
export class MCPServerManagerService {
|
|
10
22
|
private name: string
|
|
11
23
|
private command: string
|
|
12
24
|
private args: string[]
|
|
13
25
|
private transport?: 'stdio' | 'sse'
|
|
14
26
|
private env?: Record<string, string>
|
|
15
|
-
|
|
16
27
|
private running: boolean = false
|
|
17
28
|
|
|
18
29
|
constructor (serverConfig: MCPServerConfig) {
|
|
@@ -43,7 +54,407 @@ export class MCPServerManagerService {
|
|
|
43
54
|
return this.env
|
|
44
55
|
}
|
|
45
56
|
|
|
46
|
-
isRunning (): boolean {
|
|
47
|
-
|
|
57
|
+
isRunning (): boolean | MatchedProcess {
|
|
58
|
+
try {
|
|
59
|
+
let psOutput: string
|
|
60
|
+
|
|
61
|
+
if (platform() === 'win32') {
|
|
62
|
+
// Windows: Use wmic to get process info
|
|
63
|
+
psOutput = execSync('wmic process get ProcessId,ParentProcessId,CommandLine /format:csv', {
|
|
64
|
+
encoding: 'utf8',
|
|
65
|
+
timeout: 5000
|
|
66
|
+
})
|
|
67
|
+
} else {
|
|
68
|
+
// Unix/Linux/macOS: Use ps command with pid, ppid, and args
|
|
69
|
+
psOutput = execSync('ps -eao pid,ppid,args', {
|
|
70
|
+
encoding: 'utf8',
|
|
71
|
+
timeout: 5000
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const processMap = new Map<string, { ppid: string, commandTokens: string[] }>()
|
|
76
|
+
const processes = psOutput.trim().split('\n')
|
|
77
|
+
|
|
78
|
+
for (const processLine of processes) {
|
|
79
|
+
if (!processLine.trim()) continue
|
|
80
|
+
|
|
81
|
+
let pid: string
|
|
82
|
+
let ppid: string
|
|
83
|
+
let commandLine: string
|
|
84
|
+
|
|
85
|
+
if (platform() === 'win32') {
|
|
86
|
+
// Parse Windows CSV format: Node,CommandLine,ParentProcessId,ProcessId
|
|
87
|
+
const parts = processLine.split(',')
|
|
88
|
+
if (parts.length < 4) continue
|
|
89
|
+
commandLine = parts[1] || ''
|
|
90
|
+
ppid = parts[2] || ''
|
|
91
|
+
pid = parts[3] || ''
|
|
92
|
+
} else {
|
|
93
|
+
// Parse Unix ps output: PID PPID COMMAND
|
|
94
|
+
const match = processLine.trim().match(/^\s*(\d+)\s+(\d+)\s+(.+)$/)
|
|
95
|
+
if (!match) continue
|
|
96
|
+
pid = match[1]
|
|
97
|
+
ppid = match[2]
|
|
98
|
+
commandLine = match[3]
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Parse command line and store in map
|
|
102
|
+
const commandTokens = this.parseCommandLine(commandLine)
|
|
103
|
+
if (commandTokens.length > 0) {
|
|
104
|
+
processMap.set(pid, { ppid, commandTokens })
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Then iterate the map to check for matches
|
|
109
|
+
let mcpServerDetection: MatchedProcess | undefined
|
|
110
|
+
for (const [pid, processData] of processMap) {
|
|
111
|
+
if (this.isCommandMatch(processData.commandTokens, pid, processData.ppid)) {
|
|
112
|
+
mcpServerDetection = {
|
|
113
|
+
pid,
|
|
114
|
+
commandLine: processData.commandTokens.join(' '),
|
|
115
|
+
ppid: processData.ppid,
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// if we matched the command let's extract the parent command information
|
|
119
|
+
const parentProcess = processMap.get(processData.ppid)
|
|
120
|
+
if (parentProcess) {
|
|
121
|
+
const { estimatedVendor, estimatedProduct } = this.getVendorFromCommand(parentProcess.commandTokens) || {}
|
|
122
|
+
|
|
123
|
+
if (estimatedProduct || estimatedVendor) {
|
|
124
|
+
mcpServerDetection = {
|
|
125
|
+
...mcpServerDetection,
|
|
126
|
+
parentCommandLine: parentProcess.commandTokens.join(' '),
|
|
127
|
+
estimatedVendor,
|
|
128
|
+
estimatedProduct
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return mcpServerDetection
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (mcpServerDetection) {
|
|
138
|
+
return mcpServerDetection
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return false
|
|
142
|
+
} catch (error) {
|
|
143
|
+
return false
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private getVendorFromCommand (commandTokens: string[]): { estimatedVendor: string, estimatedProduct: string } | undefined {
|
|
148
|
+
// match based on known vendor patterns in the command string
|
|
149
|
+
const commandString = commandTokens.join(' ').toLowerCase()
|
|
150
|
+
if (commandString.includes('claude.app')) {
|
|
151
|
+
return {
|
|
152
|
+
estimatedVendor: 'anthropic',
|
|
153
|
+
estimatedProduct: 'claude-desktop'
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (commandString.includes('claude')) {
|
|
158
|
+
return {
|
|
159
|
+
estimatedVendor: 'anthropic',
|
|
160
|
+
estimatedProduct: 'claude-desktop'
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
private isCommandMatch (commandTokens: string[], pid: string, ppid: string): boolean {
|
|
166
|
+
// If no command tokens, cannot match
|
|
167
|
+
if (commandTokens.length === 0) return false
|
|
168
|
+
|
|
169
|
+
// Extracts the base command from the full command path of the process output list
|
|
170
|
+
// e.g. "/usr/homebrew/bin/uv" extracted to "uv"
|
|
171
|
+
const baseCommand = this.getBaseCommand(commandTokens[0])
|
|
172
|
+
|
|
173
|
+
// Map configured command to actual process command for uvx case
|
|
174
|
+
if (this.command === 'uvx' && baseCommand === 'uv') {
|
|
175
|
+
return this.matchUvxProcess(commandTokens)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Map configured command to actual process command for npx case
|
|
179
|
+
if (this.command === 'npx' && baseCommand === 'npm') {
|
|
180
|
+
return this.matchNpxProcess(commandTokens)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/*
|
|
184
|
+
example config:
|
|
185
|
+
"test_server_2": {
|
|
186
|
+
"command": "uv",
|
|
187
|
+
"args": [
|
|
188
|
+
"--directory",
|
|
189
|
+
"/Users/lirantal/projects/repos/example-python-mcp-server",
|
|
190
|
+
"run",
|
|
191
|
+
"test-server.py"
|
|
192
|
+
]
|
|
193
|
+
},
|
|
194
|
+
*/
|
|
195
|
+
if (this.command === 'uv' && baseCommand === 'uv') {
|
|
196
|
+
return this.matchGenericArgsToArgs(commandTokens)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Python Generic commands matching
|
|
200
|
+
/*
|
|
201
|
+
example config:
|
|
202
|
+
"test_server": {
|
|
203
|
+
"command": "/Users/lirantal/projects/repos/example-python-mcp-server/.venv/bin/python",
|
|
204
|
+
"args": [
|
|
205
|
+
"/Users/lirantal/projects/repos/example-python-mcp-server/test-server.py"
|
|
206
|
+
]
|
|
207
|
+
}
|
|
208
|
+
*/
|
|
209
|
+
const commandConfigPythonBase: string = this.getBaseCommand(this.command)
|
|
210
|
+
const commandAliasesPython = ['python3', 'python', 'python3.10', 'python3.11', 'python3.12', 'cpython3', 'cpython', 'python3', 'python2']
|
|
211
|
+
if (commandAliasesPython.includes(commandConfigPythonBase) && commandAliasesPython.includes(baseCommand)) {
|
|
212
|
+
return this.matchGenericArgsToArgs(commandTokens)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Match generic commands with their args, one to one
|
|
216
|
+
// this matches commands like `node`
|
|
217
|
+
const commandGenericBase: string = this.getBaseCommand(this.command)
|
|
218
|
+
const commandGenericProcessBase: string = this.getBaseCommand(commandTokens[0])
|
|
219
|
+
if (commandGenericBase === commandGenericProcessBase) {
|
|
220
|
+
return this.matchGenericArgsToArgs(commandTokens)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return false
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
private matchGenericArgsToArgs (commandTokens: string[]): boolean {
|
|
227
|
+
if (this.args.length === 0) {
|
|
228
|
+
// If no args configured, we just check if the command matches
|
|
229
|
+
return commandTokens[0] === this.command
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (commandTokens.length < 2) {
|
|
233
|
+
// If there are no command tokens or only the command itself, we cannot match
|
|
234
|
+
return false
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Remove the command from the command tokens
|
|
238
|
+
const commandWithoutArgs = commandTokens.slice(1)
|
|
239
|
+
|
|
240
|
+
for (let i = 0; i < this.args.length; i++) {
|
|
241
|
+
// If we reach the end of command tokens, we cannot match
|
|
242
|
+
if (i >= commandWithoutArgs.length) return false
|
|
243
|
+
|
|
244
|
+
const arg = this.args[i]
|
|
245
|
+
const token = commandWithoutArgs[i]
|
|
246
|
+
|
|
247
|
+
// Check if the argument matches the command token
|
|
248
|
+
if (arg !== token && !token.includes(arg)) {
|
|
249
|
+
return false
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// If we reached here, we matched all arguments
|
|
254
|
+
return true
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// @TODO refactor this to use path.basename or similar
|
|
258
|
+
// to extract the base command from the full command path
|
|
259
|
+
private getBaseCommand (fullCommandPath: string): string {
|
|
260
|
+
// Extract base command name from full path
|
|
261
|
+
const parts = fullCommandPath.split(/[/\\]/)
|
|
262
|
+
return parts[parts.length - 1]
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/*
|
|
266
|
+
example1:
|
|
267
|
+
```
|
|
268
|
+
"command": "uvx",
|
|
269
|
+
"args": ["--from", "mcp-alchemy==2025.5.2.210242", "--with", "oracledb",
|
|
270
|
+
"--refresh-package", "mcp-alchemy", "mcp-alchemy"],
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
example 2:
|
|
274
|
+
```
|
|
275
|
+
"command": "uvx",
|
|
276
|
+
"args": [
|
|
277
|
+
"mcp-neo4j-memory@0.1.4",
|
|
278
|
+
"--db-url",
|
|
279
|
+
"neo4j+s://xxxx.databases.neo4j.io",
|
|
280
|
+
"--username",
|
|
281
|
+
"<your-username>",
|
|
282
|
+
"--password",
|
|
283
|
+
"<your-password>"
|
|
284
|
+
]
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
example 3:
|
|
288
|
+
```
|
|
289
|
+
"vefaas": {
|
|
290
|
+
"command": "uvx",
|
|
291
|
+
"args": [
|
|
292
|
+
"--from",
|
|
293
|
+
"git+https://github.com/volcengine/mcp-server#subdirectory=server/mcp_server_vefaas_function",
|
|
294
|
+
"mcp-server-vefaas-function"
|
|
295
|
+
],
|
|
296
|
+
"env": {
|
|
297
|
+
"VOLC_ACCESSKEY": "xxx",
|
|
298
|
+
"VOLC_SECRETKEY": "xxx"
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
example 4:
|
|
305
|
+
```
|
|
306
|
+
"time": {
|
|
307
|
+
"command": "uvx",
|
|
308
|
+
"args": ["mcp-server-time", "--local-timezone=America/New_York"]
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
*/
|
|
312
|
+
private getUvxMcpServerNameFromArgs (): string | undefined {
|
|
313
|
+
if (this.args.length === 0) return undefined
|
|
314
|
+
|
|
315
|
+
let mcpServerName
|
|
316
|
+
|
|
317
|
+
// If total args is 1 we know it is the MCP server name
|
|
318
|
+
if (this.args.length === 1) {
|
|
319
|
+
mcpServerName = this.args[0]
|
|
320
|
+
return mcpServerName
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// Extract the MCP server name from --from flag if it exists
|
|
324
|
+
for (let i = 0; i < this.args.length; i++) {
|
|
325
|
+
if (this.args[i] === '--from' && i + 1 < this.args.length) {
|
|
326
|
+
mcpServerName = this.args[i + 1]
|
|
327
|
+
return mcpServerName
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// If no use of --from flag, we try to extract the MCP server name from the last argument
|
|
332
|
+
const firstArg = this.args[0]
|
|
333
|
+
if (firstArg.startsWith('-') || firstArg.startsWith('--')) {
|
|
334
|
+
// If the first argument is a flag, take the last argument as the MCP server name
|
|
335
|
+
const lastArg = this.args[this.args.length - 1]
|
|
336
|
+
mcpServerName = lastArg
|
|
337
|
+
return mcpServerName
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// If the first argument is not a flag, take it as the MCP server name
|
|
341
|
+
mcpServerName = firstArg
|
|
342
|
+
return mcpServerName
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
private matchUvxProcess (commandTokens: string[]): boolean {
|
|
346
|
+
if (commandTokens.length === 0) return false
|
|
347
|
+
|
|
348
|
+
// We already matched the base command as "uv" for uvx
|
|
349
|
+
// Let's get the MCP server name from the args in command configuration
|
|
350
|
+
const mcpServerName = this.getUvxMcpServerNameFromArgs()
|
|
351
|
+
if (!mcpServerName) return false
|
|
352
|
+
|
|
353
|
+
// Check if the command tokens contain the MCP server name
|
|
354
|
+
// const expectedArgs = [mcpServerName, ...this.args]
|
|
355
|
+
return this.findMcpServerNameInProcessArguments(commandTokens, mcpServerName)
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
private findMcpServerNameInProcessArguments (commandTokens: string[], mcpServerName: string): boolean {
|
|
359
|
+
// Check if the command tokens contain the MCP server name
|
|
360
|
+
for (let i = 0; i < commandTokens.length; i++) {
|
|
361
|
+
const token = commandTokens[i]
|
|
362
|
+
if (mcpServerName === token || token.includes(mcpServerName)) {
|
|
363
|
+
// If we find the MCP server name in the command tokens, we consider it a match
|
|
364
|
+
return true
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return false
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
private parseCommandLine (commandLine: string): string[] {
|
|
371
|
+
const tokens: string[] = []
|
|
372
|
+
let current = ''
|
|
373
|
+
let inQuotes = false
|
|
374
|
+
let quoteChar = ''
|
|
375
|
+
|
|
376
|
+
for (let i = 0; i < commandLine.length; i++) {
|
|
377
|
+
const char = commandLine[i]
|
|
378
|
+
|
|
379
|
+
if (!inQuotes && (char === '"' || char === "'")) {
|
|
380
|
+
inQuotes = true
|
|
381
|
+
quoteChar = char
|
|
382
|
+
} else if (inQuotes && char === quoteChar) {
|
|
383
|
+
inQuotes = false
|
|
384
|
+
quoteChar = ''
|
|
385
|
+
} else if (!inQuotes && char === ' ') {
|
|
386
|
+
if (current.trim()) {
|
|
387
|
+
tokens.push(current.trim())
|
|
388
|
+
current = ''
|
|
389
|
+
}
|
|
390
|
+
} else {
|
|
391
|
+
current += char
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if (current.trim()) {
|
|
396
|
+
tokens.push(current.trim())
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
return tokens
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/*
|
|
403
|
+
example to match:
|
|
404
|
+
```
|
|
405
|
+
"command": "npx",
|
|
406
|
+
"args": [
|
|
407
|
+
"-y",
|
|
408
|
+
"@modelcontextprotocol/server-postgres",
|
|
409
|
+
"postgresql://localhost/mydb"
|
|
410
|
+
]
|
|
411
|
+
}
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
with a process command like:
|
|
415
|
+
```
|
|
416
|
+
npm exec @modelcontextprotocol/server-postgres postgresql://localhost/mydb
|
|
417
|
+
```
|
|
418
|
+
*/
|
|
419
|
+
private matchNpxProcess (commandTokens: string[]): boolean {
|
|
420
|
+
// npx command pattern: npm exec <package> [args...]
|
|
421
|
+
// Expected command tokens: ["npm", "exec", package_name, ...args]
|
|
422
|
+
|
|
423
|
+
if (commandTokens.length < 3) return false
|
|
424
|
+
|
|
425
|
+
// Check if it's the expected npm exec pattern
|
|
426
|
+
if (commandTokens[1] !== 'exec') return false
|
|
427
|
+
|
|
428
|
+
let argsToMatch: string[] = []
|
|
429
|
+
const yIndex = this.args.indexOf('-y')
|
|
430
|
+
|
|
431
|
+
if (yIndex !== -1 && yIndex + 1 < this.args.length) {
|
|
432
|
+
// Case 1: -y flag is present, extract args after it
|
|
433
|
+
argsToMatch = this.args.slice(yIndex + 1)
|
|
434
|
+
} else {
|
|
435
|
+
// Case 2: No -y flag, match all args directly
|
|
436
|
+
argsToMatch = this.args
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// Match the args after "npm exec" with the extracted args from config
|
|
440
|
+
// commandTokens: ["npm", "exec", package_name, ...additional_args]
|
|
441
|
+
// argsToMatch: [package_name, ...additional_args]
|
|
442
|
+
|
|
443
|
+
if (commandTokens.length - 2 !== argsToMatch.length) {
|
|
444
|
+
// Length mismatch between process args and config args
|
|
445
|
+
return false
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// Compare each argument starting from position 2 in commandTokens
|
|
449
|
+
for (let i = 0; i < argsToMatch.length; i++) {
|
|
450
|
+
const commandToken = commandTokens[i + 2] // Start from index 2 (after "npm exec")
|
|
451
|
+
const expectedArg = argsToMatch[i]
|
|
452
|
+
|
|
453
|
+
if (commandToken !== expectedArg) {
|
|
454
|
+
return false
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
return true
|
|
48
459
|
}
|
|
49
460
|
}
|
|
@@ -27,28 +27,49 @@ export class RenderService {
|
|
|
27
27
|
static printMcpServers (data: any[]) {
|
|
28
28
|
if (data.length === 0) return
|
|
29
29
|
|
|
30
|
-
// const headers = ['STATUS', 'NAME', 'TRANSPORT', 'VERSION', 'TOOLS', 'RESOURCES']
|
|
31
|
-
// const keys = ['status', 'name', 'transport', 'version', 'tools', 'resources']
|
|
32
30
|
const headers = ['STATUS', 'NAME', 'TRANSPORT']
|
|
33
31
|
const keys = ['status', 'name', 'transport']
|
|
34
|
-
const centerColumns = [0, 2
|
|
32
|
+
const centerColumns = [0, 2] // STATUS and TRANSPORT column indices
|
|
35
33
|
const leftPadding = ' ' // 6 characters
|
|
36
34
|
|
|
37
|
-
// Calculate column widths
|
|
35
|
+
// Calculate column widths accounting for styled text
|
|
38
36
|
const columnWidths = headers.map((header, index) => {
|
|
39
|
-
const
|
|
40
|
-
|
|
37
|
+
const headerWidth = this.getVisibleLength(ColumnNameComponent(header))
|
|
38
|
+
const dataWidth = Math.max(...data.map(row => {
|
|
39
|
+
let text = String(row[keys[index]])
|
|
40
|
+
|
|
41
|
+
// Apply the same transformations used in rendering
|
|
42
|
+
if (keys[index] === 'transport') {
|
|
43
|
+
text = TransportComponent(text)
|
|
44
|
+
}
|
|
45
|
+
if (keys[index] === 'status') {
|
|
46
|
+
text = MCPServerStatusComponent(text)
|
|
47
|
+
}
|
|
48
|
+
if (keys[index] === 'name') {
|
|
49
|
+
text = MCPServerNameComponent(text)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return this.getVisibleLength(text)
|
|
53
|
+
}))
|
|
54
|
+
return Math.max(headerWidth, dataWidth)
|
|
41
55
|
})
|
|
42
56
|
|
|
43
57
|
// Helper function to center text in a given width
|
|
44
58
|
const centerText = (text: string, width: number): string => {
|
|
45
|
-
|
|
46
|
-
const padding = width -
|
|
59
|
+
const visibleLength = this.getVisibleLength(text)
|
|
60
|
+
const padding = width - visibleLength
|
|
47
61
|
const leftPad = Math.floor(padding / 2)
|
|
48
62
|
const rightPad = padding - leftPad
|
|
49
63
|
return ' '.repeat(leftPad) + text + ' '.repeat(rightPad)
|
|
50
64
|
}
|
|
51
65
|
|
|
66
|
+
// Helper function to pad text to the right
|
|
67
|
+
const padRight = (text: string, width: number): string => {
|
|
68
|
+
const visibleLength = this.getVisibleLength(text)
|
|
69
|
+
const padding = Math.max(0, width - visibleLength)
|
|
70
|
+
return text + ' '.repeat(padding)
|
|
71
|
+
}
|
|
72
|
+
|
|
52
73
|
// Calculate total table width for separator line
|
|
53
74
|
const totalWidth = columnWidths.reduce((sum, width) => sum + width, 0) + (columnWidths.length - 1) * 2
|
|
54
75
|
const separator = '─'.repeat(totalWidth)
|
|
@@ -62,35 +83,34 @@ export class RenderService {
|
|
|
62
83
|
if (centerColumns.includes(index)) {
|
|
63
84
|
return centerText(headerText, columnWidths[index])
|
|
64
85
|
}
|
|
65
|
-
|
|
66
|
-
const padding = columnWidths[index] - this.getVisibleLength(headerText)
|
|
67
|
-
return headerText + ' '.repeat(Math.max(0, padding))
|
|
86
|
+
return padRight(headerText, columnWidths[index])
|
|
68
87
|
}).join(' ')
|
|
69
88
|
console.log(leftPadding + headerRow)
|
|
70
89
|
|
|
71
|
-
// Print
|
|
90
|
+
// Print separator
|
|
72
91
|
console.log(leftPadding + separator)
|
|
73
92
|
|
|
74
93
|
// Print data rows
|
|
75
94
|
for (const row of data) {
|
|
76
95
|
const dataRow = keys.map((key, index) => {
|
|
77
96
|
let text = String(row[key])
|
|
97
|
+
|
|
98
|
+
// Apply styling transformations
|
|
78
99
|
if (key === 'transport') {
|
|
79
100
|
text = TransportComponent(text)
|
|
80
101
|
}
|
|
81
|
-
|
|
82
102
|
if (key === 'status') {
|
|
83
103
|
text = MCPServerStatusComponent(text)
|
|
84
104
|
}
|
|
85
|
-
|
|
86
105
|
if (key === 'name') {
|
|
87
106
|
text = MCPServerNameComponent(text)
|
|
88
107
|
}
|
|
89
108
|
|
|
109
|
+
// Apply alignment
|
|
90
110
|
if (centerColumns.includes(index)) {
|
|
91
111
|
return centerText(text, columnWidths[index])
|
|
92
112
|
}
|
|
93
|
-
return text
|
|
113
|
+
return padRight(text, columnWidths[index])
|
|
94
114
|
}).join(' ')
|
|
95
115
|
console.log(leftPadding + dataRow)
|
|
96
116
|
}
|
|
@@ -177,11 +197,16 @@ export class RenderService {
|
|
|
177
197
|
const filledWidth = Math.round(progress * width)
|
|
178
198
|
const emptyWidth = width - filledWidth
|
|
179
199
|
|
|
180
|
-
|
|
181
|
-
|
|
200
|
+
let filled: string
|
|
201
|
+
let empty: string
|
|
182
202
|
|
|
183
|
-
|
|
184
|
-
|
|
203
|
+
if (count > 0) {
|
|
204
|
+
filled = styleText(['greenBright'], '█'.repeat(filledWidth))
|
|
205
|
+
empty = styleText(['green'], '░'.repeat(emptyWidth))
|
|
206
|
+
} else {
|
|
207
|
+
filled = '█'.repeat(filledWidth)
|
|
208
|
+
empty = '░'.repeat(emptyWidth)
|
|
209
|
+
}
|
|
185
210
|
|
|
186
211
|
return `${filled}${empty} ${count} / ${total} ${label}`
|
|
187
212
|
}
|