diff --git a/src/main/services/MCPService.ts b/src/main/services/MCPService.ts index 49e648336c..2bdb31d228 100644 --- a/src/main/services/MCPService.ts +++ b/src/main/services/MCPService.ts @@ -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 => { 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()