ls-mcp 1.3.1 → 1.5.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/src/main.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import fs from 'node:fs/promises'
2
+ import { platform } from 'node:os'
3
+ import path from 'node:path'
2
4
  import { MCPConfigLinterService } from './services/mcp-config-linter-service.ts'
3
5
  import { MCPServerManagerService } from './services/mcp-server-manager-service.ts'
4
6
 
@@ -39,22 +41,95 @@ interface MCPFileGroupsResult {
39
41
  type MCPFilePathGroupsRecord = Record<string, MCPFileGroups>
40
42
  type MCPFileGroupsResultRecord = Record<string, MCPFileGroupsResult>
41
43
 
44
+ const osSpecificPaths: { [key: string]: MCPFilePath[] } = {
45
+ claude: [],
46
+ cursor: [],
47
+ vscode: [],
48
+ cline: [],
49
+ windsurf: [],
50
+ roo: []
51
+ }
52
+
53
+ if (platform() === 'win32') {
54
+ osSpecificPaths['claude'] = [
55
+ { filePath: `${process.env.APPDATA}\\Claude\\claude_desktop_config.json`, type: 'global' }
56
+ ]
57
+ osSpecificPaths['cursor'] = [
58
+ { filePath: `${process.env.HOME}\\.cursor\\mcp.json`, type: 'global' },
59
+ { filePath: '.cursor\\mcp.json', type: 'local' }
60
+ ]
61
+ osSpecificPaths['vscode'] = [
62
+ { filePath: '.vscode\\mcp.json', type: 'local' },
63
+ { filePath: `${process.env.APPDATA}\\Code\\User\\settings.json`, type: 'global' },
64
+ { filePath: `${process.env.APPDATA}\\Code - Insiders\\User\\settings.json`, type: 'global' },
65
+ ]
66
+ osSpecificPaths['cline'] = [
67
+ { filePath: `${process.env.APPDATA}\\Code\\User\\globalStorage\\saoudrizwan.claude-dev\\settings\\cline_mcp_settings.json`, type: 'global' },
68
+ { filePath: `${process.env.APPDATA}\\Code - Insiders\\User\\globalStorage\\saoudrizwan.claude-dev\\settings\\cline_mcp_settings.json`, type: 'global' }
69
+ ]
70
+ osSpecificPaths['windsurf'] = [
71
+ { filePath: '.codeium\\windsurf\\mcp_config.json', type: 'local' },
72
+ ]
73
+ osSpecificPaths['roo'] = [
74
+ { filePath: `${process.env.APPDATA}\\Code\\User\\globalStorage\\rooveterinaryinc.roo-cline\\settings\\cline_mcp_settings.json`, type: 'global' },
75
+ { filePath: `${process.env.APPDATA}\\Code - Insiders\\User\\globalStorage\\rooveterinaryinc.roo-cline\\settings\\cline_mcp_settings.json`, type: 'global' },]
76
+ } else {
77
+ osSpecificPaths['claude'] = [
78
+ { filePath: '~/Library/Application Support/Claude/claude_desktop_config.json', type: 'global' }
79
+ ]
80
+ osSpecificPaths['cursor'] = [
81
+ { filePath: '~/.cursor/mcp.json', type: 'global' },
82
+ { filePath: '.cursor/mcp.json', type: 'local' }
83
+ ]
84
+ osSpecificPaths['vscode'] = [
85
+ { filePath: '.vscode/mcp.json', type: 'local' },
86
+ { filePath: '~/Library/Application Support/Code/User/settings.json', type: 'global' },
87
+ { filePath: '~/Library/Application Support/Code - Insiders/User/settings.json', type: 'global' },
88
+ ]
89
+ osSpecificPaths['cline'] = [
90
+ { filePath: '~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json', type: 'global' },
91
+ { filePath: '~/Library/Application Support/Code - Insiders/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json', type: 'global' }
92
+ ]
93
+ osSpecificPaths['windsurf'] = [
94
+ { filePath: '.codeium/windsurf/mcp_config.json', type: 'local' },
95
+ ]
96
+ osSpecificPaths['roo'] = [
97
+ { filePath: '~/Library/Application Support/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/cline_mcp_settings.json', type: 'global' },
98
+ { filePath: '~/Library/Application Support/Code - Insiders/User/globalStorage/rooveterinaryinc.roo-cline/settings/cline_mcp_settings.json', type: 'global' },
99
+ ]
100
+ }
101
+
42
102
  export class MCPFiles {
43
103
  private mcpFilePathGroups: MCPFilePathGroupsRecord = {
44
104
  claude: {
45
105
  name: 'claude-desktop',
46
106
  friendlyName: 'Claude Desktop',
47
- paths: [
48
- { filePath: '~/Library/Application Support/Claude/claude_desktop_config.json', type: 'global' },
49
- ]
107
+ paths: osSpecificPaths['claude']
50
108
  },
51
109
  cursor: {
52
110
  name: 'cursor',
53
111
  friendlyName: 'Cursor',
54
- paths: [
55
- { filePath: '~/.cursor/mcp.json', type: 'global' },
56
- { filePath: '.cursor/mcp.json', type: 'local' },
57
- ]
112
+ paths: osSpecificPaths['cursor']
113
+ },
114
+ vscode: {
115
+ name: 'vscode',
116
+ friendlyName: 'VS Code',
117
+ paths: osSpecificPaths['vscode']
118
+ },
119
+ cline: {
120
+ name: 'cline',
121
+ friendlyName: 'Cline',
122
+ paths: osSpecificPaths['cline']
123
+ },
124
+ windsurf: {
125
+ name: 'windsurf',
126
+ friendlyName: 'Windsurf',
127
+ paths: osSpecificPaths['windsurf']
128
+ },
129
+ roo: {
130
+ name: 'roo',
131
+ friendlyName: 'Roo',
132
+ paths: osSpecificPaths['roo']
58
133
  }
59
134
  }
60
135
 
@@ -74,8 +149,16 @@ export class MCPFiles {
74
149
  stats: {}
75
150
  }
76
151
 
152
+ const uniqueFilePaths = new Set<string>()
153
+
77
154
  for (const filePathData of clientsGroup.paths) {
78
155
  const resolvedPath: string = filePathData.filePath.replace('~', process.env.HOME || '')
156
+ const absolutePath: string = path.resolve(resolvedPath)
157
+ if (uniqueFilePaths.has(absolutePath)) {
158
+ continue
159
+ }
160
+ uniqueFilePaths.add(absolutePath)
161
+
79
162
  try {
80
163
  await fs.access(resolvedPath)
81
164
 
@@ -83,6 +166,7 @@ export class MCPFiles {
83
166
  const parsable = await MCPConfigLinter.isValidSyntax()
84
167
  filePathData.parsable = parsable
85
168
 
169
+ // @TODO if file isn't parsable we should skip the following logic here
86
170
  const mcpServersData: MCPServerInfo[] = []
87
171
  const mcpServersFromConfig = await MCPConfigLinter.getMCPServers()
88
172
  // let's iterate over the mcpServer Record and access the server objects
@@ -26,11 +26,27 @@ export class MCPConfigLinterService {
26
26
 
27
27
  async getMCPServers (): Promise<Record<string, object>> {
28
28
  const fileContentRaw = await this.getFileContent()
29
+
30
+ // @TODO parse this file that may have comments inside it
31
+ // can use comment-json npm package or similar
29
32
  const fileContentsData = JSON.parse(fileContentRaw)
30
33
 
31
- const mcpServers = fileContentsData?.mcpServers
34
+ // VS Code uses `servers`
35
+ if (fileContentsData?.servers) {
36
+ return fileContentsData.servers
37
+ }
38
+
39
+ // VS Code global settings.json file uses `mcp` -> `servers`
40
+ if (fileContentsData?.mcp?.servers) {
41
+ return fileContentsData.mcp.servers
42
+ }
43
+
44
+ // Claude and Cursor use the `mcpServers` key
45
+ if (fileContentsData?.mcpServers) {
46
+ return fileContentsData.mcpServers
47
+ }
32
48
 
33
- return mcpServers
49
+ return {}
34
50
  }
35
51
 
36
52
  async getFileContent (): Promise<string> {
@@ -1,3 +1,4 @@
1
+ import path from 'node:path'
1
2
  import { execSync } from 'node:child_process'
2
3
  import { platform } from 'node:os'
3
4
 
@@ -89,17 +90,17 @@ export class MCPServerManagerService {
89
90
 
90
91
  const parts = this.parseCSVLine(processLine)
91
92
  if (parts.length < 4) continue
92
- pid = parts[0] || ''
93
+ pid = parts[0].trim() || ''
93
94
  // Skip Name (parts[1])
94
- commandLine = parts[2] || ''
95
- ppid = parts[3] || ''
95
+ commandLine = parts[2].trim() || ''
96
+ ppid = parts[3].trim() || ''
96
97
  } else {
97
98
  // Parse Unix ps output: PID PPID COMMAND
98
99
  const match = processLine.trim().match(/^\s*(\d+)\s+(\d+)\s+(.+)$/)
99
100
  if (!match) continue
100
- pid = match[1]
101
- ppid = match[2]
102
- commandLine = match[3]
101
+ pid = match[1].trim() || ''
102
+ ppid = match[2].trim() || ''
103
+ commandLine = match[3].trim() || ''
103
104
  }
104
105
 
105
106
  // Parse command line and store in map
@@ -111,8 +112,34 @@ export class MCPServerManagerService {
111
112
 
112
113
  // Then iterate the map to check for matches
113
114
  let mcpServerDetection: MatchedProcess | undefined
115
+
114
116
  for (const [pid, processData] of processMap) {
115
- if (this.isCommandMatch(processData.commandTokens, pid, processData.ppid)) {
117
+ const commandMatchLinux = this.isCommandMatch(processData.commandTokens, pid, processData.ppid)
118
+ let commandMatchWin32 = false
119
+ if (platform() === 'win32') {
120
+ // for Windows, we need to change commandTokens to also match another pattern
121
+ // where the command starts with `cmd` then follows potentially several command-line
122
+ // flags like /c /d and then the actual command.
123
+ // This is because Claude Desktop on Windows automatically starts MCP Servers like that
124
+ // even if the command specified in the MCP config is just `uvx` or `npx`.
125
+
126
+ let commandTokensOnWin32 = processData.commandTokens
127
+ if (commandTokensOnWin32.length > 0 && commandTokensOnWin32[0].toLowerCase().startsWith('cmd')) {
128
+ // If the first token is 'cmd', we need to skip it and check the next tokens
129
+ commandTokensOnWin32 = commandTokensOnWin32.slice(1)
130
+
131
+ // Skip any additional flags like /c, /d, etc.
132
+ while (commandTokensOnWin32.length > 0 && commandTokensOnWin32[0].startsWith('/')) {
133
+ commandTokensOnWin32 = commandTokensOnWin32.slice(1)
134
+ }
135
+ }
136
+
137
+ commandMatchWin32 = this.isCommandMatch(commandTokensOnWin32, pid, processData.ppid)
138
+ }
139
+
140
+ const commandMatch = commandMatchLinux || commandMatchWin32
141
+
142
+ if (commandMatch) {
116
143
  mcpServerDetection = {
117
144
  pid,
118
145
  commandLine: processData.commandTokens.join(' '),
@@ -174,13 +201,15 @@ export class MCPServerManagerService {
174
201
  // e.g. "/usr/homebrew/bin/uv" extracted to "uv"
175
202
  const baseCommand = this.getBaseCommand(commandTokens[0])
176
203
 
204
+ const commandInConfig: string = this.getBaseCommand(this.command)
205
+
177
206
  // Map configured command to actual process command for uvx case
178
- if (this.command === 'uvx' && baseCommand === 'uv') {
207
+ if (commandInConfig === 'uvx' && baseCommand === 'uv') {
179
208
  return this.matchUvxProcess(commandTokens)
180
209
  }
181
210
 
182
211
  // Map configured command to actual process command for npx case
183
- if (this.command === 'npx' && baseCommand === 'npm') {
212
+ if (commandInConfig === 'npx' && baseCommand === 'npm') {
184
213
  return this.matchNpxProcess(commandTokens)
185
214
  }
186
215
 
@@ -196,7 +225,7 @@ export class MCPServerManagerService {
196
225
  ]
197
226
  },
198
227
  */
199
- if (this.command === 'uv' && baseCommand === 'uv') {
228
+ if (commandInConfig === 'uv' && baseCommand === 'uv') {
200
229
  return this.matchGenericArgsToArgs(commandTokens)
201
230
  }
202
231
 
@@ -245,8 +274,8 @@ export class MCPServerManagerService {
245
274
  // If we reach the end of command tokens, we cannot match
246
275
  if (i >= commandWithoutArgs.length) return false
247
276
 
248
- const arg = this.args[i]
249
- const token = commandWithoutArgs[i]
277
+ const arg = this.args[i].toLowerCase()
278
+ const token = commandWithoutArgs[i].toLowerCase()
250
279
 
251
280
  // Check if the argument matches the command token
252
281
  if (arg !== token && !token.includes(arg)) {
@@ -258,12 +287,17 @@ export class MCPServerManagerService {
258
287
  return true
259
288
  }
260
289
 
261
- // @TODO refactor this to use path.basename or similar
262
- // to extract the base command from the full command path
263
290
  private getBaseCommand (fullCommandPath: string): string {
264
291
  // Extract base command name from full path
265
- const parts = fullCommandPath.split(/[/\\]/)
266
- return parts[parts.length - 1]
292
+ let baseCommand = path.basename(fullCommandPath)
293
+ // Detect if we're on Windows and if so we omit the .exe extension
294
+ if (platform() === 'win32') {
295
+ baseCommand = path.basename(fullCommandPath, '.exe')
296
+ }
297
+
298
+ // In any case, we want to return the base command as lowercase
299
+ baseCommand = baseCommand.toLowerCase()
300
+ return baseCommand
267
301
  }
268
302
 
269
303
  /*
@@ -362,8 +396,10 @@ export class MCPServerManagerService {
362
396
  private findMcpServerNameInProcessArguments (commandTokens: string[], mcpServerName: string): boolean {
363
397
  // Check if the command tokens contain the MCP server name
364
398
  for (let i = 0; i < commandTokens.length; i++) {
365
- const token = commandTokens[i]
366
- if (mcpServerName === token || token.includes(mcpServerName)) {
399
+ const token = commandTokens[i].toLowerCase()
400
+ const normalizedMcpServerName = mcpServerName.toLowerCase()
401
+
402
+ if (normalizedMcpServerName === token || token.includes(normalizedMcpServerName)) {
367
403
  // If we find the MCP server name in the command tokens, we consider it a match
368
404
  return true
369
405
  }
@@ -480,8 +516,9 @@ export class MCPServerManagerService {
480
516
 
481
517
  // Compare each argument starting from position 2 in commandTokens
482
518
  for (let i = 0; i < argsToMatch.length; i++) {
483
- const commandToken = commandTokens[i + 2] // Start from index 2 (after "npm exec")
484
- const expectedArg = argsToMatch[i]
519
+ // Start from index 2 (after "npm exec")
520
+ const commandToken = commandTokens[i + 2].toLowerCase()
521
+ const expectedArg = argsToMatch[i].toLowerCase()
485
522
 
486
523
  if (commandToken !== expectedArg) {
487
524
  return false
@@ -180,9 +180,6 @@ export class RenderService {
180
180
  const leftPadding = index === 0 ? leftPaddingGroupLead : leftPaddingGroupData
181
181
  console.log(leftPadding + dataRow)
182
182
  }
183
-
184
- // Print bottom separator
185
- // console.log('')
186
183
  }
187
184
 
188
185
  // draws progress bar components like this