@@ -33,7 +33,7 @@ import {
3333 McpUiResourceTeardownRequest ,
3434 McpUiResourceTeardownRequestSchema ,
3535 McpUiResourceTeardownResult ,
36- McpUiSizeChangedNotification ,
36+ McpUiHeightChangedNotification ,
3737 McpUiToolCancelledNotification ,
3838 McpUiToolCancelledNotificationSchema ,
3939 McpUiToolInputNotification ,
@@ -94,10 +94,10 @@ export const RESOURCE_MIME_TYPE = "text/html;profile=mcp-app";
9494 */
9595type AppOptions = ProtocolOptions & {
9696 /**
97- * Automatically report size changes to the host using ResizeObserver.
97+ * Automatically report height changes to the host using ResizeObserver.
9898 *
9999 * When enabled, the App monitors `document.body` and `document.documentElement`
100- * for size changes and automatically sends `ui/notifications/size -changed`
100+ * for size changes and automatically sends `ui/notifications/height -changed`
101101 * notifications to the host.
102102 *
103103 * @default true
@@ -840,37 +840,34 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
840840 }
841841
842842 /**
843- * Notify the host of UI size changes .
843+ * Notify the host of UI height change .
844844 *
845- * Apps can manually report size changes to help the host adjust the container .
845+ * Apps can manually report height changes to help the host adjust the iframe .
846846 * If `autoResize` is enabled (default), this is called automatically.
847847 *
848- * @param params - New width and height in pixels
848+ * @param params - New height in pixels
849849 *
850- * @example Manually notify host of size change
850+ * @example Manually notify host of height change
851851 * ```typescript
852- * app.sendSizeChanged({
853- * width: 400,
854- * height: 600
855- * });
852+ * app.sendHeightChanged({ height: 600 });
856853 * ```
857854 *
858855 * @returns Promise that resolves when the notification is sent
859856 *
860- * @see {@link McpUiSizeChangedNotification } for notification structure
857+ * @see {@link McpUiHeightChangedNotification } for notification structure
861858 */
862- sendSizeChanged ( params : McpUiSizeChangedNotification [ "params" ] ) {
863- return this . notification ( < McpUiSizeChangedNotification > {
864- method : "ui/notifications/size -changed" ,
859+ sendHeightChanged ( params : McpUiHeightChangedNotification [ "params" ] ) {
860+ return this . notification ( < McpUiHeightChangedNotification > {
861+ method : "ui/notifications/height -changed" ,
865862 params,
866863 } ) ;
867864 }
868865
869866 /**
870- * Set up automatic size change notifications using ResizeObserver.
867+ * Set up automatic height change notifications using ResizeObserver.
871868 *
872869 * Observes both `document.documentElement` and `document.body` for size changes
873- * and automatically sends `ui/notifications/size -changed` notifications to the host.
870+ * and automatically sends `ui/notifications/height -changed` notifications to the host.
874871 * The notifications are debounced using requestAnimationFrame to avoid duplicates.
875872 *
876873 * Note: This method is automatically called by `connect()` if the `autoResize`
@@ -885,18 +882,17 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
885882 * await app.connect(transport);
886883 *
887884 * // Later, enable auto-resize manually
888- * const cleanup = app.setupSizeChangedNotifications ();
885+ * const cleanup = app.setupHeightChangedNotifications ();
889886 *
890887 * // Clean up when done
891888 * cleanup();
892889 * ```
893890 */
894- setupSizeChangedNotifications ( ) {
891+ setupHeightChangedNotifications ( ) {
895892 let scheduled = false ;
896- let lastWidth = 0 ;
897893 let lastHeight = 0 ;
898894
899- const sendBodySizeChanged = ( ) => {
895+ const sendBodyHeightChanged = ( ) => {
900896 if ( scheduled ) {
901897 return ;
902898 }
@@ -905,36 +901,27 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
905901 scheduled = false ;
906902 const html = document . documentElement ;
907903
908- // Measure actual content size by temporarily setting html to fit-content.
904+ // Measure actual content height by temporarily setting html to fit-content.
909905 // This shrinks html to fit body (including body margins), giving us the
910- // true minimum size needed by the content.
911- const originalWidth = html . style . width ;
906+ // true minimum height needed by the content.
912907 const originalHeight = html . style . height ;
913- html . style . width = "fit-content" ;
914908 html . style . height = "fit-content" ;
915909 const rect = html . getBoundingClientRect ( ) ;
916- html . style . width = originalWidth ;
917910 html . style . height = originalHeight ;
918911
919- // Compensate for scrollbar width on Linux/Windows where scrollbars consume space.
920- // On systems with overlay scrollbars (macOS), this will be 0.
921- const scrollbarWidth = window . innerWidth - html . clientWidth ;
922-
923- const width = Math . ceil ( rect . width + scrollbarWidth ) ;
924912 const height = Math . ceil ( rect . height ) ;
925913
926- // Only send if size actually changed (prevents feedback loops from style changes)
927- if ( width !== lastWidth || height !== lastHeight ) {
928- lastWidth = width ;
914+ // Only send if height actually changed (prevents feedback loops from style changes)
915+ if ( height !== lastHeight ) {
929916 lastHeight = height ;
930- this . sendSizeChanged ( { width , height } ) ;
917+ this . sendHeightChanged ( { height } ) ;
931918 }
932919 } ) ;
933920 } ;
934921
935- sendBodySizeChanged ( ) ;
922+ sendBodyHeightChanged ( ) ;
936923
937- const resizeObserver = new ResizeObserver ( sendBodySizeChanged ) ;
924+ const resizeObserver = new ResizeObserver ( sendBodyHeightChanged ) ;
938925 // Observe both html and body to catch all size changes
939926 resizeObserver . observe ( document . documentElement ) ;
940927 resizeObserver . observe ( document . body ) ;
@@ -950,7 +937,7 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
950937 * 2. Sends `ui/initialize` request with app info and capabilities
951938 * 3. Receives host capabilities and context in response
952939 * 4. Sends `ui/notifications/initialized` notification
953- * 5. Sets up auto-resize using {@link setupSizeChangedNotifications } if enabled (default)
940+ * 5. Sets up auto-resize using {@link setupHeightChangedNotifications } if enabled (default)
954941 *
955942 * If initialization fails, the connection is automatically closed and an error
956943 * is thrown.
@@ -1012,7 +999,7 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
1012999 } ) ;
10131000
10141001 if ( this . options ?. autoResize ) {
1015- this . setupSizeChangedNotifications ( ) ;
1002+ this . setupHeightChangedNotifications ( ) ;
10161003 }
10171004 } catch ( error ) {
10181005 // Disconnect if initialization fails.
0 commit comments