fix: surface MCP server errors to UI with toast notifications

- Updated showErrorMessage() to display errors via vscode.window.showErrorMessage()
- Added UI error notifications for transport errors (stdio, SSE, streamable-http)
- Ensures users get visible feedback when MCP server connections fail
- Maintains console logging for debugging while adding user-facing notifications

Fixes #7639
This commit is contained in:
Roo Code 2025-09-03 21:05:49 +00:00
parent c25cfdeaef
commit 03633d1156

View file

@ -257,7 +257,10 @@ export class McpHub {
* @param error The error object
*/
private showErrorMessage(message: string, error: unknown): void {
console.error(`${message}:`, error)
const errorMessage = error instanceof Error ? error.message : String(error)
const fullMessage = `${message}: ${errorMessage}`
console.error(fullMessage)
vscode.window.showErrorMessage(fullMessage)
}
public setupWorkspaceFoldersWatcher(): void {
@ -692,11 +695,14 @@ export class McpHub {
// Set up stdio specific error handling
transport.onerror = async (error) => {
console.error(`Transport error for "${name}":`, error)
const errorMessage = error instanceof Error ? error.message : `${error}`
const fullMessage = `Transport error for MCP server "${name}": ${errorMessage}`
console.error(fullMessage)
vscode.window.showErrorMessage(fullMessage)
const connection = this.findConnection(name, source)
if (connection) {
connection.server.status = "disconnected"
this.appendErrorMessage(connection, error instanceof Error ? error.message : `${error}`)
this.appendErrorMessage(connection, errorMessage)
}
await this.notifyWebviewOfServerChanges()
}
@ -747,11 +753,14 @@ export class McpHub {
// Set up Streamable HTTP specific error handling
transport.onerror = async (error) => {
console.error(`Transport error for "${name}" (streamable-http):`, error)
const errorMessage = error instanceof Error ? error.message : `${error}`
const fullMessage = `Transport error for MCP server "${name}" (streamable-http): ${errorMessage}`
console.error(fullMessage)
vscode.window.showErrorMessage(fullMessage)
const connection = this.findConnection(name, source)
if (connection) {
connection.server.status = "disconnected"
this.appendErrorMessage(connection, error instanceof Error ? error.message : `${error}`)
this.appendErrorMessage(connection, errorMessage)
}
await this.notifyWebviewOfServerChanges()
}
@ -790,11 +799,14 @@ export class McpHub {
// Set up SSE specific error handling
transport.onerror = async (error) => {
console.error(`Transport error for "${name}":`, error)
const errorMessage = error instanceof Error ? error.message : `${error}`
const fullMessage = `Transport error for MCP server "${name}" (SSE): ${errorMessage}`
console.error(fullMessage)
vscode.window.showErrorMessage(fullMessage)
const connection = this.findConnection(name, source)
if (connection) {
connection.server.status = "disconnected"
this.appendErrorMessage(connection, error instanceof Error ? error.message : `${error}`)
this.appendErrorMessage(connection, errorMessage)
}
await this.notifyWebviewOfServerChanges()
}