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
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 inMcpUiHostContext.styles.css.fonts. This typically contains:
@font-facedeclarations for the host’s typeface@importstatements for web font services
<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
| 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 (combinesuseHostStyleVariableswith this hook)useHostStyleVariables— CSS variables and theme hook- Fonts — How host font delivery works in MCP Apps