diff --git a/ui/desktop/src/components/McpApps/McpAppRenderer.tsx b/ui/desktop/src/components/McpApps/McpAppRenderer.tsx index e3df201c114d..c78e2b94a95b 100644 --- a/ui/desktop/src/components/McpApps/McpAppRenderer.tsx +++ b/ui/desktop/src/components/McpApps/McpAppRenderer.tsx @@ -128,12 +128,22 @@ export default function McpAppRenderer({ if (!append) { throw new Error('Message handler not available in this context'); } - append(content.text); + + if (!Array.isArray(content)) { + throw new Error('Invalid message format: content must be an array of ContentBlock'); + } + + // Extract first text block from content, ignoring other block types + const textContent = content.find((block) => block.type === 'text'); + if (!textContent) { + throw new Error('Invalid message format: content must contain a text block'); + } + + // MCP Apps can send other content block types, but we only append text blocks for now + + append(textContent.text); window.dispatchEvent(new CustomEvent('scroll-chat-to-bottom')); - return { - status: 'success', - message: 'Message appended successfully', - } satisfies McpMethodResponse['ui/message']; + return {} satisfies McpMethodResponse['ui/message']; } case 'tools/call': { diff --git a/ui/desktop/src/components/McpApps/types.ts b/ui/desktop/src/components/McpApps/types.ts index 43ce6ecade11..c24c7ae80f85 100644 --- a/ui/desktop/src/components/McpApps/types.ts +++ b/ui/desktop/src/components/McpApps/types.ts @@ -1,8 +1,16 @@ export type { CspMetadata, CallToolResponse as ToolResult } from '../../api/types.gen'; +export type ContentBlock = + | { type: 'text'; text: string } + | { type: 'image'; data: string; mimeType: string } + | { + type: 'resource'; + resource: { uri: string; mimeType?: string; text?: string; blob?: string }; + }; + export type McpMethodParams = { 'ui/open-link': { url: string }; - 'ui/message': { content: { type: string; text: string } }; + 'ui/message': { role: 'user'; content: ContentBlock[] }; 'tools/call': { name: string; arguments?: Record }; 'resources/read': { uri: string }; 'notifications/message': { level?: string; logger?: string; data: unknown }; @@ -11,7 +19,7 @@ export type McpMethodParams = { export type McpMethodResponse = { 'ui/open-link': { status: string; message: string }; - 'ui/message': { status: string; message: string }; + 'ui/message': Record; 'tools/call': { content: unknown[]; isError: boolean;