Overview
getHostContext() returns the current host environment context. This includes the theme, styles, locale, time zone, display mode, container dimensions, device capabilities, platform, and safe area insets.
The context is first populated during the initialization handshake and automatically updated when the host sends onhostcontextchanged notifications.
Returns undefined before connect() completes.
Signature
Returns
The current host context, or
undefined if the app has not connected yet. See McpUiHostContext for the full type definition.Usage
Read the current theme
Check display mode
Use locale for formatting
Adapt to container dimensions
Check device capabilities
Apply safe area insets
Context Fields
| Field | Type | Description |
|---|---|---|
theme | McpUiTheme | "light" or "dark" |
styles | McpUiHostStyles | CSS variables and font CSS |
displayMode | McpUiDisplayMode | "inline", "fullscreen", or "pip" |
availableDisplayModes | McpUiDisplayMode[] | Modes the host supports |
containerDimensions | object | width, maxWidth, height, maxHeight in pixels |
locale | string | BCP 47 locale (e.g., "en-US") |
timeZone | string | IANA time zone (e.g., "America/New_York") |
userAgent | string | Host application identifier |
platform | string | "web", "desktop", or "mobile" |
deviceCapabilities | object | touch and hover booleans |
safeAreaInsets | object | top, right, bottom, left in pixels |
toolInfo | object | Current tool ID and definition |
Reactivity
getHostContext() always returns the latest context. When the host sends a context change notification, the App class merges the partial update into its stored context. To react to changes:
- Vanilla JS — Register an
onhostcontextchangedhandler - React — Use the sunpeak
useHostContexthook for reactive updates
Related
McpUiHostContext— Full type definitiononhostcontextchanged— Event handler for context updatesgetHostCapabilities()— What the host supportsgetHostVersion()— Host identification- Accessors overview — All App accessor methods