In sunpeak, the
useApp hook handles App creation and connection automatically. The details below are useful for understanding the underlying API or for non-React usage.Overview
TheApp class provides a framework-agnostic way to build interactive MCP Apps that run inside host applications. It extends the MCP SDK’s Protocol class and handles the connection lifecycle, initialization handshake, and bidirectional communication with the host.
Constructor
App identification:
{ name: string; version: string }.Features this app provides. Set
tools to expose app-side tools to the host. Set availableDisplayModes to declare supported display modes.Automatically report size changes to the host using
ResizeObserver.connect()
Establishes connection with the host and performs the initialization handshake.- Connects the transport layer
- Sends
ui/initializewith app info and capabilities - Receives host capabilities and context
- Sends
ui/notifications/initialized(see Lifecycle) - Sets up auto-resize if enabled
new PostMessageTransport(window.parent, window.parent).
Accessors
getHostCapabilities()
Returns the host’s capabilities from the initialization handshake.undefined before connection.
getHostVersion()
Returns the host’s name and version.undefined before connection.
getHostContext()
Returns the current host context (theme, locale, display mode, etc.). Automatically updated when the host sends context change notifications.PostMessageTransport
The transport layer for iframe-to-parent communication usingwindow.postMessage. In most cases you never need to use this directly — App.connect() creates one automatically when no transport is provided.
| Method | Description |
|---|---|
start() | Begin listening for messages |
send(message) | Send a JSON-RPC message to the target |
close() | Stop listening and clean up |
Auto-Resize
By default,App monitors document.body and document.documentElement for size changes and sends ui/notifications/size-changed to the host. Disable with { autoResize: false }. In React, you can use the useAutoResize hook instead.
setupSizeChangedNotifications()
Manually start auto-resize reporting. Returns a cleanup function. Automatically called byconnect() when autoResize: true.