The connected App instance, or null during initialization
OptionalinitialContext: McpUiHostContext | nullInitial host context from the connection (optional). If provided, styles and theme will be applied immediately on mount.
import { useApp } from '@modelcontextprotocol/ext-apps/react';
import { useHostStyleVariables } from '@modelcontextprotocol/ext-apps/react';
function MyApp() {
const { app, isConnected } = useApp({
appInfo: { name: "MyApp", version: "1.0.0" },
capabilities: {},
});
// Automatically apply host style variables and theme
useHostStyleVariables(app);
return (
<div style={{ background: 'var(--color-background-primary)' }}>
Hello!
</div>
);
}
const [hostContext, setHostContext] = useState<McpUiHostContext | null>(null);
// ... get initial context from app.connect() result
useHostStyleVariables(app, hostContext);
React hook that applies host style variables and theme as CSS custom properties.
This hook listens to host context changes and automatically applies:
styles.variablesCSS variables todocument.documentElement(e.g.,--color-background-primary)themeviacolor-schemeCSS property, enablinglight-dark()CSS function supportThe hook also applies styles and theme from the initial host context when the app first connects.
Note: If the host provides style values using CSS
light-dark()function, this hook ensures they work correctly by setting thecolor-schemeproperty based on the host's theme preference.