ls-mcp 1.9.1 → 1.11.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/README.md +29 -3
- package/dist/bin/cli.cjs +952 -289
- package/dist/bin/cli.mjs +935 -272
- package/dist/main.cjs +814 -263
- package/dist/main.d.cts +82 -14
- package/dist/main.d.ts +82 -14
- package/dist/main.mjs +814 -265
- package/package.json +3 -1
- package/src/bin/cli.ts +37 -5
- package/src/components/credential-warning.ts +37 -0
- package/src/components/summary.ts +57 -0
- package/src/main.ts +50 -140
- package/src/services/credential-detection-service.ts +166 -0
- package/src/services/directory-bubble-service.ts +82 -0
- package/src/services/mcp-config-linter-service.ts +13 -74
- package/src/services/mcp-config-parser.ts +234 -0
- package/src/services/mcp-config-service.ts +304 -0
- package/src/services/mcp-path-registry.ts +164 -0
- package/src/services/mcp-server-manager-service.ts +5 -4
- package/src/services/render-service.ts +46 -2
- package/src/types/mcp-config-service.types.ts +76 -0
- package/src/types.ts +1 -1
- package/src/utils/url-utils.ts +24 -0
- package/src/utils/os-paths.ts +0 -102
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ls-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.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,157 +1,67 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import { MCPConfigLinterService } from './services/mcp-config-linter-service.ts'
|
|
5
|
-
import { MCPServerManagerService } from './services/mcp-server-manager-service.ts'
|
|
6
|
-
import { getWindowsPaths, getDarwinPaths } from './utils/os-paths.ts'
|
|
7
|
-
import { type MCPServerInfo, type MCPFilePath, type MCPFilePathGroupsRecord, type MCPFileGroupsResultRecord } from './types.ts'
|
|
8
|
-
|
|
9
|
-
let osSpecificPaths: { [key: string]: MCPFilePath[] } = {}
|
|
10
|
-
|
|
11
|
-
if (platform() === 'win32') {
|
|
12
|
-
osSpecificPaths = getWindowsPaths()
|
|
13
|
-
} else {
|
|
14
|
-
osSpecificPaths = getDarwinPaths()
|
|
15
|
-
}
|
|
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'
|
|
16
4
|
|
|
17
5
|
export class MCPFiles {
|
|
18
|
-
private
|
|
19
|
-
claude: {
|
|
20
|
-
name: 'claude-desktop',
|
|
21
|
-
friendlyName: 'Claude Desktop',
|
|
22
|
-
paths: osSpecificPaths['claude']
|
|
23
|
-
},
|
|
24
|
-
claude_code: {
|
|
25
|
-
name: 'claude-code',
|
|
26
|
-
friendlyName: 'Claude Code',
|
|
27
|
-
paths: osSpecificPaths['claude_code']
|
|
28
|
-
},
|
|
29
|
-
cursor: {
|
|
30
|
-
name: 'cursor',
|
|
31
|
-
friendlyName: 'Cursor',
|
|
32
|
-
paths: osSpecificPaths['cursor']
|
|
33
|
-
},
|
|
34
|
-
vscode: {
|
|
35
|
-
name: 'vscode',
|
|
36
|
-
friendlyName: 'VS Code',
|
|
37
|
-
paths: osSpecificPaths['vscode']
|
|
38
|
-
},
|
|
39
|
-
cline: {
|
|
40
|
-
name: 'cline',
|
|
41
|
-
friendlyName: 'Cline',
|
|
42
|
-
paths: osSpecificPaths['cline']
|
|
43
|
-
},
|
|
44
|
-
windsurf: {
|
|
45
|
-
name: 'windsurf',
|
|
46
|
-
friendlyName: 'Windsurf',
|
|
47
|
-
paths: osSpecificPaths['windsurf']
|
|
48
|
-
},
|
|
49
|
-
roo: {
|
|
50
|
-
name: 'roo',
|
|
51
|
-
friendlyName: 'Roo',
|
|
52
|
-
paths: osSpecificPaths['roo']
|
|
53
|
-
},
|
|
54
|
-
'intellij-github-copilot': {
|
|
55
|
-
name: 'intellij-github-copilot',
|
|
56
|
-
friendlyName: 'IntelliJ GitHub Copilot',
|
|
57
|
-
paths: osSpecificPaths['intellij-github-copilot']
|
|
58
|
-
},
|
|
59
|
-
junie: {
|
|
60
|
-
name: 'junie',
|
|
61
|
-
friendlyName: 'IntelliJ Junie',
|
|
62
|
-
paths: osSpecificPaths['junie']
|
|
63
|
-
},
|
|
64
|
-
zed: {
|
|
65
|
-
name: 'zed',
|
|
66
|
-
friendlyName: 'Zed',
|
|
67
|
-
paths: osSpecificPaths['zed']
|
|
68
|
-
},
|
|
69
|
-
gemini: {
|
|
70
|
-
name: 'gemini-cli',
|
|
71
|
-
friendlyName: 'Gemini CLI',
|
|
72
|
-
paths: osSpecificPaths.gemini
|
|
73
|
-
}
|
|
74
|
-
}
|
|
6
|
+
private mcpConfigService: MCPConfigService
|
|
75
7
|
|
|
76
|
-
constructor (
|
|
77
|
-
|
|
8
|
+
constructor () {
|
|
9
|
+
// Enable directory bubbling for better DX when running from nested directories
|
|
10
|
+
this.mcpConfigService = new MCPConfigService({ enableDirectoryBubbling: true })
|
|
78
11
|
}
|
|
79
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Find and process all MCP configuration files
|
|
15
|
+
*/
|
|
80
16
|
async findFiles (): Promise<MCPFileGroupsResultRecord> {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
try {
|
|
103
|
-
await fs.access(resolvedPath)
|
|
17
|
+
try {
|
|
18
|
+
// Get MCP file groups with basic server information
|
|
19
|
+
const mcpFilesPathsData = await this.mcpConfigService.getMCPFileGroups()
|
|
20
|
+
|
|
21
|
+
// Process each group to add server status information
|
|
22
|
+
for (const groupName of Object.keys(mcpFilesPathsData)) {
|
|
23
|
+
const group = mcpFilesPathsData[groupName]
|
|
24
|
+
|
|
25
|
+
for (const filePathData of group.paths) {
|
|
26
|
+
if (filePathData.servers && filePathData.servers.length > 0) {
|
|
27
|
+
// Update server status for each server in this file
|
|
28
|
+
for (const server of filePathData.servers) {
|
|
29
|
+
const serverConfig = {
|
|
30
|
+
name: server.name,
|
|
31
|
+
command: server.command,
|
|
32
|
+
args: server.args,
|
|
33
|
+
transport: server.transport, // transport is always populated from type in the data layer
|
|
34
|
+
type: server.type,
|
|
35
|
+
env: server.env
|
|
36
|
+
}
|
|
104
37
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
filePathData.parsable = parsable
|
|
38
|
+
const serverManager = new MCPServerManagerService(serverConfig)
|
|
39
|
+
const processDetection = serverManager.isRunning()
|
|
108
40
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const serverConfig = {
|
|
116
|
-
name: serverName,
|
|
117
|
-
command: serverConfigRaw.command || '',
|
|
118
|
-
args: serverConfigRaw.args,
|
|
119
|
-
url: serverConfigRaw.url,
|
|
120
|
-
transport: serverConfigRaw.transport,
|
|
121
|
-
type: serverConfigRaw.type,
|
|
122
|
-
env: serverConfigRaw.env
|
|
123
|
-
}
|
|
124
|
-
const MCPServerManager = new MCPServerManagerService(serverConfig)
|
|
125
|
-
|
|
126
|
-
const mcpServerProcessDetection = MCPServerManager.isRunning()
|
|
127
|
-
let mcpServerProcess = false
|
|
128
|
-
if (mcpServerProcessDetection) {
|
|
129
|
-
if (typeof mcpServerProcessDetection === 'object' && mcpServerProcessDetection.estimatedProduct === clientsGroup.name) {
|
|
130
|
-
mcpServerProcess = true
|
|
41
|
+
// Determine if the server is running
|
|
42
|
+
let isRunning = false
|
|
43
|
+
if (processDetection) {
|
|
44
|
+
if (typeof processDetection === 'object' && processDetection.estimatedProduct === group.name) {
|
|
45
|
+
isRunning = true
|
|
46
|
+
}
|
|
131
47
|
}
|
|
132
|
-
}
|
|
133
48
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
command: MCPServerManager.getCmd(),
|
|
137
|
-
args: MCPServerManager.getArgs(),
|
|
138
|
-
source: MCPServerManager.getSource(),
|
|
139
|
-
transport: MCPServerManager.getTransport(),
|
|
140
|
-
env: MCPServerManager.getEnv(),
|
|
141
|
-
status: mcpServerProcess ? 'running' : 'stopped'
|
|
142
|
-
})
|
|
49
|
+
server.status = isRunning ? 'running' : 'stopped'
|
|
50
|
+
}
|
|
143
51
|
}
|
|
144
|
-
|
|
145
|
-
filePathData.servers = mcpServersData
|
|
146
|
-
|
|
147
|
-
mcpFilesPathsData[groupName]['stats']['serversCount'] = await MCPConfigLinter.countMCPServers()
|
|
148
|
-
mcpFilesPathsData[groupName].paths.push(filePathData)
|
|
149
|
-
} catch (error) {
|
|
150
|
-
// File does not exist, continue to next
|
|
151
52
|
}
|
|
152
53
|
}
|
|
54
|
+
|
|
55
|
+
return mcpFilesPathsData
|
|
56
|
+
} catch (error) {
|
|
57
|
+
throw new Error(`Failed to find MCP files: ${error instanceof Error ? error.message : 'Unknown error'}`)
|
|
153
58
|
}
|
|
59
|
+
}
|
|
154
60
|
|
|
155
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Get MCP configuration service instance for advanced operations
|
|
63
|
+
*/
|
|
64
|
+
getMCPConfigService (): MCPConfigService {
|
|
65
|
+
return this.mcpConfigService
|
|
156
66
|
}
|
|
157
67
|
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import fs from 'node:fs/promises'
|
|
3
|
+
import { homedir } from 'node:os'
|
|
4
|
+
|
|
5
|
+
export class DirectoryBubbleService {
|
|
6
|
+
/**
|
|
7
|
+
* Find a local MCP config file by bubbling up the directory tree
|
|
8
|
+
* @param localPath - The relative path to search for (e.g., '.vscode/mcp.json')
|
|
9
|
+
* @param startDir - The directory to start searching from
|
|
10
|
+
* @returns The absolute path to the found config file, or null if not found
|
|
11
|
+
*/
|
|
12
|
+
async findLocalConfigInParentDirectories (
|
|
13
|
+
localPath: string,
|
|
14
|
+
startDir: string
|
|
15
|
+
): Promise<string | null> {
|
|
16
|
+
try {
|
|
17
|
+
let currentDir = path.resolve(startDir)
|
|
18
|
+
const homeDir = homedir()
|
|
19
|
+
const rootDir = '/'
|
|
20
|
+
let iterationCount = 0
|
|
21
|
+
const maxIterations = 100 // Safety limit to prevent infinite loops
|
|
22
|
+
|
|
23
|
+
// Check the start directory first
|
|
24
|
+
const startDirResult = await this.checkDirectoryForConfig(currentDir, localPath)
|
|
25
|
+
if (startDirResult) {
|
|
26
|
+
return path.join(currentDir, localPath)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Bubble up directory tree until we reach home directory or root
|
|
30
|
+
while (currentDir !== homeDir && currentDir !== rootDir && iterationCount < maxIterations) {
|
|
31
|
+
const parentDir = this.getParentDirectory(currentDir)
|
|
32
|
+
if (!parentDir || parentDir === currentDir) {
|
|
33
|
+
break
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Additional safety check: ensure we're actually moving up the tree
|
|
37
|
+
if (parentDir === currentDir || parentDir.length >= currentDir.length) {
|
|
38
|
+
break
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
currentDir = parentDir
|
|
42
|
+
iterationCount++
|
|
43
|
+
|
|
44
|
+
const found = await this.checkDirectoryForConfig(currentDir, localPath)
|
|
45
|
+
if (found) {
|
|
46
|
+
return path.join(currentDir, localPath)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return null
|
|
51
|
+
} catch (error) {
|
|
52
|
+
// Silently catch errors as per requirements
|
|
53
|
+
return null
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Check if a config file exists in the specified directory
|
|
59
|
+
* @param dir - The directory to check
|
|
60
|
+
* @param configPath - The relative path to the config file
|
|
61
|
+
* @returns True if the config file exists and is accessible
|
|
62
|
+
*/
|
|
63
|
+
private async checkDirectoryForConfig (dir: string, configPath: string): Promise<boolean> {
|
|
64
|
+
try {
|
|
65
|
+
const fullPath = path.join(dir, configPath)
|
|
66
|
+
await fs.access(fullPath)
|
|
67
|
+
return true
|
|
68
|
+
} catch (error) {
|
|
69
|
+
return false
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Get the parent directory of the specified directory
|
|
75
|
+
* @param dir - The directory to get the parent of
|
|
76
|
+
* @returns The parent directory path, or null if already at root
|
|
77
|
+
*/
|
|
78
|
+
private getParentDirectory (dir: string): string | null {
|
|
79
|
+
const parent = path.dirname(dir)
|
|
80
|
+
return parent === dir ? null : parent
|
|
81
|
+
}
|
|
82
|
+
}
|