From 6bc81c2a0e13202a4b5b9e0c446da4eda6a3b5b7 Mon Sep 17 00:00:00 2001 From: aheizi Date: Thu, 20 Mar 2025 21:12:36 +0800 Subject: [PATCH] fix mcp stderr log (#1830) --- src/services/mcp/McpHub.ts | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/services/mcp/McpHub.ts b/src/services/mcp/McpHub.ts index 2a99499a9d..8ca7429176 100644 --- a/src/services/mcp/McpHub.ts +++ b/src/services/mcp/McpHub.ts @@ -351,15 +351,22 @@ export class McpHub { const stderrStream = transport.stderr if (stderrStream) { stderrStream.on("data", async (data: Buffer) => { - const errorOutput = data.toString() - console.error(`Server "${name}" stderr:`, errorOutput) - const connection = this.connections.find((conn) => conn.server.name === name) - if (connection) { - // NOTE: we do not set server status to "disconnected" because stderr logs do not necessarily mean the server crashed or disconnected, it could just be informational. In fact when the server first starts up, it immediately logs " server running on stdio" to stderr. - this.appendErrorMessage(connection, errorOutput) - // Only need to update webview right away if it's already disconnected - if (connection.server.status === "disconnected") { - await this.notifyWebviewOfServerChanges() + const output = data.toString() + // Check if output contains INFO level log + const isInfoLog = /INFO/i.test(output) + + if (isInfoLog) { + // Log normal informational messages + console.log(`Server "${name}" info:`, output) + } else { + // Treat as error log + console.error(`Server "${name}" stderr:`, output) + const connection = this.connections.find((conn) => conn.server.name === name) + if (connection) { + this.appendErrorMessage(connection, output) + if (connection.server.status === "disconnected") { + await this.notifyWebviewOfServerChanges() + } } } })