Skip to main content
MCP Apps SDK

Overview

useHostFonts injects host-provided font CSS into the document. It listens for onhostcontextchanged notifications and updates the fonts automatically when the host’s font configuration changes. The host sends font CSS as @font-face rules or @import statements in McpUiHostContext.styles.css.fonts. This hook injects those rules as a <style> tag via applyHostFonts(). For CSS variable and theme handling, use useHostStyleVariables 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 fonts immediately on mount without waiting for the first context change notification.

Usage

What It Applies

The host provides font CSS in McpUiHostContext.styles.css.fonts. This typically contains:
  • @font-face declarations for the host’s typeface
  • @import statements for web font services
The hook injects these as a <style> tag in the document head using applyHostFonts(). This makes the host’s fonts available for use via CSS variables like var(--font-sans).

When to Use

  • useHostStyles — All-in-one styling hook (combines useHostStyleVariables with this hook)
  • useHostStyleVariables — CSS variables and theme hook
  • Fonts — How host font delivery works in MCP Apps
The sunpeak framework provides useHostContext which auto-applies host styles (including fonts) in React components.