Skip to content

Commit dad65ff

Browse files
aharvardCopilot
andauthored
fix(mcp-apps): update ui/message to use ContentBlock[] for content (#6546)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent d69a372 commit dad65ff

2 files changed

Lines changed: 25 additions & 7 deletions

File tree

ui/desktop/src/components/McpApps/McpAppRenderer.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,22 @@ export default function McpAppRenderer({
128128
if (!append) {
129129
throw new Error('Message handler not available in this context');
130130
}
131-
append(content.text);
131+
132+
if (!Array.isArray(content)) {
133+
throw new Error('Invalid message format: content must be an array of ContentBlock');
134+
}
135+
136+
// Extract first text block from content, ignoring other block types
137+
const textContent = content.find((block) => block.type === 'text');
138+
if (!textContent) {
139+
throw new Error('Invalid message format: content must contain a text block');
140+
}
141+
142+
// MCP Apps can send other content block types, but we only append text blocks for now
143+
144+
append(textContent.text);
132145
window.dispatchEvent(new CustomEvent('scroll-chat-to-bottom'));
133-
return {
134-
status: 'success',
135-
message: 'Message appended successfully',
136-
} satisfies McpMethodResponse['ui/message'];
146+
return {} satisfies McpMethodResponse['ui/message'];
137147
}
138148

139149
case 'tools/call': {

ui/desktop/src/components/McpApps/types.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
export type { CspMetadata, CallToolResponse as ToolResult } from '../../api/types.gen';
22

3+
export type ContentBlock =
4+
| { type: 'text'; text: string }
5+
| { type: 'image'; data: string; mimeType: string }
6+
| {
7+
type: 'resource';
8+
resource: { uri: string; mimeType?: string; text?: string; blob?: string };
9+
};
10+
311
export type McpMethodParams = {
412
'ui/open-link': { url: string };
5-
'ui/message': { content: { type: string; text: string } };
13+
'ui/message': { role: 'user'; content: ContentBlock[] };
614
'tools/call': { name: string; arguments?: Record<string, unknown> };
715
'resources/read': { uri: string };
816
'notifications/message': { level?: string; logger?: string; data: unknown };
@@ -11,7 +19,7 @@ export type McpMethodParams = {
1119

1220
export type McpMethodResponse = {
1321
'ui/open-link': { status: string; message: string };
14-
'ui/message': { status: string; message: string };
22+
'ui/message': Record<string, never>;
1523
'tools/call': {
1624
content: unknown[];
1725
isError: boolean;

0 commit comments

Comments
 (0)