Skip to content

Commit 8f591b6

Browse files
committed
Update naming of functions to reflect styles.variables nesting
1 parent 277a41b commit 8f591b6

File tree

6 files changed

+22
-22
lines changed

6 files changed

+22
-22
lines changed

examples/customer-segmentation-server/src/mcp-app.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import {
55
App,
66
PostMessageTransport,
7-
applyHostStyles,
7+
applyHostStyleVariables,
88
applyDocumentTheme,
99
} from "@modelcontextprotocol/ext-apps";
1010
import { Chart, registerables } from "chart.js";
@@ -454,7 +454,7 @@ app.onhostcontextchanged = (params) => {
454454
applyDocumentTheme(params.theme);
455455
}
456456
if (params.styles?.variables) {
457-
applyHostStyles(params.styles.variables);
457+
applyHostStyleVariables(params.styles.variables);
458458
}
459459
// Recreate chart to pick up new colors
460460
if (state.chart && (params.theme || params.styles?.variables)) {
@@ -470,7 +470,7 @@ app.connect(new PostMessageTransport(window.parent)).then(() => {
470470
applyDocumentTheme(ctx.theme);
471471
}
472472
if (ctx?.styles?.variables) {
473-
applyHostStyles(ctx.styles.variables);
473+
applyHostStyleVariables(ctx.styles.variables);
474474
}
475475
});
476476

specification/draft/apps.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ type McpUiStyleVariableKey =
587587
...
588588
}
589589
```
590-
- Apps can use the `applyHostStyles` utility (or `useHostStyles` if they prefer a React hook) to easily populate the host-provided CSS variables into their style sheet
590+
- Apps can use the `applyHostStyleVariables` utility (or `useHostStyleVariables` if they prefer a React hook) to easily populate the host-provided CSS variables into their style sheet
591591
- Apps can use the `applyDocumentTheme` utility (or `useDocumentTheme` if they prefer a React hook) to easily respond to Host Context `theme` changes in a way that is compatible with the host's light/dark color variables
592592

593593
Example usage of standardized CSS variables:

src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
4848
export { PostMessageTransport } from "./message-transport";
4949
export * from "./types";
5050
export {
51-
applyHostStyles,
51+
applyHostStyleVariables,
5252
getDocumentTheme,
5353
applyDocumentTheme,
5454
} from "./styles";

src/react/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* ## Main Exports
1010
*
1111
* - {@link useApp} - React hook to create and connect an MCP App
12-
* - {@link useHostStyles} - React hook to apply host styles as CSS variables
12+
* - {@link useHostStyleVariables} - React hook to apply host style variables and theme
1313
* - {@link useDocumentTheme} - React hook for reactive document theme
1414
* - {@link useAutoResize} - React hook for manual auto-resize control (rarely needed)
1515
*

src/react/useHostStyles.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { useEffect, useRef } from "react";
22
import { App } from "../app";
3-
import { applyDocumentTheme, applyHostStyles } from "../styles";
3+
import { applyDocumentTheme, applyHostStyleVariables } from "../styles";
44
import { McpUiHostContext } from "../types";
55

66
/**
7-
* React hook that applies host styles and theme as CSS custom properties.
7+
* React hook that applies host style variables and theme as CSS custom properties.
88
*
99
* This hook listens to host context changes and automatically applies:
1010
* - `styles.variables` CSS variables to `document.documentElement` (e.g., `--color-background-primary`)
@@ -24,16 +24,16 @@ import { McpUiHostContext } from "../types";
2424
* @example Basic usage with useApp
2525
* ```tsx
2626
* import { useApp } from '@modelcontextprotocol/ext-apps/react';
27-
* import { useHostStyles } from '@modelcontextprotocol/ext-apps/react';
27+
* import { useHostStyleVariables } from '@modelcontextprotocol/ext-apps/react';
2828
*
2929
* function MyApp() {
3030
* const { app, isConnected } = useApp({
3131
* appInfo: { name: "MyApp", version: "1.0.0" },
3232
* capabilities: {},
3333
* });
3434
*
35-
* // Automatically apply host styles and theme
36-
* useHostStyles(app);
35+
* // Automatically apply host style variables and theme
36+
* useHostStyleVariables(app);
3737
*
3838
* return (
3939
* <div style={{ background: 'var(--color-background-primary)' }}>
@@ -49,14 +49,14 @@ import { McpUiHostContext } from "../types";
4949
*
5050
* // ... get initial context from app.connect() result
5151
*
52-
* useHostStyles(app, hostContext);
52+
* useHostStyleVariables(app, hostContext);
5353
* ```
5454
*
55-
* @see {@link applyHostStyles} for the underlying styles function
55+
* @see {@link applyHostStyleVariables} for the underlying styles function
5656
* @see {@link applyDocumentTheme} for the underlying theme function
5757
* @see {@link McpUiStyles} for available CSS variables
5858
*/
59-
export function useHostStyles(
59+
export function useHostStyleVariables(
6060
app: App | null,
6161
initialContext?: McpUiHostContext | null,
6262
): void {
@@ -71,7 +71,7 @@ export function useHostStyles(
7171
applyDocumentTheme(initialContext.theme);
7272
}
7373
if (initialContext?.styles?.variables) {
74-
applyHostStyles(initialContext.styles.variables);
74+
applyHostStyleVariables(initialContext.styles.variables);
7575
}
7676
if (initialContext?.theme || initialContext?.styles?.variables) {
7777
initialApplied.current = true;
@@ -89,7 +89,7 @@ export function useHostStyles(
8989
applyDocumentTheme(params.theme);
9090
}
9191
if (params.styles?.variables) {
92-
applyHostStyles(params.styles.variables);
92+
applyHostStyleVariables(params.styles.variables);
9393
}
9494
};
9595
}, [app]);

src/styles.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export function applyDocumentTheme(theme: McpUiTheme): void {
7474
}
7575

7676
/**
77-
* Apply host styles as CSS custom properties on an element.
77+
* Apply host style variables as CSS custom properties on an element.
7878
*
7979
* This function takes the `variables` object from `McpUiHostContext.styles` and sets
8080
* each CSS variable on the specified root element (defaults to `document.documentElement`).
@@ -84,27 +84,27 @@ export function applyDocumentTheme(theme: McpUiTheme): void {
8484
* @param styles - The styles object from `McpUiHostContext.styles.variables`
8585
* @param root - The element to apply styles to (defaults to `document.documentElement`)
8686
*
87-
* @example Apply styles from host context
87+
* @example Apply style variables from host context
8888
* ```typescript
89-
* import { applyHostStyles } from '@modelcontextprotocol/ext-apps';
89+
* import { applyHostStyleVariables } from '@modelcontextprotocol/ext-apps';
9090
*
9191
* app.onhostcontextchanged = (params) => {
9292
* if (params.styles?.variables) {
93-
* applyHostStyles(params.styles.variables);
93+
* applyHostStyleVariables(params.styles.variables);
9494
* }
9595
* };
9696
* ```
9797
*
9898
* @example Apply to a specific element
9999
* ```typescript
100100
* const container = document.getElementById('app-root');
101-
* applyHostStyles(hostContext.styles?.variables, container);
101+
* applyHostStyleVariables(hostContext.styles?.variables, container);
102102
* ```
103103
*
104104
* @see {@link McpUiStyles} for the available CSS variables
105105
* @see {@link McpUiHostContext} for the full host context structure
106106
*/
107-
export function applyHostStyles(
107+
export function applyHostStyleVariables(
108108
styles: McpUiStyles,
109109
root: HTMLElement = document.documentElement,
110110
): void {

0 commit comments

Comments
 (0)