-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix(mcp-apps): update ui/message to use ContentBlock[] for content #6546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
The MCP Apps draft spec (SEP-1865) has been in flux regarding the
ui/message params.content type. After discussion with the spec authors,
the agreed format is ContentBlock[] (array of content blocks) rather
than a single ContentBlock object.
This change:
- Updates McpMethodParams['ui/message'] to expect content as ContentBlock[]
- Adds ContentBlock type supporting text, image, and resource blocks
- Updates the handler to extract text from the first text block in the array
- Returns empty object {} on success per the spec
Related spec discussions:
- modelcontextprotocol/ext-apps#48
- modelcontextprotocol/ext-apps#119
- MCP-UI-Org/mcp-ui#166
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a bug in the MCP Apps ui/message handler where it was crashing when trying to access content.text on an array. The spec has been clarified to use ContentBlock[] instead of a single content object, and this PR updates both the types and handler implementation accordingly.
Changes:
- Updated
ui/messagetype definitions to useContentBlock[]array with support for text, image, and resource blocks - Modified handler to validate array format and extract text from the first text block
- Changed response type from status object to empty object per spec
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| ui/desktop/src/components/McpApps/types.ts | Added ContentBlock type union and updated ui/message params/response types |
| ui/desktop/src/components/McpApps/McpAppRenderer.tsx | Updated handler to process ContentBlock array and extract text content |
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Summary
Fixes a bug where the
ui/messagehandler was crashing withTypeError: Cannot read properties of undefined (reading 'trim')when MCP Apps sent messages.Problem
The MCP Apps draft spec (SEP-1865) has been in flux regarding the
ui/messageparams.contenttype. The written documentation showedcontentas a single object:But MCP Apps were actually sending
contentas an array (this will the standard going forward):Our code was trying to access
content.textdirectly, which wasundefinedbecausecontentwas an array.Resolution
After discussion with the spec authors, the agreed format going forward is
ContentBlock[](array of content blocks):Changes
types.ts:ContentBlocktype supportingtext,image, andresourceblock typesMcpMethodParams['ui/message']to use{ role: 'user'; content: ContentBlock[] }McpMethodResponse['ui/message']to return empty object{}per specMcpAppRenderer.tsx:contentis an arrayTesting