Skip to content

Commit 03633d1

Browse files
committed
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
1 parent c25cfde commit 03633d1

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/services/mcp/McpHub.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,10 @@ export class McpHub {
257257
* @param error The error object
258258
*/
259259
private showErrorMessage(message: string, error: unknown): void {
260-
console.error(`${message}:`, error)
260+
const errorMessage = error instanceof Error ? error.message : String(error)
261+
const fullMessage = `${message}: ${errorMessage}`
262+
console.error(fullMessage)
263+
vscode.window.showErrorMessage(fullMessage)
261264
}
262265

263266
public setupWorkspaceFoldersWatcher(): void {
@@ -692,11 +695,14 @@ export class McpHub {
692695

693696
// Set up stdio specific error handling
694697
transport.onerror = async (error) => {
695-
console.error(`Transport error for "${name}":`, error)
698+
const errorMessage = error instanceof Error ? error.message : `${error}`
699+
const fullMessage = `Transport error for MCP server "${name}": ${errorMessage}`
700+
console.error(fullMessage)
701+
vscode.window.showErrorMessage(fullMessage)
696702
const connection = this.findConnection(name, source)
697703
if (connection) {
698704
connection.server.status = "disconnected"
699-
this.appendErrorMessage(connection, error instanceof Error ? error.message : `${error}`)
705+
this.appendErrorMessage(connection, errorMessage)
700706
}
701707
await this.notifyWebviewOfServerChanges()
702708
}
@@ -747,11 +753,14 @@ export class McpHub {
747753

748754
// Set up Streamable HTTP specific error handling
749755
transport.onerror = async (error) => {
750-
console.error(`Transport error for "${name}" (streamable-http):`, error)
756+
const errorMessage = error instanceof Error ? error.message : `${error}`
757+
const fullMessage = `Transport error for MCP server "${name}" (streamable-http): ${errorMessage}`
758+
console.error(fullMessage)
759+
vscode.window.showErrorMessage(fullMessage)
751760
const connection = this.findConnection(name, source)
752761
if (connection) {
753762
connection.server.status = "disconnected"
754-
this.appendErrorMessage(connection, error instanceof Error ? error.message : `${error}`)
763+
this.appendErrorMessage(connection, errorMessage)
755764
}
756765
await this.notifyWebviewOfServerChanges()
757766
}
@@ -790,11 +799,14 @@ export class McpHub {
790799

791800
// Set up SSE specific error handling
792801
transport.onerror = async (error) => {
793-
console.error(`Transport error for "${name}":`, error)
802+
const errorMessage = error instanceof Error ? error.message : `${error}`
803+
const fullMessage = `Transport error for MCP server "${name}" (SSE): ${errorMessage}`
804+
console.error(fullMessage)
805+
vscode.window.showErrorMessage(fullMessage)
794806
const connection = this.findConnection(name, source)
795807
if (connection) {
796808
connection.server.status = "disconnected"
797-
this.appendErrorMessage(connection, error instanceof Error ? error.message : `${error}`)
809+
this.appendErrorMessage(connection, errorMessage)
798810
}
799811
await this.notifyWebviewOfServerChanges()
800812
}

0 commit comments

Comments
 (0)