ls-mcp 1.9.0 → 1.10.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ls-mcp",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "description": "list and detect MCP servers and configurations",
5
5
  "types": "dist/main.d.ts",
6
6
  "type": "module",
@@ -40,6 +40,7 @@
40
40
  "lint": "eslint . && npm run lint:lockfile",
41
41
  "lint:fix": "eslint . --fix",
42
42
  "lint:lockfile": "lockfile-lint --path package-lock.json --validate-https --allowed-hosts npm yarn",
43
+ "lint:markdown": "npx -y markdownlint-cli@0.45.0 -c .github/.markdownlint.yml '**/**.md' --fix",
43
44
  "test": "c8 node --import tsx --test __tests__/**/*.test.ts",
44
45
  "test:watch": "c8 node --import tsx --test --watch __tests__/**/*.test.ts",
45
46
  "coverage:view": "open coverage/lcov-report/index.html",
@@ -77,6 +78,7 @@
77
78
  "jsonc-parser": "^3.3.1"
78
79
  },
79
80
  "devDependencies": {
81
+ "@changesets/changelog-git": "^0.2.1",
80
82
  "@changesets/changelog-github": "^0.5.0",
81
83
  "@changesets/cli": "^2.27.7",
82
84
  "@types/node": "^24.0.3",
package/src/bin/cli.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- // import { debuglog } from 'node:util'
4
3
  import { styleText } from 'node:util'
5
4
  import { MCPFiles } from '../main.ts'
6
5
  import { RenderService } from '../services/render-service.ts'
@@ -10,15 +9,13 @@ interface MCPServerInfo {
10
9
  command: string
11
10
  args?: string[]
12
11
  transport?: 'stdio' | 'sse' | 'http'
13
- type?: 'sse' | 'http' | 'stdio'
12
+ type?: 'sse' | 'http' | 'stdio' | 'streamable-http'
14
13
  source?: string
15
14
  env?: Record<string, string>
16
15
  status?: 'running' | 'stopped'
16
+ credentials?: any
17
17
  }
18
18
 
19
- // @TODO add debug logging
20
- // const debug = debuglog('ls-mcp')
21
-
22
19
  async function init () {
23
20
  // Start the CLI with a new line for better readability
24
21
  console.log()
@@ -32,6 +29,11 @@ async function init () {
32
29
  }
33
30
 
34
31
  let pathIndex = 0
32
+ let totalServers = 0
33
+ let totalRunning = 0
34
+ let totalHighRiskCredentials = 0
35
+ const transportCounts = { stdio: 0, sse: 0, http: 0 }
36
+
35
37
  for (const groupName of Object.keys(mcpFilesList)) {
36
38
  const group = mcpFilesList[groupName]
37
39
 
@@ -48,6 +50,26 @@ async function init () {
48
50
  const totalMCPServers = filePathData.servers ? filePathData.servers.length : 0
49
51
  const totalMCPServersRunning = mcpServers.filter((server: MCPServerInfo) => server.status === 'running').length
50
52
 
53
+ // Accumulate summary statistics
54
+ totalServers += totalMCPServers
55
+ totalRunning += totalMCPServersRunning
56
+
57
+ // Count transport types
58
+ for (const server of mcpServers) {
59
+ // transport field is always populated from type field in the data layer
60
+ if (server.transport) {
61
+ const transport = server.transport.toLowerCase()
62
+ if (transport in transportCounts) {
63
+ transportCounts[transport as keyof typeof transportCounts]++
64
+ }
65
+ }
66
+
67
+ // Count high-risk credentials
68
+ if (server.credentials?.hasCredentials && server.credentials?.riskLevel === 'high') {
69
+ totalHighRiskCredentials++
70
+ }
71
+ }
72
+
51
73
  const mcpGroupData = [
52
74
  { key: 'PROVIDER', value: group.friendlyName },
53
75
  { key: 'FILE', value: filePath },
@@ -69,6 +91,16 @@ async function init () {
69
91
  if (pathIndex === 0) {
70
92
  exitWithError('No MCP servers found in known configuration files.')
71
93
  }
94
+
95
+ // Display summary statistics
96
+ const summaryStats = {
97
+ totalServers,
98
+ runningServers: totalRunning,
99
+ highRiskCredentials: totalHighRiskCredentials,
100
+ transportBreakdown: transportCounts
101
+ }
102
+
103
+ RenderService.printSummary(summaryStats)
72
104
  }
73
105
 
74
106
  init().then(() => {
@@ -0,0 +1,37 @@
1
+ import { styleText } from 'node:util'
2
+ import { type CredentialAnalysisResult } from '../types/mcp-config-service.types.js'
3
+
4
+ export default function CredentialWarningComponent (credentials: CredentialAnalysisResult | undefined): string {
5
+ if (!credentials || !credentials.hasCredentials) {
6
+ return ''
7
+ }
8
+
9
+ const { riskLevel, credentialVars } = credentials
10
+
11
+ // Color coding based on risk level
12
+ let riskColor: 'red' | 'blue'
13
+ let riskIcon: string
14
+
15
+ switch (riskLevel) {
16
+ case 'high':
17
+ riskColor = 'red'
18
+ riskIcon = styleText(['red'], '●')
19
+ break
20
+ case 'low':
21
+ riskColor = 'blue'
22
+ riskIcon = styleText(['blue'], '●')
23
+ break
24
+ default:
25
+ riskColor = 'blue'
26
+ riskIcon = styleText(['blue'], '●')
27
+ }
28
+
29
+ const riskText = styleText([riskColor], `${riskIcon} ${riskLevel.toUpperCase()} RISK`)
30
+
31
+ // Create summary of credential variables
32
+ const credentialSummary = credentialVars
33
+ .map(cv => `${cv.name}=${cv.value}`)
34
+ .join(', ')
35
+
36
+ return `${riskText} ${styleText(['dim'], `(${credentialVars.length} cred vars: ${credentialSummary})`)}`
37
+ }
@@ -0,0 +1,57 @@
1
+ import { styleText } from 'node:util'
2
+
3
+ interface SummaryStats {
4
+ totalServers: number
5
+ runningServers: number
6
+ highRiskCredentials: number
7
+ transportBreakdown: {
8
+ stdio: number
9
+ sse: number
10
+ http: number
11
+ }
12
+ }
13
+
14
+ export default function SummaryComponent (stats: SummaryStats): string {
15
+ const { totalServers, runningServers, highRiskCredentials, transportBreakdown } = stats
16
+
17
+ // Create progress bars (20 characters wide, following existing convention)
18
+ const runningBar = createProgressBar(runningServers, totalServers, 20, 'green')
19
+ const securityBar = createProgressBar(highRiskCredentials, totalServers, 20, 'red')
20
+
21
+ // Format transport breakdown
22
+ const transportText = `stdio: ${transportBreakdown.stdio} | SSE: ${transportBreakdown.sse} | HTTP: ${transportBreakdown.http}`
23
+
24
+ // Build the summary output
25
+ const lines = [
26
+ 'SUMMARY',
27
+ ` SERVERS ${runningBar} ${runningServers} / ${totalServers} Running`,
28
+ ` SECURITY ${securityBar} ${highRiskCredentials} / ${totalServers} High Risk Credentials`,
29
+ ` TRANSPORT ${transportText}`
30
+ ]
31
+
32
+ return lines.join('\n')
33
+ }
34
+
35
+ function createProgressBar (count: number, total: number, width: number, color: 'green' | 'red'): string {
36
+ if (total === 0) {
37
+ const emptyBar = '░'.repeat(width)
38
+ return emptyBar
39
+ }
40
+
41
+ const progress = Math.min(count / total, 1)
42
+ const filledWidth = Math.round(progress * width)
43
+ const emptyWidth = width - filledWidth
44
+
45
+ let filled: string
46
+ let empty: string
47
+
48
+ if (color === 'green') {
49
+ filled = styleText(['greenBright'], '█'.repeat(filledWidth))
50
+ empty = styleText(['green'], '░'.repeat(emptyWidth))
51
+ } else { // red
52
+ filled = styleText(['redBright'], '█'.repeat(filledWidth))
53
+ empty = styleText(['red'], '░'.repeat(emptyWidth))
54
+ }
55
+
56
+ return `${filled}${empty}`
57
+ }
package/src/main.ts CHANGED
@@ -1,275 +1,66 @@
1
- import fs from 'node:fs/promises'
2
- import { platform } from 'node:os'
3
- import path from 'node:path'
4
- import { MCPConfigLinterService } from './services/mcp-config-linter-service.ts'
5
- import { MCPServerManagerService } from './services/mcp-server-manager-service.ts'
6
-
7
- interface MCPServerInfo {
8
- name: string
9
- command: string
10
- args?: string[]
11
- transport?: 'stdio' | 'sse' | 'http',
12
- type?: 'sse' | 'http' | 'stdio'
13
- source?: string
14
- env?: Record<string, string>
15
- status?: 'running' | 'stopped'
16
- }
17
-
18
- interface MCPFilePath {
19
- filePath: string
20
- type: 'local' | 'global'
21
- parsable?: boolean
22
- servers?: MCPServerInfo[]
23
- }
24
-
25
- interface MCPFileGroups {
26
- name: string
27
- friendlyName: string
28
- paths: MCPFilePath[]
29
- stats?: {
30
- serversCount?: number
31
- }
32
- }
33
-
34
- interface MCPFileGroupsResult {
35
- name: string
36
- friendlyName: string
37
- paths: MCPFilePath[]
38
- stats: {
39
- serversCount?: number
40
- }
41
- }
42
-
43
- type MCPFilePathGroupsRecord = Record<string, MCPFileGroups>
44
- type MCPFileGroupsResultRecord = Record<string, MCPFileGroupsResult>
45
-
46
- const osSpecificPaths: { [key: string]: MCPFilePath[] } = {
47
- claude: [],
48
- claude_code: [],
49
- cursor: [],
50
- vscode: [],
51
- cline: [],
52
- windsurf: [],
53
- roo: [],
54
- 'intellij-github-copilot': [],
55
- junie: []
56
- }
57
-
58
- if (platform() === 'win32') {
59
- osSpecificPaths['claude'] = [
60
- { filePath: `${process.env.APPDATA}\\Claude\\claude_desktop_config.json`, type: 'global' }
61
- ]
62
- osSpecificPaths['claude_code'] = [
63
- { filePath: '.mcp.json', type: 'local' }
64
- ]
65
- osSpecificPaths['cursor'] = [
66
- { filePath: '~\\.cursor\\mcp.json', type: 'global' },
67
- { filePath: '.cursor\\mcp.json', type: 'local' }
68
- ]
69
- osSpecificPaths['vscode'] = [
70
- { filePath: '.vscode\\mcp.json', type: 'local' },
71
- { filePath: `${process.env.APPDATA}\\Code\\User\\settings.json`, type: 'global' },
72
- { filePath: `${process.env.APPDATA}\\Code - Insiders\\User\\settings.json`, type: 'global' },
73
- { filePath: `${process.env.APPDATA}\\Code\\User\\mcp.json`, type: 'global' },
74
- { filePath: `${process.env.APPDATA}\\Code - Insiders\\User\\mcp.json`, type: 'global' }
75
- ]
76
- osSpecificPaths['cline'] = [
77
- { filePath: `${process.env.APPDATA}\\Code\\User\\globalStorage\\saoudrizwan.claude-dev\\settings\\cline_mcp_settings.json`, type: 'global' },
78
- { filePath: `${process.env.APPDATA}\\Code - Insiders\\User\\globalStorage\\saoudrizwan.claude-dev\\settings\\cline_mcp_settings.json`, type: 'global' }
79
- ]
80
- osSpecificPaths['windsurf'] = [
81
- { filePath: '.codeium\\windsurf\\mcp_config.json', type: 'local' },
82
- ]
83
- osSpecificPaths['roo'] = [
84
- { filePath: `${process.env.APPDATA}\\Code\\User\\globalStorage\\rooveterinaryinc.roo-cline\\settings\\cline_mcp_settings.json`, type: 'global' },
85
- { filePath: `${process.env.APPDATA}\\Code - Insiders\\User\\globalStorage\\rooveterinaryinc.roo-cline\\settings\\cline_mcp_settings.json`, type: 'global' },
86
- ]
87
- osSpecificPaths['intellij-github-copilot'] = [
88
- { filePath: `${process.env.LOCALAPPDATA}\\github-copilot\\intellij\\mcp.json`, type: 'global' },
89
- ]
90
- osSpecificPaths['junie'] = [
91
- { filePath: '~\\.junie\\mcp\\mcp.json', type: 'global' },
92
- ]
93
- osSpecificPaths['zed'] = [
94
- { filePath: `${process.env.LOCALAPPDATA}\\zed\\settings.json`, type: 'global' },
95
- { filePath: '.zed\\settings.json', type: 'local' }
96
- ]
97
- } else {
98
- osSpecificPaths['claude'] = [
99
- { filePath: '~/Library/Application Support/Claude/claude_desktop_config.json', type: 'global' }
100
- ]
101
- osSpecificPaths['claude_code'] = [
102
- { filePath: '.mcp.json', type: 'local' }
103
- ]
104
- osSpecificPaths['cursor'] = [
105
- { filePath: '~/.cursor/mcp.json', type: 'global' },
106
- { filePath: '.cursor/mcp.json', type: 'local' }
107
- ]
108
- osSpecificPaths['vscode'] = [
109
- { filePath: '.vscode/mcp.json', type: 'local' },
110
- { filePath: '~/Library/Application Support/Code/User/settings.json', type: 'global' },
111
- { filePath: '~/Library/Application Support/Code/User/mcp.json', type: 'global' },
112
- { filePath: '~/Library/Application Support/Code - Insiders/User/settings.json', type: 'global' },
113
- { filePath: '~/Library/Application Support/Code - Insiders/User/mcp.json', type: 'global' }
114
- ]
115
- osSpecificPaths['cline'] = [
116
- { filePath: '~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json', type: 'global' },
117
- { filePath: '~/Library/Application Support/Code - Insiders/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json', type: 'global' }
118
- ]
119
- osSpecificPaths['windsurf'] = [
120
- { filePath: '.codeium/windsurf/mcp_config.json', type: 'local' },
121
- ]
122
- osSpecificPaths['roo'] = [
123
- { filePath: '~/Library/Application Support/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/cline_mcp_settings.json', type: 'global' },
124
- { filePath: '~/Library/Application Support/Code - Insiders/User/globalStorage/rooveterinaryinc.roo-cline/settings/cline_mcp_settings.json', type: 'global' },
125
- ]
126
- osSpecificPaths['intellij-github-copilot'] = [
127
- { filePath: '~/.config/github-copilot/intellij/mcp.json', type: 'global' },
128
- ]
129
- osSpecificPaths['junie'] = [
130
- { filePath: '~/.junie/mcp/mcp.json', type: 'global' },
131
- { filePath: '.junie/mcp/mcp.json', type: 'local' }
132
- ]
133
-
134
- osSpecificPaths['zed'] = [
135
- { filePath: '~/.config/zed/settings.json', type: 'global' },
136
- { filePath: '.zed/settings.json', type: 'local' }
137
- ]
138
- }
1
+ import { MCPConfigService } from './services/mcp-config-service.js'
2
+ import { MCPServerManagerService } from './services/mcp-server-manager-service.js'
3
+ import { type MCPFileGroupsResultRecord } from './types/mcp-config-service.types.js'
139
4
 
140
5
  export class MCPFiles {
141
- private mcpFilePathGroups: MCPFilePathGroupsRecord = {
142
- claude: {
143
- name: 'claude-desktop',
144
- friendlyName: 'Claude Desktop',
145
- paths: osSpecificPaths['claude']
146
- },
147
- claude_code: {
148
- name: 'claude-code',
149
- friendlyName: 'Claude Code',
150
- paths: osSpecificPaths['claude_code']
151
- },
152
- cursor: {
153
- name: 'cursor',
154
- friendlyName: 'Cursor',
155
- paths: osSpecificPaths['cursor']
156
- },
157
- vscode: {
158
- name: 'vscode',
159
- friendlyName: 'VS Code',
160
- paths: osSpecificPaths['vscode']
161
- },
162
- cline: {
163
- name: 'cline',
164
- friendlyName: 'Cline',
165
- paths: osSpecificPaths['cline']
166
- },
167
- windsurf: {
168
- name: 'windsurf',
169
- friendlyName: 'Windsurf',
170
- paths: osSpecificPaths['windsurf']
171
- },
172
- roo: {
173
- name: 'roo',
174
- friendlyName: 'Roo',
175
- paths: osSpecificPaths['roo']
176
- },
177
- 'intellij-github-copilot': {
178
- name: 'intellij-github-copilot',
179
- friendlyName: 'IntelliJ GitHub Copilot',
180
- paths: osSpecificPaths['intellij-github-copilot']
181
- },
182
- junie: {
183
- name: 'junie',
184
- friendlyName: 'IntelliJ Junie',
185
- paths: osSpecificPaths['junie']
186
- },
187
- zed: {
188
- name: 'zed',
189
- friendlyName: 'Zed',
190
- paths: osSpecificPaths['zed']
191
- }
192
- }
6
+ private mcpConfigService: MCPConfigService
193
7
 
194
- constructor (mcpFilePathGroups?: MCPFilePathGroupsRecord) {
195
- this.mcpFilePathGroups = mcpFilePathGroups || this.mcpFilePathGroups
8
+ constructor () {
9
+ this.mcpConfigService = new MCPConfigService()
196
10
  }
197
11
 
12
+ /**
13
+ * Find and process all MCP configuration files
14
+ */
198
15
  async findFiles (): Promise<MCPFileGroupsResultRecord> {
199
- const mcpFilesPathsData: MCPFileGroupsResultRecord = {}
200
-
201
- for (const groupName of Object.keys(this.mcpFilePathGroups)) {
202
- const clientsGroup = this.mcpFilePathGroups[groupName]
203
- mcpFilesPathsData[groupName] = {
204
- name: clientsGroup.name,
205
- friendlyName: clientsGroup.friendlyName,
206
- paths: [],
207
- stats: {}
208
- }
209
-
210
- const uniqueFilePaths = new Set<string>()
211
-
212
- for (const filePathData of clientsGroup.paths) {
213
- const resolvedPath: string = filePathData.filePath.replace('~', process.env.HOME || '')
214
- const absolutePath: string = path.resolve(resolvedPath)
215
- if (uniqueFilePaths.has(absolutePath)) {
216
- continue
217
- }
218
- uniqueFilePaths.add(absolutePath)
219
-
220
- try {
221
- await fs.access(resolvedPath)
222
-
223
- const MCPConfigLinter = new MCPConfigLinterService(resolvedPath)
224
- const parsable = await MCPConfigLinter.isValidSyntax()
225
- filePathData.parsable = parsable
16
+ try {
17
+ // Get MCP file groups with basic server information
18
+ const mcpFilesPathsData = await this.mcpConfigService.getMCPFileGroups()
19
+
20
+ // Process each group to add server status information
21
+ for (const groupName of Object.keys(mcpFilesPathsData)) {
22
+ const group = mcpFilesPathsData[groupName]
23
+
24
+ for (const filePathData of group.paths) {
25
+ if (filePathData.servers && filePathData.servers.length > 0) {
26
+ // Update server status for each server in this file
27
+ for (const server of filePathData.servers) {
28
+ const serverConfig = {
29
+ name: server.name,
30
+ command: server.command,
31
+ args: server.args,
32
+ transport: server.transport, // transport is always populated from type in the data layer
33
+ type: server.type,
34
+ env: server.env
35
+ }
226
36
 
227
- // @TODO if file isn't parsable we should skip the following logic here
228
- const mcpServersData: MCPServerInfo[] = []
229
- const mcpServersFromConfig = await MCPConfigLinter.getMCPServers()
230
- // let's iterate over the mcpServer Record and access the server objects
231
- for (const serverName of Object.keys(mcpServersFromConfig)) {
232
- const serverConfigRaw = mcpServersFromConfig[serverName] as any
233
- const serverConfig = {
234
- name: serverName,
235
- command: serverConfigRaw.command || '',
236
- args: serverConfigRaw.args,
237
- url: serverConfigRaw.url,
238
- transport: serverConfigRaw.transport,
239
- type: serverConfigRaw.type,
240
- env: serverConfigRaw.env
241
- }
242
- const MCPServerManager = new MCPServerManagerService(serverConfig)
37
+ const serverManager = new MCPServerManagerService(serverConfig)
38
+ const processDetection = serverManager.isRunning()
243
39
 
244
- const mcpServerProcessDetection = MCPServerManager.isRunning()
245
- let mcpServerProcess = false
246
- if (mcpServerProcessDetection) {
247
- if (typeof mcpServerProcessDetection === 'object' && mcpServerProcessDetection.estimatedProduct === clientsGroup.name) {
248
- mcpServerProcess = true
40
+ // Determine if the server is running
41
+ let isRunning = false
42
+ if (processDetection) {
43
+ if (typeof processDetection === 'object' && processDetection.estimatedProduct === group.name) {
44
+ isRunning = true
45
+ }
249
46
  }
250
- }
251
47
 
252
- mcpServersData.push({
253
- name: MCPServerManager.getName(),
254
- command: MCPServerManager.getCmd(),
255
- args: MCPServerManager.getArgs(),
256
- source: MCPServerManager.getSource(),
257
- transport: MCPServerManager.getTransport(),
258
- env: MCPServerManager.getEnv(),
259
- status: mcpServerProcess ? 'running' : 'stopped'
260
- })
48
+ server.status = isRunning ? 'running' : 'stopped'
49
+ }
261
50
  }
262
-
263
- filePathData.servers = mcpServersData
264
-
265
- mcpFilesPathsData[groupName]['stats']['serversCount'] = await MCPConfigLinter.countMCPServers()
266
- mcpFilesPathsData[groupName].paths.push(filePathData)
267
- } catch (error) {
268
- // File does not exist, continue to next
269
51
  }
270
52
  }
53
+
54
+ return mcpFilesPathsData
55
+ } catch (error) {
56
+ throw new Error(`Failed to find MCP files: ${error instanceof Error ? error.message : 'Unknown error'}`)
271
57
  }
58
+ }
272
59
 
273
- return mcpFilesPathsData
60
+ /**
61
+ * Get MCP configuration service instance for advanced operations
62
+ */
63
+ getMCPConfigService (): MCPConfigService {
64
+ return this.mcpConfigService
274
65
  }
275
66
  }
@@ -0,0 +1,166 @@
1
+ export class CredentialDetectionService {
2
+ /**
3
+ * Credential patterns grouped by risk level for easier maintenance
4
+ */
5
+ private static readonly CREDENTIAL_PATTERNS = {
6
+ high: [
7
+ // API Keys and Tokens
8
+ /api[_-]?key/i,
9
+ /api[_-]?token/i,
10
+ /access[_-]?token/i,
11
+ /secret[_-]?key/i,
12
+ /private[_-]?key/i,
13
+
14
+ // Authentication Tokens
15
+ /auth[_-]?token/i,
16
+ /bearer[_-]?token/i,
17
+ /jwt[_-]?token/i,
18
+ /oauth[_-]?token/i,
19
+
20
+ // Passwords
21
+ /password/i,
22
+ /passwd/i,
23
+ /pwd/i,
24
+
25
+ // Credentials
26
+ /credential/i,
27
+ /creds/i,
28
+
29
+ // Specific service patterns
30
+ /openai[_-]?api[_-]?key/i,
31
+ /anthropic[_-]?api[_-]?key/i,
32
+ /firecrawl[_-]?api[_-]?key/i,
33
+ /github[_-]?token/i,
34
+ /gitlab[_-]?token/i,
35
+ /bitbucket[_-]?token/i,
36
+
37
+ // Database passwords
38
+ /db[_-]?password/i,
39
+ /database[_-]?password/i,
40
+ /redis[_-]?password/i,
41
+ /postgres[_-]?password/i,
42
+ /mysql[_-]?password/i,
43
+
44
+ // Cloud services
45
+ /aws[_-]?secret[_-]?access[_-]?key/i,
46
+ /aws[_-]?access[_-]?key[_-]?id/i,
47
+ /azure[_-]?key/i,
48
+ /gcp[_-]?key/i,
49
+ /google[_-]?api[_-]?key/i,
50
+ /gemini[_-]?api[_-]?key/i,
51
+ /claude[_-]?api[_-]?key/i
52
+ ],
53
+ low: [
54
+ // Organization and Account IDs
55
+ /org[_-]?id/i,
56
+ /organization[_-]?id/i,
57
+ /account[_-]?id/i,
58
+ /user[_-]?id/i,
59
+ /openai[_-]?org[_-]?id/i
60
+ ]
61
+ }
62
+
63
+ /**
64
+ * Check if an environment variable name suggests it might contain credentials
65
+ */
66
+ static isPotentialCredential (envVarName: string): boolean {
67
+ return this.CREDENTIAL_PATTERNS.high.some(pattern => pattern.test(envVarName)) ||
68
+ this.CREDENTIAL_PATTERNS.low.some(pattern => pattern.test(envVarName))
69
+ }
70
+
71
+ /**
72
+ * Analyze environment variables and return credential detection results
73
+ */
74
+ static analyzeEnvironmentVariables (env: Record<string, string> | undefined): CredentialAnalysisResult {
75
+ if (!env || typeof env !== 'object') {
76
+ return {
77
+ hasCredentials: false,
78
+ credentialVars: [],
79
+ riskLevel: 'none'
80
+ }
81
+ }
82
+
83
+ const credentialVars: CredentialVariable[] = []
84
+
85
+ for (const [name, value] of Object.entries(env)) {
86
+ if (this.isPotentialCredential(name)) {
87
+ credentialVars.push({
88
+ name,
89
+ value: this.maskValue(value),
90
+ riskLevel: this.assessRiskLevel(name)
91
+ })
92
+ }
93
+ }
94
+
95
+ const hasCredentials = credentialVars.length > 0
96
+ const riskLevel = this.calculateOverallRiskLevel(credentialVars)
97
+
98
+ return {
99
+ hasCredentials,
100
+ credentialVars,
101
+ riskLevel
102
+ }
103
+ }
104
+
105
+ /**
106
+ * Mask sensitive values for display (show only first and last character)
107
+ */
108
+ private static maskValue (value: string): string {
109
+ if (!value || value.length <= 2) {
110
+ return value
111
+ }
112
+
113
+ const first = value.charAt(0)
114
+ const last = value.charAt(value.length - 1)
115
+ const maskedLength = Math.min(value.length - 2, 8) // Show max 8 asterisks
116
+
117
+ return `${first}${'*'.repeat(maskedLength)}${last}`
118
+ }
119
+
120
+ /**
121
+ * Assess risk level for a specific credential variable
122
+ */
123
+ private static assessRiskLevel (name: string): 'low' | 'high' {
124
+ // Check if it matches any high-risk patterns
125
+ if (this.CREDENTIAL_PATTERNS.high.some(pattern => pattern.test(name))) {
126
+ return 'high'
127
+ }
128
+
129
+ // If it matches low-risk patterns, it's low risk
130
+ if (this.CREDENTIAL_PATTERNS.low.some(pattern => pattern.test(name))) {
131
+ return 'low'
132
+ }
133
+
134
+ // Default to high risk for any other credential-like variables
135
+ return 'high'
136
+ }
137
+
138
+ /**
139
+ * Calculate overall risk level based on all credential variables
140
+ */
141
+ private static calculateOverallRiskLevel (credentialVars: CredentialVariable[]): 'none' | 'low' | 'high' {
142
+ if (credentialVars.length === 0) {
143
+ return 'none'
144
+ }
145
+
146
+ const hasHighRisk = credentialVars.some(v => v.riskLevel === 'high')
147
+
148
+ if (hasHighRisk) {
149
+ return 'high'
150
+ }
151
+
152
+ return 'low'
153
+ }
154
+ }
155
+
156
+ export interface CredentialVariable {
157
+ name: string
158
+ value: string
159
+ riskLevel: 'low' | 'high'
160
+ }
161
+
162
+ export interface CredentialAnalysisResult {
163
+ hasCredentials: boolean
164
+ credentialVars: CredentialVariable[]
165
+ riskLevel: 'none' | 'low' | 'high'
166
+ }