From 03633d1156320e4cc820a698db5674aacf946b9d Mon Sep 17 00:00:00 2001 From: Roo Code Date: Wed, 3 Sep 2025 21:05:49 +0000 Subject: [PATCH] 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 --- src/services/mcp/McpHub.ts | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/services/mcp/McpHub.ts b/src/services/mcp/McpHub.ts index 6ec5b839e8..8f40c35142 100644 --- a/src/services/mcp/McpHub.ts +++ b/src/services/mcp/McpHub.ts @@ -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() }