From 3aa93db3c39c39855f5a85cf2ffee55a737a4397 Mon Sep 17 00:00:00 2001 From: Olivier Chafik Date: Mon, 8 Dec 2025 15:28:21 +0100 Subject: [PATCH] Add AppBridge.sendHostContextChange + reexport RESOURCE_URI_META_KEY (#87) * Export RESOURCE_URI_META_KEY from app-bridge * add sendHostContextChange * nit --- src/app-bridge.ts | 21 ++++++++++++++++----- src/app.ts | 2 +- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/app-bridge.ts b/src/app-bridge.ts index e36aeea..43c9898 100644 --- a/src/app-bridge.ts +++ b/src/app-bridge.ts @@ -60,6 +60,7 @@ import { McpUiSizeChangedNotificationSchema, } from "./types"; export * from "./types"; +export { RESOURCE_URI_META_KEY } from "./app"; export { PostMessageTransport } from "./message-transport"; /** @@ -153,8 +154,8 @@ type RequestHandlerExtra = Parameters< */ export class AppBridge extends Protocol { private _appCapabilities?: McpUiAppCapabilities; + private _hostContext: McpUiHostContext = {}; private _appInfo?: Implementation; - private _hostContext: McpUiHostContext; /** * Create a new AppBridge instance. @@ -625,13 +626,23 @@ export class AppBridge extends Protocol { } if (hasChanges) { this._hostContext = hostContext; - this.notification(({ - method: "ui/notifications/host-context-changed", - params: changes, - }) as Notification); // Cast needed because McpUiHostContext is a params type that doesn't allow arbitrary keys. + this.sendHostContextChange(changes); } } + /** + * Send a host context change notification to the app. + * Only sends the fields that have changed (partial update). + */ + sendHostContextChange( + params: McpUiHostContextChangedNotification["params"], + ): Promise | void { + return this.notification(({ + method: "ui/notifications/host-context-changed", + params, + }) as Notification); + } + /** * Send complete tool arguments to the Guest UI. * diff --git a/src/app.ts b/src/app.ts index 42e3057..7719667 100644 --- a/src/app.ts +++ b/src/app.ts @@ -41,7 +41,7 @@ import { } from "./types"; import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js"; -export { PostMessageTransport } from "./message-transport.js"; +export { PostMessageTransport } from "./message-transport"; export * from "./types"; /**