Skip to main content
MCP Apps SDK

Overview

setupSizeChangedNotifications() manually starts automatic size reporting to the host. It attaches a ResizeObserver to document.body and document.documentElement, sending ui/notifications/size-changed whenever the content dimensions change. This method is automatically called by connect() when the App is created with autoResize: true (the default). You only need to call it directly when:
  • You created the App with autoResize: false and want to enable it later
  • You previously stopped auto-resize and want to restart it

Signature

Returns

return
() => void
A cleanup function that disconnects the ResizeObserver and stops size reporting. Call this to disable auto-resize.

Usage

Enable auto-resize after connection

Temporarily disable auto-resize

Conditional auto-resize

How It Works

The method creates a ResizeObserver that watches:
  1. document.documentElement catches viewport-level changes.
  2. document.body catches content-level changes.
When either element’s size changes, the observer sends the current scrollWidth and scrollHeight of document.documentElement to the host via sendSizeChanged().