From a81e6725c8888fd0ebca2e91553e9819e38a78f1 Mon Sep 17 00:00:00 2001 From: Areo-Joe <1047726016@qq.com> Date: Mon, 19 May 2025 14:17:49 +0800 Subject: [PATCH] fix: add error handling for stderr messages in stdio transport - Add catch handler for promise rejection when sending stderr content\n- Log both error and original stderr content when sending fails\n- Improve debugging capabilities for stdio transport errors --- server/src/index.ts | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/server/src/index.ts b/server/src/index.ts index c967b60c7..7f063a3aa 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -257,13 +257,23 @@ app.get("/stdio", async (req, res) => { (backingServerTransport as StdioClientTransport).stderr!.on( "data", (chunk) => { - webAppTransport.send({ - jsonrpc: "2.0", - method: "notifications/stderr", - params: { - content: chunk.toString(), - }, - }); + const content = chunk.toString(); + + webAppTransport + .send({ + jsonrpc: "2.0", + method: "notifications/stderr", + params: { + content, + }, + }) + .catch((error) => { + console.error( + "Error from inspector client when sending content from stdio transport's stderr:", + error, + ); + console.error("Origin content from stderr:", content); + }); }, );