ls-mcp 1.1.0 → 1.2.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.
@@ -0,0 +1,188 @@
1
+ import { styleText } from 'node:util'
2
+ import TransportComponent from '../components/transport.js'
3
+ import ColumnNameComponent from '../components/column-name.js'
4
+ import MCPServerStatusComponent from '../components/mcp-server-status.js'
5
+ import MCPServerNameComponent from '../components/mcp-server-name.js'
6
+ import FilePathComponent from '../components/file-path.js'
7
+ import MCPServersConfigParsableComponent from '../components/mcp-servers-config-parsable.js'
8
+
9
+ interface GroupMetadata {
10
+ mcpServersRunning?: number
11
+ mcpServersTotal?: number
12
+ }
13
+
14
+ export class RenderService {
15
+ // Example mocked data for rendering the servers information
16
+ // const mcpServersDataMock = [
17
+ // { status: '●', name: 'logging-server', type: 'SSE', version: '2.3.0', tools: '6', resources: '2' },
18
+ // { status: '●', name: 'git-logging-server', type: 'SSE', version: '2.3.0', tools: '6', resources: '2' },
19
+ // { status: '○', name: 'mcp-server', type: 'STDIO', version: '2.3.0', tools: '62', resources: '0' }
20
+ // ]
21
+
22
+ private static getVisibleLength (text: string): number {
23
+ // Calculate visible length by removing ANSI escape codes
24
+ return text.replace(/\u001b\[[0-9;]*m/g, '').length
25
+ }
26
+
27
+ static printMcpServers (data: any[]) {
28
+ if (data.length === 0) return
29
+
30
+ // const headers = ['STATUS', 'NAME', 'TRANSPORT', 'VERSION', 'TOOLS', 'RESOURCES']
31
+ // const keys = ['status', 'name', 'transport', 'version', 'tools', 'resources']
32
+ const headers = ['STATUS', 'NAME', 'TRANSPORT']
33
+ const keys = ['status', 'name', 'transport']
34
+ const centerColumns = [0, 2, 4, 5] // STATUS, TOOLS, RESOURCES column indices
35
+ const leftPadding = ' ' // 6 characters
36
+
37
+ // Calculate column widths
38
+ const columnWidths = headers.map((header, index) => {
39
+ const dataWidth = Math.max(...data.map(row => String(row[keys[index]]).length))
40
+ return Math.max(header.length, dataWidth)
41
+ })
42
+
43
+ // Helper function to center text in a given width
44
+ const centerText = (text: string, width: number): string => {
45
+ // Calculate visible length by removing ANSI escape codes
46
+ const padding = width - this.getVisibleLength(text)
47
+ const leftPad = Math.floor(padding / 2)
48
+ const rightPad = padding - leftPad
49
+ return ' '.repeat(leftPad) + text + ' '.repeat(rightPad)
50
+ }
51
+
52
+ // Calculate total table width for separator line
53
+ const totalWidth = columnWidths.reduce((sum, width) => sum + width, 0) + (columnWidths.length - 1) * 2
54
+ const separator = '─'.repeat(totalWidth)
55
+
56
+ // Print top separator
57
+ console.log('\n' + leftPadding + separator)
58
+
59
+ // Print header
60
+ const headerRow = headers.map((header, index) => {
61
+ const headerText = ColumnNameComponent(header)
62
+ if (centerColumns.includes(index)) {
63
+ return centerText(headerText, columnWidths[index])
64
+ }
65
+ // Calculate visible length by removing ANSI escape codes
66
+ const padding = columnWidths[index] - this.getVisibleLength(headerText)
67
+ return headerText + ' '.repeat(Math.max(0, padding))
68
+ }).join(' ')
69
+ console.log(leftPadding + headerRow)
70
+
71
+ // Print bottom separator
72
+ console.log(leftPadding + separator)
73
+
74
+ // Print data rows
75
+ for (const row of data) {
76
+ const dataRow = keys.map((key, index) => {
77
+ let text = String(row[key])
78
+ if (key === 'transport') {
79
+ text = TransportComponent(text)
80
+ }
81
+
82
+ if (key === 'status') {
83
+ text = MCPServerStatusComponent(text)
84
+ }
85
+
86
+ if (key === 'name') {
87
+ text = MCPServerNameComponent(text)
88
+ }
89
+
90
+ if (centerColumns.includes(index)) {
91
+ return centerText(text, columnWidths[index])
92
+ }
93
+ return text.padEnd(columnWidths[index])
94
+ }).join(' ')
95
+ console.log(leftPadding + dataRow)
96
+ }
97
+
98
+ console.log('\n')
99
+ console.log(`${leftPadding}▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄`)
100
+ }
101
+
102
+ // Example mocked data for rendering the group information
103
+ // const mcpGroupDataMock = [
104
+ // { key: 'PROVIDER', value: 'Claude Desktop', },
105
+ // { key: 'FILE', value: '~/Library/Application Support/Claude/claude_desktop_config.json' },
106
+ // { key: 'STATUS', value: '[✓ VALID] [GLOBAL] [5 MCP SERVERS]' }
107
+ // ]
108
+
109
+ static printMcpGroup (id: number, data: any[], groupMetadata: GroupMetadata = {}) {
110
+ if (data.length === 0) return
111
+
112
+ console.log('\n')
113
+
114
+ const headers = ['KEY', 'VALUE']
115
+ const keys = ['key', 'value']
116
+
117
+ // group left padding should include the indicator number
118
+ // and then calculator for the remaining right padding.
119
+ // left padding in total is 6 characters
120
+ const indexText = `[${id}]`
121
+ const leftPaddingGroupLead = indexText + ' '.repeat(6 - indexText.length)
122
+ const leftPaddingGroupData = ' '.repeat(6)
123
+
124
+ // Append group metadata keys to the data array
125
+ if (Object.keys(groupMetadata).length > 0) {
126
+ const runningCount = groupMetadata.mcpServersRunning || 0
127
+ const totalCount = groupMetadata.mcpServersTotal || 0
128
+ const metadataRow = this.renderProgressBar(runningCount, totalCount, 'Running')
129
+ data.push({ key: 'MCP SERVERS', value: metadataRow })
130
+ }
131
+
132
+ // Calculate column widths
133
+ const columnWidths = headers.map((header, index) => {
134
+ const dataWidth = Math.max(...data.map(row => {
135
+ const columnText = ColumnNameComponent(row[keys[index]])
136
+ const columnTextLength = this.getVisibleLength(columnText)
137
+ return columnTextLength
138
+ }))
139
+ return Math.max(header.length, dataWidth)
140
+ })
141
+
142
+ // Print data rows
143
+ for (const [index, row] of data.entries()) {
144
+ const dataRow = keys.map((key, index) => {
145
+ const paddingNormalizer = ColumnNameComponent(row[key]).length - row[key].length
146
+ if (key === 'key') {
147
+ return ColumnNameComponent(row[key]).padEnd(columnWidths[index] + paddingNormalizer)
148
+ }
149
+
150
+ if (row['key'] === 'FILE') {
151
+ return FilePathComponent(row[key]).padEnd(columnWidths[index] + paddingNormalizer)
152
+ }
153
+
154
+ if (row['key'] === 'PARSABLE') {
155
+ return MCPServersConfigParsableComponent(row[key]).padEnd(columnWidths[index] + paddingNormalizer)
156
+ }
157
+
158
+ return String(row[key]).padEnd(columnWidths[index] + paddingNormalizer)
159
+ }).join(' ')
160
+ const leftPadding = index === 0 ? leftPaddingGroupLead : leftPaddingGroupData
161
+ console.log(leftPadding + dataRow)
162
+ }
163
+
164
+ // Print bottom separator
165
+ // console.log('')
166
+ }
167
+
168
+ // draws progress bar components like this
169
+ // "███████░░░░░░░░░░░░░ 3 / 9 Running"
170
+ static renderProgressBar (count: number, total: number, label: string, width: number = 20): string {
171
+ if (total === 0) {
172
+ const emptyBar = '░'.repeat(width)
173
+ return `${emptyBar} 0 / 0 ${label}`
174
+ }
175
+
176
+ const progress = Math.min(count / total, 1)
177
+ const filledWidth = Math.round(progress * width)
178
+ const emptyWidth = width - filledWidth
179
+
180
+ const colorRunning = count > 0 ? 'greenBright' : 'red'
181
+ const colorEmpty = count > 0 ? 'green' : 'red'
182
+
183
+ const filled = styleText([colorRunning], '█'.repeat(filledWidth))
184
+ const empty = styleText([colorEmpty], '░'.repeat(emptyWidth))
185
+
186
+ return `${filled}${empty} ${count} / ${total} ${label}`
187
+ }
188
+ }
@@ -0,0 +1,7 @@
1
+ import { styleText } from 'node:util'
2
+
3
+ export class FormatterService {
4
+ filePathToTerminal (filePath: string): string {
5
+ return styleText(['underline'], filePath)
6
+ }
7
+ }