Skip to main content
MCP Apps SDK
In React components, useHostStyles applies theme, CSS variables, and fonts automatically. The functions below are useful for non-React usage or custom control.

Overview

Hosts provide a theme preference ("light" or "dark") via host context. The SDK provides functions to apply this theme to the document and read the current theme state.

applyDocumentTheme

Sets the data-theme attribute and color-scheme CSS property on document.documentElement. This enables:
  • CSS selectors like [data-theme="dark"]
  • The CSS light-dark() function
  • Native elements (scrollbars, form controls) respecting the theme

Signature

Usage

CSS Selectors

After calling applyDocumentTheme, use these patterns in your CSS:

getDocumentTheme

Reads the current theme from document.documentElement. Checks the data-theme attribute first, then falls back to the dark class for Tailwind CSS compatibility.

Signature

Usage

McpUiTheme

See also: CSS Variables for host-provided color tokens, and Fonts for host typography.
The sunpeak framework provides useTheme for reactive theme access in React components.