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

Overview

Hosts may provide custom font CSS via McpUiHostContext.styles.css.fonts. This CSS can contain @font-face rules, @import statements, or both. Use applyHostFonts to inject it as a <style> tag.

applyHostFonts

Injects host font CSS into the document head. Idempotent — subsequent calls are no-ops.

Signature

fontCss
string
required
CSS string containing @font-face rules and/or @import statements.

Usage

Reference host fonts in CSS with the font family variables:

What Hosts Provide

Hosts may provide different types of font CSS:

Self-hosted fonts

Google Fonts

Combined Pattern

In practice, apply theme, variables, and fonts together when host context changes:
The sunpeak framework provides useHostContext which auto-applies host styles in React components.