The Layout Contract
The Host sends layout state inhostContext 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
IfcontainerDimensions.height or containerDimensions.width is set, the Host controls that axis. Fill the available space instead of reporting a larger preferred size.
Flexible Dimensions
If the Host sendsmaxHeight 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:AppenablesautoResize: trueby default.- Auto-resize watches
document.bodyanddocument.documentElementwithResizeObserver. - When content changes, the View sends
ui/notifications/size-changed. - The Host updates iframe dimensions when the corresponding axis is flexible.
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 inMcpUiAppCapabilities. Hosts declare the modes they can provide in hostContext.availableDisplayModes. The View can request a mode, but the Host decides the final mode.
Safe Areas
UsesafeAreaInsets 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:
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
Related
getHostContext()- Read display mode, dimensions, and safe areas.requestDisplayMode()- Ask the Host to switch display modes.sendSizeChanged()- Manually report View dimensions.setupSizeChangedNotifications()- Control auto-resize.useAutoResize- React wrapper for manual auto-resize control.