Skip to content

Conversation

@aharvard
Copy link
Collaborator

@aharvard aharvard commented Jan 16, 2026

Summary

Fixes a bug where the ui/message handler was crashing with TypeError: 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/message params.content type. The written documentation showed content as a single object:

content: { type: 'text', text: string }

But MCP Apps were actually sending content as an array (this will the standard going forward):

content: [{ type: 'text', text: string }]

Our code was trying to access content.text directly, which was undefined because content was an array.

Resolution

After discussion with the spec authors, the agreed format going forward is ContentBlock[] (array of content blocks):

Changes

  • types.ts:

    • Added ContentBlock type supporting text, image, and resource block types
    • Updated McpMethodParams['ui/message'] to use { role: 'user'; content: ContentBlock[] }
    • Updated McpMethodResponse['ui/message'] to return empty object {} per spec
  • McpAppRenderer.tsx:

    • Updated handler to validate content is an array
    • Extracts text from the first text block found
    • Returns empty object on success per spec

Testing

  • TypeScript compiles without errors
  • ESLint passes

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
Copilot AI review requested due to automatic review settings January 16, 2026 19:08
@aharvard aharvard requested a review from DOsinga January 16, 2026 19:09
Copy link
Contributor

Copilot AI left a 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/message type definitions to use ContentBlock[] 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

Copilot AI review requested due to automatic review settings January 16, 2026 19:16
Copy link
Contributor

Copilot AI left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants