ls-mcp 1.9.1 → 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/README.md +12 -0
- package/dist/bin/cli.cjs +841 -289
- package/dist/bin/cli.mjs +823 -271
- package/dist/main.cjs +703 -263
- package/dist/main.d.cts +76 -14
- package/dist/main.d.ts +76 -14
- package/dist/main.mjs +702 -264
- 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 +49 -140
- package/src/services/credential-detection-service.ts +166 -0
- package/src/services/mcp-config-linter-service.ts +13 -74
- package/src/services/mcp-config-parser.ts +233 -0
- package/src/services/mcp-config-service.ts +267 -0
- package/src/services/mcp-path-registry.ts +164 -0
- package/src/services/mcp-server-manager-service.ts +3 -3
- package/src/services/render-service.ts +46 -2
- package/src/types/mcp-config-service.types.ts +75 -0
- package/src/types.ts +1 -1
- 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.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,157 +1,66 @@
|
|
|
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
|
-
this.
|
|
8
|
+
constructor () {
|
|
9
|
+
this.mcpConfigService = new MCPConfigService()
|
|
78
10
|
}
|
|
79
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Find and process all MCP configuration files
|
|
14
|
+
*/
|
|
80
15
|
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)
|
|
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
|
+
}
|
|
104
36
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
filePathData.parsable = parsable
|
|
37
|
+
const serverManager = new MCPServerManagerService(serverConfig)
|
|
38
|
+
const processDetection = serverManager.isRunning()
|
|
108
39
|
|
|
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
|
|
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
|
+
}
|
|
131
46
|
}
|
|
132
|
-
}
|
|
133
47
|
|
|
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
|
-
})
|
|
48
|
+
server.status = isRunning ? 'running' : 'stopped'
|
|
49
|
+
}
|
|
143
50
|
}
|
|
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
51
|
}
|
|
152
52
|
}
|
|
53
|
+
|
|
54
|
+
return mcpFilesPathsData
|
|
55
|
+
} catch (error) {
|
|
56
|
+
throw new Error(`Failed to find MCP files: ${error instanceof Error ? error.message : 'Unknown error'}`)
|
|
153
57
|
}
|
|
58
|
+
}
|
|
154
59
|
|
|
155
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Get MCP configuration service instance for advanced operations
|
|
62
|
+
*/
|
|
63
|
+
getMCPConfigService (): MCPConfigService {
|
|
64
|
+
return this.mcpConfigService
|
|
156
65
|
}
|
|
157
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
|
+
}
|
|
@@ -1,95 +1,34 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { parse } from 'jsonc-parser'
|
|
1
|
+
import { MCPConfigParser } from './mcp-config-parser.js'
|
|
3
2
|
|
|
4
3
|
export class MCPConfigLinterService {
|
|
5
|
-
private
|
|
6
|
-
private fileContents: string | null = null
|
|
7
|
-
private parsed: boolean = false
|
|
8
|
-
private valid: boolean = false
|
|
9
|
-
private fileContentsData: any | null = null
|
|
4
|
+
private parser: MCPConfigParser
|
|
10
5
|
|
|
11
6
|
constructor (filePath: string) {
|
|
12
|
-
this.
|
|
7
|
+
this.parser = new MCPConfigParser(filePath)
|
|
13
8
|
}
|
|
14
9
|
|
|
15
10
|
async parseFile (): Promise<void> {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
this.parsed = true
|
|
20
|
-
|
|
21
|
-
const fileContent = await this.getFileContent()
|
|
22
|
-
|
|
23
|
-
// @TODO this should also support YAML files and other formats
|
|
24
|
-
try {
|
|
25
|
-
this.fileContentsData = JSON.parse(fileContent)
|
|
26
|
-
if (typeof this.fileContentsData === 'object') {
|
|
27
|
-
this.valid = true
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
} catch (e) {
|
|
31
|
-
// ignore
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
this.fileContentsData = parse(fileContent)
|
|
36
|
-
if (typeof this.fileContentsData === 'object') {
|
|
37
|
-
this.valid = true
|
|
38
|
-
}
|
|
39
|
-
} catch (error) {
|
|
40
|
-
// ignore
|
|
41
|
-
}
|
|
11
|
+
// This method is kept for backward compatibility but now delegates to the parser
|
|
12
|
+
await this.parser.parseConfigFile()
|
|
42
13
|
}
|
|
43
14
|
|
|
44
15
|
async isValidSyntax (): Promise<boolean> {
|
|
45
|
-
|
|
46
|
-
await this.parseFile()
|
|
47
|
-
return this.valid
|
|
48
|
-
} catch (error) {
|
|
49
|
-
return false
|
|
50
|
-
}
|
|
16
|
+
return await this.parser.isValidSyntax()
|
|
51
17
|
}
|
|
52
18
|
|
|
53
19
|
async countMCPServers (): Promise<number> {
|
|
54
|
-
|
|
55
|
-
const mcpServers = await this.getMCPServers()
|
|
56
|
-
return Object.keys(mcpServers).length
|
|
57
|
-
} catch (error) {
|
|
58
|
-
return 0
|
|
59
|
-
}
|
|
20
|
+
return await this.parser.countMCPServers()
|
|
60
21
|
}
|
|
61
22
|
|
|
62
23
|
async getMCPServers (): Promise<Record<string, object>> {
|
|
63
|
-
await this.
|
|
64
|
-
|
|
65
|
-
// VS Code uses `servers`
|
|
66
|
-
if (this.fileContentsData?.servers) {
|
|
67
|
-
return this.fileContentsData.servers
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// VS Code global settings.json file uses `mcp` -> `servers`
|
|
71
|
-
if (this.fileContentsData?.mcp?.servers) {
|
|
72
|
-
return this.fileContentsData.mcp.servers
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Claude and Cursor use the `mcpServers` key
|
|
76
|
-
if (this.fileContentsData?.mcpServers) {
|
|
77
|
-
return this.fileContentsData.mcpServers
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Zed uses `context_servers` key
|
|
81
|
-
if (this.fileContentsData?.context_servers) {
|
|
82
|
-
return this.fileContentsData.context_servers
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return {}
|
|
24
|
+
const configData = await this.parser.parseConfigFile()
|
|
25
|
+
return configData.servers
|
|
86
26
|
}
|
|
87
27
|
|
|
88
28
|
async getFileContent (): Promise<string> {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return this.fileContents
|
|
29
|
+
// This method is kept for backward compatibility but the parser handles file reading internally
|
|
30
|
+
// We'll need to access the parser's internal file content
|
|
31
|
+
const configData = await this.parser.parseConfigFile()
|
|
32
|
+
return JSON.stringify(configData.raw, null, 2)
|
|
94
33
|
}
|
|
95
34
|
}
|