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
This commit is contained in:
Dallin Romney 2026-03-10 12:08:25 -06:00 • committed by GitHub
parent f8df44777b
commit d1bb77c42b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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 (
<div className="rounded border border-red-500 bg-red-500/10 p-3 text-sm">
<p className="font-medium text-red-500">MCP UI Error</p>
<p className="text-red-400">{error.message}</p>
</div>
);
return null;
}
const cspMetaContent = buildCspMetaContent(csp);