Skip to main content
sunpeak API

Overview

The useViewport hook returns the container dimensions provided by the host. This is useful for creating responsive layouts based on the actual available space.
For most resources, use the <SafeArea> component instead — it applies both safe area padding and viewport height constraints automatically.

Wraps onhostcontextchanged

MCP Apps SDK reference

Import

Signature

Returns

return
Viewport | null
Container dimension constraints set by the host, or null if the host does not report any.The host sends either a fixed size or a maximum constraint for each axis:
For each axis, the host provides either a fixed value (height/width) or a maximum (maxHeight/maxWidth), never both.

Usage

Container dimensions come from McpUiHostContext.containerDimensions. The inspector exposes Max Height and Max Width inputs under Container Dimensions so you can test how your resource responds to host-enforced size constraints.