Skip to main content
MCP Apps SDK

Overview

useHostStyleVariables applies host-provided CSS custom properties and the document theme to the page. It listens for onhostcontextchanged notifications and updates styles automatically when the host’s theme or style variables change. This hook handles two responsibilities:
  • CSS variables — Applies styles.variables from the host context as CSS custom properties via applyHostStyleVariables()
  • Document theme — Sets the data-theme attribute and color-scheme property via applyDocumentTheme()
For font handling, use useHostFonts separately, or use useHostStyles to apply everything at once.

Signature

App | null
required
The connected App instance from useApp, or null during initialization.
McpUiHostContext | null
Initial host context from app?.getHostContext(). Pass this to apply styles immediately on mount without waiting for the first context change notification.

Usage

What It Applies

The host sends style variables as part of McpUiHostContext.styles.variables. These are CSS custom properties that match the host’s design system. See CSS Variables for the full list of available variable keys. The hook also applies the theme from McpUiHostContext.theme, setting:
  • document.documentElement.dataset.theme to "light" or "dark"
  • document.documentElement.style.colorScheme to match

When to Use

The sunpeak framework provides useHostContext which auto-applies host styles in React components.