-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcli.ts
More file actions
executable file
·80 lines (64 loc) · 2.36 KB
/
cli.ts
File metadata and controls
executable file
·80 lines (64 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
#!/usr/bin/env node
// import { debuglog } from 'node:util'
import { styleText } from 'node:util'
import { MCPFiles } from '../main.ts'
import { RenderService } from '../services/render-service.ts'
interface MCPServerInfo {
name: string
command: string
args?: string[]
transport?: 'stdio' | 'sse' | 'http'
source?: 'local' | 'remote'
env?: Record<string, string>
status?: 'running' | 'stopped'
}
// @TODO add debug logging
// const debug = debuglog('ls-mcp')
async function init () {
// Start the CLI with a new line for better readability
console.log()
console.log('[+] Detecting MCP Server configurations...')
const mcpFilesManager = new MCPFiles()
const mcpFilesList = await mcpFilesManager.findFiles()
if (Object.keys(mcpFilesList).length === 0) {
exitWithError('No configuration for MCP Server applications found.')
}
let pathIndex = 0
for (const groupName of Object.keys(mcpFilesList)) {
const group = mcpFilesList[groupName]
if (group.paths.length > 0) {
// handle file path list of MCP Servers
for (const filePathData of group.paths) {
pathIndex++
const filePath = filePathData.filePath.replace('~', process.env.HOME || '')
const filePathValid = filePathData.parsable ? 'VALID' : 'INVALID'
const filePathDataType = filePathData.type.toUpperCase()
const mcpServers = filePathData.servers || []
const totalMCPServers = filePathData.servers ? filePathData.servers.length : 0
const totalMCPServersRunning = mcpServers.filter((server: MCPServerInfo) => server.status === 'running').length
const mcpGroupData = [
{ key: 'PROVIDER', value: group.friendlyName },
{ key: 'FILE', value: filePath },
{ key: 'TYPE', value: filePathDataType },
{ key: 'PARSABLE', value: filePathValid },
]
const groupMetadata = {
mcpServersTotal: totalMCPServers,
mcpServersRunning: totalMCPServersRunning,
}
RenderService.printMcpGroup(pathIndex, mcpGroupData, groupMetadata)
RenderService.printMcpServers(mcpServers)
}
}
}
if (pathIndex === 0) {
exitWithError('No MCP servers found in known configuration files.')
}
}
init().then(() => {
console.log('\n')
})
function exitWithError (message: string) {
console.error(`${styleText(['red'], '●')} ${message}\n`)
process.exit(1)
}