@@ -159,6 +159,7 @@ const BRIDGE_EVENT_NOTIFICATION_SCHEMAS: Record<
159159 */
160160export function isToolVisibilityModelOnly ( tool : {
161161 _meta ?: Record < string , unknown > ;
162+ [ key : string ] : unknown ;
162163} ) : boolean {
163164 const v = ( tool . _meta ?. ui as McpUiToolMeta | undefined ) ?. visibility ;
164165 return Array . isArray ( v ) && v . length > 0 && ! v . includes ( "app" ) ;
@@ -169,6 +170,7 @@ export function isToolVisibilityModelOnly(tool: {
169170 */
170171export function isToolVisibilityAppOnly ( tool : {
171172 _meta ?: Record < string , unknown > ;
173+ [ key : string ] : unknown ;
172174} ) : boolean {
173175 const v = ( tool . _meta ?. ui as McpUiToolMeta | undefined ) ?. visibility ;
174176 return Array . isArray ( v ) && v . length > 0 && ! v . includes ( "model" ) ;
@@ -219,6 +221,8 @@ export class AppBridge extends EventDispatcher<AppBridgeEventMap> {
219221
220222 /** Optional error handler. Mirrors the v1 `Protocol.onerror` slot. */
221223 onerror ?: ( error : Error ) => void ;
224+ /** Called when the underlying transport closes. Mirrors v1 Protocol.onclose. */
225+ onclose ?: ( ) => void ;
222226
223227 constructor (
224228 private _client : Client | null ,
@@ -239,6 +243,7 @@ export class AppBridge extends EventDispatcher<AppBridgeEventMap> {
239243 } ,
240244 } ) ;
241245 this . server . onerror = ( err ) => this . onerror ?.( err ) ;
246+ this . server . onclose = ( ) => this . onclose ?.( ) ;
242247 this . ui = this . server . extension ( MCP_APPS_EXTENSION_ID , _capabilities , {
243248 peerSchema : McpUiAppCapabilitiesSchema ,
244249 } ) ;
@@ -447,7 +452,7 @@ export class AppBridge extends EventDispatcher<AppBridgeEventMap> {
447452 private _onupdatemodelcontext ?: (
448453 params : McpUiUpdateModelContextRequest [ "params" ] ,
449454 extra : RequestHandlerExtra ,
450- ) => Promise < void > | void ;
455+ ) => Promise < void | object > | void | object ;
451456 get onupdatemodelcontext ( ) { return this . _onupdatemodelcontext ; }
452457 set onupdatemodelcontext ( cb ) {
453458 this . warnIfRequestHandlerReplaced (
@@ -552,8 +557,13 @@ export class AppBridge extends EventDispatcher<AppBridgeEventMap> {
552557 * Call this when theme, locale, displayMode, etc. change.
553558 */
554559 setHostContext ( context : Partial < McpUiHostContext > ) {
560+ const changed : Partial < McpUiHostContext > = { } ;
561+ for ( const [ k , v ] of Object . entries ( context ) as [ keyof McpUiHostContext , unknown ] [ ] ) {
562+ if ( this . _hostContext [ k ] !== v ) ( changed as Record < string , unknown > ) [ k ] = v ;
563+ }
555564 this . _hostContext = { ...this . _hostContext , ...context } ;
556- return this . sendHostContextChanged ( context ) ;
565+ if ( Object . keys ( changed ) . length === 0 ) return Promise . resolve ( ) ;
566+ return this . sendHostContextChanged ( changed ) ;
557567 }
558568
559569 /** Low-level: send a host-context-changed notification with the given diff. */
0 commit comments