You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve patterns guide with concrete examples and safe area insets
- Rename "host styling" section to "host context" and add safe area
insets handling
- Replace abstract `renderLoadingUI`/`renderFinalUI` example with
concrete code preview pattern for `ontoolinputpartial`
- Rename callback parameter `params` → `ctx` for clarity across all
`onhostcontextchanged` handlers
- Add CSS snippet for fullscreen border-radius handling
- Expand display mode example to show `availableDisplayModes` check
- Fix minor typos and wording consistency
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
_See [`examples/pdf-server/`](https://github.com/modelcontextprotocol/ext-apps/tree/main/examples/pdf-server) for a full implementation of this pattern._
160
160
161
-
## Giving errors back to model
161
+
## Giving errors back to the model
162
162
163
163
**Server-side**: Tool handler validates inputs and returns `{ isError: true, content: [...] }`. The model receives this error through the normal tool call response.
164
164
@@ -182,18 +182,19 @@ try {
182
182
}
183
183
```
184
184
185
-
## Matching host styling (CSS variables, theme, and fonts)
185
+
## Adapting to host context (theme, styling, fonts, and safe areas)
186
186
187
-
Use the SDK's style helpers to apply host styling, then reference them in your CSS:
187
+
The host provides context about its environment via {@link types!McpUiHostContext `McpUiHostContext`}. Use this to adapt your app's appearance and layout:
188
188
189
-
-**CSS variables** — Use `var(--color-background-primary)`, etc. in your CSS
190
189
-**Theme** — Use `[data-theme="dark"]` selectors or `light-dark()` function for theme-aware styles
190
+
-**CSS variables** — Use `var(--color-background-primary)`, etc. in your CSS (see {@link types!McpUiStyleVariableKey `McpUiStyleVariableKey`} for a full list)
191
191
-**Fonts** — Use `var(--font-sans)` or `var(--font-mono)` with fallbacks (e.g., `font-family: var(--font-sans, system-ui, sans-serif)`)
192
+
-**Safe area insets** — Apply padding to avoid device notches, rounded corners, or system UI overlays
Styled with host CSS variables, fonts, and safe area insets
243
277
</div>
244
278
);
245
279
}
246
280
```
247
281
248
282
_See [`examples/basic-server-vanillajs/`](https://github.com/modelcontextprotocol/ext-apps/tree/main/examples/basic-server-vanillajs) and [`examples/basic-server-react/`](https://github.com/modelcontextprotocol/ext-apps/tree/main/examples/basic-server-react) for full implementations of this pattern._
249
283
250
-
## Entering / Exiting fullscreen
284
+
## Entering / exiting fullscreen
251
285
252
286
Toggle fullscreen mode by calling {@link app!App.requestDisplayMode `requestDisplayMode`}:
In fullscreen mode, remove the container's border radius so content extends to the viewport edges:
321
+
322
+
```css
323
+
#main {
324
+
border-radius: var(--border-radius-lg);
325
+
326
+
&.fullscreen {
327
+
border-radius: 0;
328
+
}
329
+
}
330
+
```
331
+
276
332
_See [`examples/shadertoy-server/`](https://github.com/modelcontextprotocol/ext-apps/tree/main/examples/shadertoy-server) for a full implementation of this pattern._
277
333
278
-
## Passing contextual information from the App to the Model
334
+
## Passing contextual information from the App to the model
279
335
280
336
Use {@link app!App.updateModelContext `updateModelContext`} to keep the model informed about what the user is viewing or interacting with. Structure the content with YAML frontmatter for easy parsing:
_See [`examples/map-server/`](https://github.com/modelcontextprotocol/ext-apps/tree/main/examples/map-server) for a full implementation of this pattern._
391
447
392
-
## Pausing computation-heavy views when out of view
448
+
## Pausing computation-heavy views when offscreen
393
449
394
-
Views with animations, WebGL rendering, or polling can consume significant CPU/GPU even when scrolled out of view. Use [`IntersectionObserver`](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) to pause expensive operations when the view isn't visible:
450
+
Views with animations, WebGL rendering, or polling can consume significant CPU/GPU even when scrolled offscreen. Use [`IntersectionObserver`](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) to pause expensive operations when the view isn't visible:
Use {@link app!App.ontoolinputpartial `ontoolinputpartial`} to receive streaming tool arguments as they arrive, allowing you to show a loading preview before the complete input is available.
478
+
Use {@link app!App.ontoolinputpartial `ontoolinputpartial`} to receive streaming tool arguments as they arrive. This lets you show a loading preview before the complete input is available, such as streaming code into a `<pre>` tag before executing it, partially rendering a table as data arrives, or incrementally populating a chart.
0 commit comments