Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(conversations): show tool links only when there is no widget, never images

oxoxDevd477b8c24e85
diff --git a/app/src/features/conversations/tools/mcpUi/McpUiBody.test.tsx b/app/src/features/conversations/tools/mcpUi/McpUiBody.test.tsx
index 4556fd21ba..ee831a26c8 100644
--- a/app/src/features/conversations/tools/mcpUi/McpUiBody.test.tsx
+++ b/app/src/features/conversations/tools/mcpUi/McpUiBody.test.tsx
@@ -3,7 +3,10 @@ import { describe, expect, it, vi } from 'vitest';
import { McpUiBody } from './McpUiBody';
-vi.mock('../../../../utils/tauriCommands/common', () => ({ isTauri: () => false }));
+const tauri = vi.hoisted(() => ({ value: false }));
+
+vi.mock('../../../../utils/tauriCommands/common', () => ({ isTauri: () => tauri.value }));
+vi.mock('./McpAppFrame', () => ({ McpAppFrame: () => <div data-testid="mcp-ui-frame" /> }));
describe('McpUiBody', () => {
it('renders nothing for other structured payloads', () => {
@@ -27,4 +30,26 @@ describe('McpUiBody', () => {
expect(screen.queryByTestId('mcp-ui-frame')).toBeNull();
expect(screen.getByTestId('mcp-ui-link')).toBeInTheDocument();
});
+
+ it('shows only the widget when it can be sandboxed', () => {
+ tauri.value = true;
+ try {
+ render(
+ <McpUiBody
+ structured={{
+ kind: 'mcp_ui',
+ flavor: 'mcp_apps',
+ server_id: 'srv',
+ tool: 'search',
+ resource_uri: 'ui://search',
+ links: [{ url: 'https://shop.example.com/item/1', kind: 'external' }],
+ }}
+ />
+ );
+ expect(screen.getByTestId('mcp-ui-frame')).toBeInTheDocument();
+ expect(screen.queryByTestId('mcp-ui-link')).toBeNull();
+ } finally {
+ tauri.value = false;
+ }
+ });
});
diff --git a/app/src/features/conversations/tools/mcpUi/McpUiBody.tsx b/app/src/features/conversations/tools/mcpUi/McpUiBody.tsx
index 9513b5e973..2af7baeb12 100644
--- a/app/src/features/conversations/tools/mcpUi/McpUiBody.tsx
+++ b/app/src/features/conversations/tools/mcpUi/McpUiBody.tsx
@@ -5,14 +5,14 @@ import { hasWidget, readMcpUiPresentation } from './types';
/**
* What a tool call that offered UI shows outside its collapsed card: the
- * widget, when there is one and this host can sandbox it, and the links the
- * result offered as a passive fallback.
+ * widget, when there is one and this host can sandbox it, or otherwise the
+ * links the result offered.
*/
export function McpUiBody({ structured }: { structured: unknown }) {
const presentation = readMcpUiPresentation(structured);
if (!presentation) return null;
const showFrame = hasWidget(presentation) && isTauri();
- const showLinks = presentation.links.length > 0;
+ const showLinks = !showFrame && presentation.links.length > 0;
if (!showFrame && !showLinks) return null;
return (
<div className="flex flex-col gap-2" data-testid="mcp-ui-body">
diff --git a/app/src/features/conversations/tools/mcpUi/types.test.ts b/app/src/features/conversations/tools/mcpUi/types.test.ts
index 6e3c627122..750fd58b93 100644
--- a/app/src/features/conversations/tools/mcpUi/types.test.ts
+++ b/app/src/features/conversations/tools/mcpUi/types.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
-import { hasWidget, readMcpUiPresentation } from './types';
+import { hasWidget, isImageUrl, readMcpUiPresentation } from './types';
describe('readMcpUiPresentation', () => {
it('reads a presentation and drops malformed links', () => {
@@ -30,3 +30,32 @@ describe('readMcpUiPresentation', () => {
expect(inline && hasWidget(inline)).toBe(true);
});
});
+
+describe('image links', () => {
+ it('drops image assets but keeps pages and app links', () => {
+ const presentation = readMcpUiPresentation({
+ kind: 'mcp_ui',
+ tool: 'search',
+ links: [
+ {
+ url: 'https://media-assets.swiggy.com/swiggy/image/upload/fl_lossy/NI_CATALOG/x_1',
+ kind: 'external',
+ },
+ { url: 'https://cdn.example.com/a/bar.JPG', kind: 'external' },
+ { url: 'https://shop.example.com/item/1', kind: 'external' },
+ { url: 'upi://[email protected]', kind: 'handoff' },
+ ],
+ });
+ expect(presentation?.links.map(link => link.url)).toEqual([
+ 'https://shop.example.com/item/1',
+ ]);
+ });
+
+ it('classifies by path only', () => {
+ expect(isImageUrl('https://res.cloudinary.com/demo/image/upload/sample')).toBe(true);
+ expect(isImageUrl('https://cdn.example.com/logo.svg?v=2')).toBe(true);
+ expect(isImageUrl('https://example.com/pngs/list')).toBe(false);
+ expect(isImageUrl('not a url')).toBe(false);
+ });
+});
diff --git a/app/src/features/conversations/tools/mcpUi/types.ts b/app/src/features/conversations/tools/mcpUi/types.ts
index 0333351ae2..fa7425288a 100644
--- a/app/src/features/conversations/tools/mcpUi/types.ts
+++ b/app/src/features/conversations/tools/mcpUi/types.ts
@@ -43,10 +43,25 @@ export interface McpUiToolCallResult {
const FLAVORS: readonly McpUiFlavor[] = ['mcp_apps', 'apps_sdk', 'host_inline'];
+const IMAGE_PATH = /\.(?:jpe?g|png|gif|webp|avif|svg|bmp|ico|heic|heif|tiff?)$/i;
+
+/** Whether an `http(s)` URL points at an image asset rather than a page. */
+export function isImageUrl(url: string): boolean {
+ let path: string;
+ try {
+ path = new URL(url).pathname.toLowerCase();
+ } catch {
+ return false;
+ }
+ return path.includes('/image/upload/') || IMAGE_PATH.test(path);
+}
+
function isLink(value: unknown): value is McpUiLink {
if (!value || typeof value !== 'object') return false;
const link = value as Record<string, unknown>;
- return typeof link.url === 'string' && (link.kind === 'external' || link.kind === 'handoff');
+ if (typeof link.url !== 'string') return false;
+ if (link.kind === 'handoff') return true;
+ return link.kind === 'external' && !isImageUrl(link.url);
}
/** Narrows a tool call's `structured` payload to a presentation. */