fix(mcp-apps): update ui/message to use ContentBlock[] for content (#6546)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Andrew Harvard
2026-01-17 16:14:56 -05:00
committed by GitHub
parent d69a372323
commit dad65ffe29
2 changed files with 25 additions and 7 deletions
@@ -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': {
+10 -2
View File
@@ -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 };
@@ -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;