Skip to main content
MCP Apps SDK MCP Apps render inside host-controlled iframes. The View owns its internal layout, but the Host owns the outer container. A good View reads the Host’s constraints, reports its content size when the Host lets it grow, and adapts when the user changes display mode. Use this page when a View is clipped, grows forever, leaves empty space, ignores safe areas, or behaves differently between inline and fullscreen modes.

The Layout Contract

The Host sends layout state in hostContext during ui/initialize and may update it later with onhostcontextchanged.

Fixed vs Flexible Dimensions

Each axis is independent. A host can fix width while letting height grow, or fix both axes in fullscreen.

Fixed Dimensions

If containerDimensions.height or containerDimensions.width is set, the Host controls that axis. Fill the available space instead of reporting a larger preferred size.
In React with sunpeak:

Flexible Dimensions

If the Host sends maxHeight or maxWidth, the View can choose its content size up to that value. This is common for inline chat cards where the host wants the app to fit naturally in the conversation.

Auto-Resize

The Host can only resize flexible iframes when the View reports its content size. The SDK handles this by default:
  • App enables autoResize: true by default.
  • Auto-resize watches document.body and document.documentElement with ResizeObserver.
  • When content changes, the View sends ui/notifications/size-changed.
  • The Host updates iframe dimensions when the corresponding axis is flexible.
Most apps should keep auto-resize enabled and avoid manual size messages.
Use sendSizeChanged() only when DOM measurement is not enough, such as canvas rendering, virtualized content, or an animation whose final size is known after a transition.

Display Modes

Views declare supported display modes in McpUiAppCapabilities. Hosts declare the modes they can provide in hostContext.availableDisplayModes. The View can request a mode, but the Host decides the final mode.
Inline Views should be compact and quick to scan. Fullscreen Views can use denser controls, persistent sidebars, and larger canvases. PiP Views should be narrow, resilient to small sizes, and focused on one ongoing task. In React with sunpeak:

Safe Areas

Use safeAreaInsets for fixed headers, footers, floating buttons, and mobile layouts. It is host-provided padding in pixels.

CSS Rules That Hold Up Across Hosts

Start with host-neutral document sizing:
Then choose scrolling intentionally: Avoid viewport-only assumptions in inline mode. 100vh can be much larger than the chat card the Host is willing to show. Use it only when the Host has fixed the height or when your app is fullscreen.

Common Problems