@@ -71,6 +71,9 @@ import {
7171 McpUiSandboxProxyReadyNotification ,
7272 McpUiSandboxProxyReadyNotificationSchema ,
7373 McpUiSizeChangedNotificationSchema ,
74+ McpUiRequestDisplayModeRequest ,
75+ McpUiRequestDisplayModeRequestSchema ,
76+ McpUiRequestDisplayModeResult ,
7477} from "./types" ;
7578export * from "./types" ;
7679export { RESOURCE_URI_META_KEY , RESOURCE_MIME_TYPE } from "./app" ;
@@ -222,6 +225,13 @@ export class AppBridge extends Protocol<
222225 this . onping ?.( request . params , extra ) ;
223226 return { } ;
224227 } ) ;
228+
229+ // Default handler for requestDisplayMode - returns current mode from host context.
230+ // Hosts can override this by setting bridge.onrequestdisplaymode = ...
231+ this . setRequestHandler ( McpUiRequestDisplayModeRequestSchema , ( request ) => {
232+ const currentMode = this . _hostContext . displayMode ?? "inline" ;
233+ return { mode : currentMode } ;
234+ } ) ;
225235 }
226236
227237 /**
@@ -494,6 +504,52 @@ export class AppBridge extends Protocol<
494504 ) ;
495505 }
496506
507+ /**
508+ * Register a handler for display mode change requests from the Guest UI.
509+ *
510+ * The Guest UI sends `ui/request-display-mode` requests when it wants to change
511+ * its display mode (e.g., from "inline" to "fullscreen"). The handler should
512+ * check if the requested mode is in `availableDisplayModes` from the host context,
513+ * update the display mode if supported, and return the actual mode that was set.
514+ *
515+ * If the requested mode is not available, the handler should return the current
516+ * display mode instead.
517+ *
518+ * @param callback - Handler that receives the requested mode and returns the actual mode set
519+ * - params.mode - The display mode being requested ("inline" | "fullscreen" | "pip")
520+ * - extra - Request metadata (abort signal, session info)
521+ * - Returns: Promise<McpUiRequestDisplayModeResult> with the actual mode set
522+ *
523+ * @example
524+ * ```typescript
525+ * bridge.onrequestdisplaymode = async ({ mode }, extra) => {
526+ * const availableModes = hostContext.availableDisplayModes ?? ["inline"];
527+ * if (availableModes.includes(mode)) {
528+ * setDisplayMode(mode);
529+ * return { mode };
530+ * }
531+ * // Return current mode if requested mode not available
532+ * return { mode: currentDisplayMode };
533+ * };
534+ * ```
535+ *
536+ * @see {@link McpUiRequestDisplayModeRequest } for the request type
537+ * @see {@link McpUiRequestDisplayModeResult } for the result type
538+ */
539+ set onrequestdisplaymode (
540+ callback : (
541+ params : McpUiRequestDisplayModeRequest [ "params" ] ,
542+ extra : RequestHandlerExtra ,
543+ ) => Promise < McpUiRequestDisplayModeResult > ,
544+ ) {
545+ this . setRequestHandler (
546+ McpUiRequestDisplayModeRequestSchema ,
547+ async ( request , extra ) => {
548+ return callback ( request . params , extra ) ;
549+ } ,
550+ ) ;
551+ }
552+
497553 /**
498554 * Register a handler for logging messages from the Guest UI.
499555 *
0 commit comments