@@ -228,12 +228,19 @@ export type AppMessage = McpUiMessageRequest["params"];
228228export interface AppBridgeCallbacks {
229229 onContextUpdate ?: ( context : ModelContext | null ) => void ;
230230 onMessage ?: ( message : AppMessage ) => void ;
231+ onDisplayModeChange ?: ( mode : "inline" | "fullscreen" ) => void ;
232+ }
233+
234+ export interface AppBridgeOptions {
235+ containerDimensions ?: { maxHeight ?: number ; width ?: number } | { height : number ; width ?: number } ;
236+ displayMode ?: "inline" | "fullscreen" ;
231237}
232238
233239export function newAppBridge (
234240 serverInfo : ServerInfo ,
235241 iframe : HTMLIFrameElement ,
236242 callbacks ?: AppBridgeCallbacks ,
243+ options ?: AppBridgeOptions ,
237244) : AppBridge {
238245 const serverCapabilities = serverInfo . client . getServerCapabilities ( ) ;
239246 const appBridge = new AppBridge ( serverInfo . client , IMPLEMENTATION , {
@@ -242,6 +249,12 @@ export function newAppBridge(
242249 serverResources : serverCapabilities ?. resources ,
243250 // Declare support for model context updates
244251 updateModelContext : { text : { } } ,
252+ } , {
253+ hostContext : {
254+ containerDimensions : options ?. containerDimensions ?? { maxHeight : 600 } ,
255+ displayMode : options ?. displayMode ?? "inline" ,
256+ availableDisplayModes : [ "inline" , "fullscreen" ] ,
257+ } ,
245258 } ) ;
246259
247260 // Register all handlers before calling connect(). The Guest UI can start
@@ -308,5 +321,18 @@ export function newAppBridge(
308321 iframe . animate ( [ from , to ] , { duration : 300 , easing : "ease-out" } ) ;
309322 } ;
310323
324+ // Handle display mode change requests from the app
325+ appBridge . onrequestdisplaymode = async ( params ) => {
326+ log . info ( "Display mode request from MCP App:" , params ) ;
327+ const newMode = params . mode === "fullscreen" ? "fullscreen" : "inline" ;
328+ // Update host context and notify the app
329+ appBridge . sendHostContextChange ( {
330+ displayMode : newMode ,
331+ } ) ;
332+ // Notify the host UI (via callback)
333+ callbacks ?. onDisplayModeChange ?.( newMode ) ;
334+ return { mode : newMode } ;
335+ } ;
336+
311337 return appBridge ;
312338}
0 commit comments