feat(MCPService): add method to find PowerShell executable path (#5393)

- Implemented `findPowerShellExecutable` to determine the correct PowerShell executable path on Windows.
- Updated `getSystemPath` to utilize the new method for improved path retrieval.
This commit is contained in:
beyondkmp 2025-04-27 14:25:37 +08:00 committed by GitHub
parent 44299a8f5b
commit e894ab0c4c

View File

@ -567,13 +567,26 @@ class McpService {
return await cachedGetResource(server, uri)
}
private findPowerShellExecutable() {
const psPath = 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe' // Standard WinPS path
const pwshPath = 'C:\\Program Files\\PowerShell\\7\\pwsh.exe'
if (fs.existsSync(psPath)) {
return psPath
}
if (fs.existsSync(pwshPath)) {
return pwshPath
}
return 'powershell.exe'
}
private getSystemPath = memoize(async (): Promise<string> => {
return new Promise((resolve, reject) => {
let command: string
let shell: string
if (process.platform === 'win32') {
shell = 'powershell.exe'
shell = this.findPowerShellExecutable()
command = '$env:PATH'
} else {
// 尝试获取当前用户的默认 shell
@ -625,6 +638,10 @@ class McpService {
console.error('Error getting PATH:', data.toString())
})
child.on('error', (error: Error) => {
reject(new Error(`Failed to get system PATH, ${error.message}`))
})
child.on('close', (code: number) => {
if (code === 0) {
const trimmedPath = path.trim()