Skip to main content
MCP Apps SDK

Overview

The App class provides a framework-agnostic way to build interactive MCP Apps that run inside host applications. It extends ProtocolWithEvents (which itself extends the MCP SDK’s Protocol class) and handles the connection lifecycle, initialization handshake, and bidirectional communication with the host. The ProtocolWithEvents base class adds DOM-style addEventListener/removeEventListener support for composable, multi-listener event handling alongside the traditional on* setter properties.

Constructor

appInfo
Implementation
required
App identification: { name: string; version: string }.
capabilities
McpUiAppCapabilities
default:"{}"
Features this app provides. Set tools to expose app-side tools to the host. Set availableDisplayModes to declare supported display modes.
options
AppOptions
default:"{ autoResize: true }"
autoResize
boolean
default:"true"
Automatically report size changes to the host using ResizeObserver.

connect()

Establishes connection with the host and performs the initialization handshake.
Steps performed:
  1. Connects the transport layer
  2. Sends ui/initialize with app info and capabilities
  3. Receives host capabilities and context
  4. Sends ui/notifications/initialized (see Lifecycle)
  5. Sets up auto-resize if enabled
If no transport is provided, defaults to new PostMessageTransport(window.parent, window.parent).
Register event handlers before calling connect() to avoid missing notifications during the handshake.

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 using window.postMessage. In most cases you never need to use this directly — App.connect() creates one automatically when no transport is provided.

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. For the full host sizing contract, including fixed vs flexible containerDimensions and display mode changes, see Layout and Display.

setupSizeChangedNotifications()

Manually start auto-resize reporting. Returns a cleanup function. Automatically called by connect() when autoResize: true.

sendSizeChanged()

Manually notify the host of a size change:
In React, the SDK’s useApp hook handles App creation and connection automatically. The sunpeak framework provides additional convenience hooks like useApp.