From 3f15d962db55861f7dc85fc46f4f43c82a14f407 Mon Sep 17 00:00:00 2001 From: giulio-leone Date: Sat, 7 Mar 2026 17:26:22 +0100 Subject: [PATCH] fix: show error toast when streamable-http MCP connection fails When connecting to a streamable-http MCP server that is unreachable, the frontend showed a green 'MCP added!' success toast instead of an error message because the HTTP error was not thrown (fixes #2823). Throw ClientError on non-ok response. Check res.ok before attempting JSON parse so proxy HTML error pages don't cause a SyntaxError. Use data.detail as the message so the toast shows the actual error reason (e.g. 'Connection refused') rather than generic status text. --- frontend/src/api/index.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/frontend/src/api/index.ts b/frontend/src/api/index.ts index ab6c46b7dd..fab6291cbf 100644 --- a/frontend/src/api/index.ts +++ b/frontend/src/api/index.ts @@ -57,8 +57,18 @@ class ExtendedChainlitAPI extends ChainlitAPI { ...(headers ? { headers } : {}) }) }).then(async (res) => { + if (!res.ok) { + let detail: string | undefined; + try { + const data = await res.json(); + detail = data.detail; + } catch { + // Response body is not JSON (e.g. proxy HTML error page) + } + throw new ClientError(detail || res.statusText, res.status); + } const data = await res.json(); - return { success: res.ok, mcp: data.mcp, error: data.detail }; + return { success: true, mcp: data.mcp, error: undefined }; }); } }