From d1bb77c42b47812577dd85e3677d903babc66cf3 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Tue, 10 Mar 2026 12:08:25 -0600 Subject: [PATCH] fix: silently hide MCP UI on errors (#10660) fix: silently hide MCP UI on errors instead of showing broken content When an MCP UI app can't handle a tool's data (e.g. server tags non-UI tools with ui/resourceUri), hide the UI rather than showing confusing error messages. Changes: - Return null on error instead of rendering red error box - Wrap sendToolInput/sendToolResult in try/catch - Hide UI when MCP app reports error/critical via bridge logging --- .../pages/gui/ToolCallDiv/MCPAppRenderer.tsx | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/gui/src/pages/gui/ToolCallDiv/MCPAppRenderer.tsx b/gui/src/pages/gui/ToolCallDiv/MCPAppRenderer.tsx index f1f6c2745..b5f3ac791 100644 --- a/gui/src/pages/gui/ToolCallDiv/MCPAppRenderer.tsx +++ b/gui/src/pages/gui/ToolCallDiv/MCPAppRenderer.tsx @@ -254,6 +254,12 @@ export function McpAppRenderer({ `[MCP App${params.logger ? ` - ${params.logger}` : ""}]`, params.data, ); + + // If the MCP app reports an error, hide the UI rather than + // showing broken/confusing content + if (params.level === "error" || params.level === "critical") { + setError(new Error(String(params.data))); + } }; bridge.onupdatemodelcontext = async () => { @@ -297,18 +303,28 @@ export function McpAppRenderer({ useEffect(() => { const bridge = appBridgeRef.current; if (!bridge || !isInitialized || !toolInput) return; - bridge.sendToolInput({ arguments: toolInput }); + try { + bridge.sendToolInput({ arguments: toolInput }); + } catch (err) { + console.warn("[McpAppRenderer] Failed to send tool input:", err); + setError(err instanceof Error ? err : new Error(String(err))); + } }, [isInitialized, toolInput]); useEffect(() => { const bridge = appBridgeRef.current; if (!bridge || !isInitialized || !toolResult) return; - bridge.sendToolResult({ - content: toolResult.map((o) => ({ - type: "text" as const, - text: o.content, - })), - }); + try { + bridge.sendToolResult({ + content: toolResult.map((o) => ({ + type: "text" as const, + text: o.content, + })), + }); + } catch (err) { + console.warn("[McpAppRenderer] Failed to send tool result:", err); + setError(err instanceof Error ? err : new Error(String(err))); + } }, [isInitialized, toolResult]); if (!toolCallState.mcpUiState || !html) { @@ -316,12 +332,7 @@ export function McpAppRenderer({ } if (error) { - return ( -
-

MCP UI Error

-

{error.message}

-
- ); + return null; } const cspMetaContent = buildCspMetaContent(csp);