Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions ui/desktop/src/components/McpApps/McpAppRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down
12 changes: 10 additions & 2 deletions ui/desktop/src/components/McpApps/types.ts
Original file line number Diff line number Diff line change
@@ -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<string, unknown> };
'resources/read': { uri: string };
'notifications/message': { level?: string; logger?: string; data: unknown };
Expand All @@ -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<string, never>;
'tools/call': {
content: unknown[];
isError: boolean;
Expand Down
Loading