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:
@@ -128,12 +128,22 @@ export default function McpAppRenderer({
|
|||||||
if (!append) {
|
if (!append) {
|
||||||
throw new Error('Message handler not available in this context');
|
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'));
|
window.dispatchEvent(new CustomEvent('scroll-chat-to-bottom'));
|
||||||
return {
|
return {} satisfies McpMethodResponse['ui/message'];
|
||||||
status: 'success',
|
|
||||||
message: 'Message appended successfully',
|
|
||||||
} satisfies McpMethodResponse['ui/message'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'tools/call': {
|
case 'tools/call': {
|
||||||
|
|||||||
@@ -1,8 +1,16 @@
|
|||||||
export type { CspMetadata, CallToolResponse as ToolResult } from '../../api/types.gen';
|
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 = {
|
export type McpMethodParams = {
|
||||||
'ui/open-link': { url: string };
|
'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> };
|
'tools/call': { name: string; arguments?: Record<string, unknown> };
|
||||||
'resources/read': { uri: string };
|
'resources/read': { uri: string };
|
||||||
'notifications/message': { level?: string; logger?: string; data: unknown };
|
'notifications/message': { level?: string; logger?: string; data: unknown };
|
||||||
@@ -11,7 +19,7 @@ export type McpMethodParams = {
|
|||||||
|
|
||||||
export type McpMethodResponse = {
|
export type McpMethodResponse = {
|
||||||
'ui/open-link': { status: string; message: string };
|
'ui/open-link': { status: string; message: string };
|
||||||
'ui/message': { status: string; message: string };
|
'ui/message': Record<string, never>;
|
||||||
'tools/call': {
|
'tools/call': {
|
||||||
content: unknown[];
|
content: unknown[];
|
||||||
isError: boolean;
|
isError: boolean;
|
||||||
|
|||||||
Reference in New Issue
Block a user