Skip to content

Commit dc226be

Browse files
committed
Remove viewport
1 parent e90c794 commit dc226be

8 files changed

Lines changed: 13 additions & 143 deletions

File tree

examples/threejs-server/src/mcp-app-wrapper.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface WidgetProps<TToolInput = Record<string, unknown>> {
2525
toolInputsPartial: TToolInput | null;
2626
/** Tool execution result from the server */
2727
toolResult: CallToolResult | null;
28-
/** Host context (theme, viewport, locale, etc.) */
28+
/** Host context (theme, dimensions, locale, etc.) */
2929
hostContext: McpUiHostContext | null;
3030
/** Call a tool on the MCP server */
3131
callServerTool: App["callServerTool"];
@@ -65,7 +65,7 @@ function McpAppWrapper() {
6565
app.ontoolresult = (params) => {
6666
setToolResult(params as CallToolResult);
6767
};
68-
// Host context changes (theme, viewport, etc.)
68+
// Host context changes (theme, dimensions, etc.)
6969
app.onhostcontextchanged = (params) => {
7070
setHostContext(params);
7171
};

specification/draft/apps.mdx

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -469,13 +469,6 @@ interface HostContext {
469469
| { width: number } // If specified, container is fixed at this width
470470
| { maxWidth?: number } // Otherwise, container width is determined by the UI width, up to this maximum width (if defined)
471471
);
472-
/** Host window viewport dimensions */
473-
viewport?: {
474-
/** Window viewport width in pixels. */
475-
width?: number;
476-
/** Window viewport height in pixels. */
477-
height?: number;
478-
};
479472
/** User's language/region preference (BCP 47, e.g., "en-US") */
480473
locale?: string;
481474
/** User's timezone (IANA, e.g., "America/New_York") */
@@ -525,20 +518,17 @@ Example:
525518
},
526519
"displayMode": "inline",
527520
"containerDimensions": { "width": 400, "maxHeight": 600 }
528-
"viewport": { "width": 1920, "height": 1080 },
529521
}
530522
}
531523
}
532524
```
533525

534-
### Viewport and Dimensions
526+
### Container Dimensions
535527

536-
The `HostContext` provides two separate fields for sizing information:
528+
The `HostContext` provides sizing information via `containerDimensions`:
537529

538530
- **`containerDimensions`**: The dimensions of the container that holds the app. This controls the actual space the app occupies within the host. Each dimension (height and width) operates independently and can be either **fixed** or **flexible**.
539531

540-
- **`viewport`**: The host window's dimensions (e.g., `window.innerWidth` and `window.innerHeight`). Apps can use this to make responsive layout decisions based on the overall screen size.
541-
542532
#### Dimension Modes
543533

544534
| Mode | Dimensions Field | Meaning |
@@ -578,12 +568,6 @@ if (containerDimensions) {
578568
}
579569
// If neither, width is unbounded
580570
}
581-
582-
// Apps can also use viewport for additional data to make responsive layout decisions
583-
const viewport = hostContext.viewport;
584-
if (viewport?.width && viewport.width < 768) {
585-
// Apply mobile-friendly layout
586-
}
587571
```
588572

589573
#### Host Behavior

