ls-mcp 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,213 @@
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']
31
+ const keys = ['status', 'name', 'transport']
32
+ const centerColumns = [0, 2] // STATUS and TRANSPORT column indices
33
+ const leftPadding = ' ' // 6 characters
34
+
35
+ // Calculate column widths accounting for styled text
36
+ const columnWidths = headers.map((header, index) => {
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)
55
+ })
56
+
57
+ // Helper function to center text in a given width
58
+ const centerText = (text: string, width: number): string => {
59
+ const visibleLength = this.getVisibleLength(text)
60
+ const padding = width - visibleLength
61
+ const leftPad = Math.floor(padding / 2)
62
+ const rightPad = padding - leftPad
63
+ return ' '.repeat(leftPad) + text + ' '.repeat(rightPad)
64
+ }
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
+
73
+ // Calculate total table width for separator line
74
+ const totalWidth = columnWidths.reduce((sum, width) => sum + width, 0) + (columnWidths.length - 1) * 2
75
+ const separator = '─'.repeat(totalWidth)
76
+
77
+ // Print top separator
78
+ console.log('\n' + leftPadding + separator)
79
+
80
+ // Print header
81
+ const headerRow = headers.map((header, index) => {
82
+ const headerText = ColumnNameComponent(header)
83
+ if (centerColumns.includes(index)) {
84
+ return centerText(headerText, columnWidths[index])
85
+ }
86
+ return padRight(headerText, columnWidths[index])
87
+ }).join(' ')
88
+ console.log(leftPadding + headerRow)
89
+
90
+ // Print separator
91
+ console.log(leftPadding + separator)
92
+
93
+ // Print data rows
94
+ for (const row of data) {
95
+ const dataRow = keys.map((key, index) => {
96
+ let text = String(row[key])
97
+
98
+ // Apply styling transformations
99
+ if (key === 'transport') {
100
+ text = TransportComponent(text)
101
+ }
102
+ if (key === 'status') {
103
+ text = MCPServerStatusComponent(text)
104
+ }
105
+ if (key === 'name') {
106
+ text = MCPServerNameComponent(text)
107
+ }
108
+
109
+ // Apply alignment
110
+ if (centerColumns.includes(index)) {
111
+ return centerText(text, columnWidths[index])
112
+ }
113
+ return padRight(text, columnWidths[index])
114
+ }).join(' ')
115
+ console.log(leftPadding + dataRow)
116
+ }
117
+
118
+ console.log('\n')
119
+ console.log(`${leftPadding}▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄`)
120
+ }
121
+
122
+ // Example mocked data for rendering the group information
123
+ // const mcpGroupDataMock = [
124
+ // { key: 'PROVIDER', value: 'Claude Desktop', },
125
+ // { key: 'FILE', value: '~/Library/Application Support/Claude/claude_desktop_config.json' },
126
+ // { key: 'STATUS', value: '[✓ VALID] [GLOBAL] [5 MCP SERVERS]' }
127
+ // ]
128
+
129
+ static printMcpGroup (id: number, data: any[], groupMetadata: GroupMetadata = {}) {
130
+ if (data.length === 0) return
131
+
132
+ console.log('\n')
133
+
134
+ const headers = ['KEY', 'VALUE']
135
+ const keys = ['key', 'value']
136
+
137
+ // group left padding should include the indicator number
138
+ // and then calculator for the remaining right padding.
139
+ // left padding in total is 6 characters
140
+ const indexText = `[${id}]`
141
+ const leftPaddingGroupLead = indexText + ' '.repeat(6 - indexText.length)
142
+ const leftPaddingGroupData = ' '.repeat(6)
143
+
144
+ // Append group metadata keys to the data array
145
+ if (Object.keys(groupMetadata).length > 0) {
146
+ const runningCount = groupMetadata.mcpServersRunning || 0
147
+ const totalCount = groupMetadata.mcpServersTotal || 0
148
+ const metadataRow = this.renderProgressBar(runningCount, totalCount, 'Running')
149
+ data.push({ key: 'MCP SERVERS', value: metadataRow })
150
+ }
151
+
152
+ // Calculate column widths
153
+ const columnWidths = headers.map((header, index) => {
154
+ const dataWidth = Math.max(...data.map(row => {
155
+ const columnText = ColumnNameComponent(row[keys[index]])
156
+ const columnTextLength = this.getVisibleLength(columnText)
157
+ return columnTextLength
158
+ }))
159
+ return Math.max(header.length, dataWidth)
160
+ })
161
+
162
+ // Print data rows
163
+ for (const [index, row] of data.entries()) {
164
+ const dataRow = keys.map((key, index) => {
165
+ const paddingNormalizer = ColumnNameComponent(row[key]).length - row[key].length
166
+ if (key === 'key') {
167
+ return ColumnNameComponent(row[key]).padEnd(columnWidths[index] + paddingNormalizer)
168
+ }
169
+
170
+ if (row['key'] === 'FILE') {
171
+ return FilePathComponent(row[key]).padEnd(columnWidths[index] + paddingNormalizer)
172
+ }
173
+
174
+ if (row['key'] === 'PARSABLE') {
175
+ return MCPServersConfigParsableComponent(row[key]).padEnd(columnWidths[index] + paddingNormalizer)
176
+ }
177
+
178
+ return String(row[key]).padEnd(columnWidths[index] + paddingNormalizer)
179
+ }).join(' ')
180
+ const leftPadding = index === 0 ? leftPaddingGroupLead : leftPaddingGroupData
181
+ console.log(leftPadding + dataRow)
182
+ }
183
+
184
+ // Print bottom separator
185
+ // console.log('')
186
+ }
187
+
188
+ // draws progress bar components like this
189
+ // "███████░░░░░░░░░░░░░ 3 / 9 Running"
190
+ static renderProgressBar (count: number, total: number, label: string, width: number = 20): string {
191
+ if (total === 0) {
192
+ const emptyBar = '░'.repeat(width)
193
+ return `${emptyBar} 0 / 0 ${label}`
194
+ }
195
+
196
+ const progress = Math.min(count / total, 1)
197
+ const filledWidth = Math.round(progress * width)
198
+ const emptyWidth = width - filledWidth
199
+
200
+ let filled: string
201
+ let empty: string
202
+
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
+ }
210
+
211
+ return `${filled}${empty} ${count} / ${total} ${label}`
212
+ }
213
+ }
@@ -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
+ }