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.variablesfrom the host context as CSS custom properties viaapplyHostStyleVariables() - Document theme — Sets the
data-themeattribute andcolor-schemeproperty viaapplyDocumentTheme()
useHostFonts separately, or use useHostStyles to apply everything at once.
Signature
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 ofMcpUiHostContext.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.themeto"light"or"dark"document.documentElement.style.colorSchemeto match
When to Use
| Hook | Applies | Use when |
|---|---|---|
useHostStyles | CSS variables + theme + fonts | You want everything (recommended) |
useHostStyleVariables | CSS variables + theme only | You handle fonts separately or don’t need them |
useHostFonts | Fonts only | You only need host fonts |
Related
useHostStyles— All-in-one styling hook (combines this hook withuseHostFonts)useHostFonts— Host font injection hookuseDocumentTheme— Reactive theme detection hook- CSS Variables — Full list of host style variable keys