src/app-bridge.test.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ describe("App <-> AppBridge integration", () => {
113113
const testHostContext = {
114114
theme: "dark" as const,
115115
locale: "en-US",
116-
viewport: { width: 800, height: 600 },
117116
containerDimensions: { width: 800, maxHeight: 600 },
118117
};
119118
const newBridge = new AppBridge(
@@ -338,7 +337,6 @@ describe("App <-> AppBridge integration", () => {
338337
const initialContext = {
339338
theme: "light" as const,
340339
locale: "en-US",
341-
viewport: { width: 800, height: 600 },
342340
containerDimensions: { width: 800, maxHeight: 600 },
343341
};
344342
const newBridge = new AppBridge(
@@ -356,24 +354,19 @@ describe("App <-> AppBridge integration", () => {
356354
newBridge.sendHostContextChange({ theme: "dark" });
357355
await flush();
358356

359-
// Send another partial update: only viewport and containerDimensions change
357+
// Send another partial update: only containerDimensions change
360358
newBridge.sendHostContextChange({
361-
viewport: { width: 1024, height: 768 },
362359
containerDimensions: { width: 1024, maxHeight: 768 },
363360
});
364361
await flush();
365362

366363
// getHostContext should have accumulated all updates:
367364
// - locale from initial (unchanged)
368365
// - theme from first partial update
369-
// - viewport and containerDimensions from second partial update
366+
// - containerDimensions from second partial update
370367
const context = newApp.getHostContext();
371368
expect(context?.theme).toBe("dark");
372369
expect(context?.locale).toBe("en-US");
373-
expect(context?.viewport).toEqual({
374-
width: 1024,
375-
height: 768,
376-
});
377370
expect(context?.containerDimensions).toEqual({
378371
width: 1024,
379372
maxHeight: 768,

src/app-bridge.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ export class AppBridge extends Protocol<
356356
* adjust the iframe container dimensions based on the Guest UI's content.
357357
*
358358
* Note: This is for Guest UI → Host communication. To notify the Guest UI of
359-
* host viewport changes, use {@link app.App.sendSizeChanged}.
359+
* host container dimension changes, use {@link setHostContext}.
360360
*
361361
* @example
362362
* ```typescript
@@ -1008,7 +1008,6 @@ export class AppBridge extends Protocol<
10081008
* ```typescript
10091009
* bridge.setHostContext({
10101010
* theme: "dark",
1011-
* viewport: { width: 800, height: 600 },
10121011
* containerDimensions: { maxHeight: 600, width: 800 }
10131012
* });
10141013
* ```

src/app.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ type RequestHandlerExtra = Parameters<
154154
* - `ontoolinput` - Complete tool arguments from host
155155
* - `ontoolinputpartial` - Streaming partial tool arguments
156156
* - `ontoolresult` - Tool execution results
157-
* - `onhostcontextchanged` - Host context changes (theme, viewport, etc.)
157+
* - `onhostcontextchanged` - Host context changes (theme, locale, etc.)
158158
*
159159
* These setters are convenience wrappers around `setNotificationHandler()`.
160160
* Both patterns work; use whichever fits your coding style better.
@@ -293,7 +293,7 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
293293
* Get the host context discovered during initialization.
294294
*
295295
* Returns the host context that was provided in the initialization response,
296-
* including tool info, theme, viewport, locale, and other environment details.
296+
* including tool info, theme, locale, and other environment details.
297297
* This context is automatically updated when the host sends
298298
* `ui/notifications/host-context-changed` notifications.
299299
*
@@ -478,12 +478,12 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
478478
}
479479

480480
/**
481-
* Convenience handler for host context changes (theme, viewport, locale, etc.).
481+
* Convenience handler for host context changes (theme, locale, etc.).
482482
*
483483
* Set this property to register a handler that will be called when the host's
484-
* context changes, such as theme switching (light/dark), viewport size changes,
485-
* locale changes, or other environmental updates. Apps should respond by
486-
* updating their UI accordingly.
484+
* context changes, such as theme switching (light/dark), locale changes, or
485+
* other environmental updates. Apps should respond by updating their UI
486+
* accordingly.
487487
*
488488
* This setter is a convenience wrapper around `setNotificationHandler()` that
489489
* automatically handles the notification schema and extracts the params for you.

src/generated/schema.json

Lines changed: 0 additions & 75 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/generated/schema.ts

Lines changed: 0 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/spec.types.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -349,16 +349,6 @@ export interface McpUiHostContext {
349349
maxWidth?: number | undefined;
350350
}
351351
);
352-
/**
353-
* @description Window viewport dimensions. Represents the host window's viewport size,
354-
* which provides additional information apps can use to make responsive layout decisions.
355-
*/
356-
viewport?: {
357-
/** @description Window viewport width in pixels. */
358-
width?: number | undefined;
359-
/** @description Window viewport height in pixels. */
360-
height?: number | undefined;
361-
};
362352
/** @description User's language and region preference in BCP 47 format. */
363353
locale?: string;
364354
/** @description User's timezone in IANA format. */

0 commit comments

Comments
 (0)