The connected App instance, or null during initialization
OptionalinitialContext: McpUiHostContext | nullInitial host context from the connection (optional). If provided, fonts will be applied immediately on mount.
import { useApp } from '@modelcontextprotocol/ext-apps/react';
import { useHostFonts } from '@modelcontextprotocol/ext-apps/react';
function MyApp() {
const { app, isConnected } = useApp({
appInfo: { name: "MyApp", version: "1.0.0" },
capabilities: {},
});
// Automatically apply host fonts
useHostFonts(app);
return (
<div style={{ fontFamily: 'var(--font-sans)' }}>
Hello!
</div>
);
}
const [hostContext, setHostContext] = useState<McpUiHostContext | null>(null);
// ... get initial context from app.connect() result
useHostFonts(app, hostContext);
React hook that applies host fonts from CSS.
This hook listens to host context changes and automatically applies:
styles.css.fontsas a<style>tag for custom fontsThe CSS can contain
@font-facerules for self-hosted fonts,@importstatements for Google Fonts or other font services, or both.The hook also applies fonts from the initial host context when the app first connects.