connect().
Sequence
1. Discovery
The Host learns about tools and their UI resources when connecting to the server. Tools with_meta.ui.resourceUri are identified as MCP App tools.
_meta.ui.resourceUri to determine which resource to fetch and render.
2. Initialization
When a UI tool is called, the Host renders the iframe. The View sendsui/initialize with its app info and capabilities. The Host responds with:
- Protocol version — Negotiated protocol version
- Host info — Host name and version
- Host capabilities — What the host supports (tool proxying, messages, links, etc.)
- Host context — Theme, locale, display mode, container dimensions, safe area insets
ui/notifications/initialized to signal readiness.
The
App class handles this handshake automatically in connect(). Register event handlers before calling connect() to avoid missing notifications.3. Data Delivery
The Host sends tool arguments and results to the View:ui/notifications/tool-input— Complete tool arguments after the tool call beginsui/notifications/tool-input-partial— Streaming partial arguments (healed JSON) for progressive renderingui/notifications/tool-result— Tool execution result from the server, including bothcontent(text for model context) andstructuredContent(data optimized for UI rendering)ui/notifications/tool-cancelled— Notification that tool execution was cancelled
4. Interactive Phase
The user interacts with the View. The View can:| Action | Method |
|---|---|
| Call server tools | callServerTool() |
| Send chat messages | sendMessage() |
| Update model context | updateModelContext() |
| Open external links | openLink() |
| Download files | downloadFile() |
| Change display mode | requestDisplayMode() |
| Send logs | sendLog() |
5. Teardown
Before unmounting the iframe, the Host sendsui/resource-teardown. The View can save state or release resources before returning an acknowledgment. See Event Handlers for handling teardown.
Host Context Updates
At any point during the interactive phase, the Host may sendui/notifications/host-context-changed when the environment changes (theme toggle, resize, locale change). The App class automatically merges these updates into its internal context — access the latest via getHostContext().