Add AppBridge.sendHostContextChange + reexport RESOURCE_URI_META_KEY (#87)

* Export  RESOURCE_URI_META_KEY from app-bridge

* add sendHostContextChange

* nit
This commit is contained in:
Olivier Chafik 2025-12-08 15:28:21 +01:00 • committed by GitHub
commit 3aa93db3c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 6 deletions

View file

@ -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<Request, Notification, Result> {
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<Request, Notification, Result> {
}
if (hasChanges) {
this._hostContext = hostContext;
this.notification((<McpUiHostContextChangedNotification>{
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> | void {
return this.notification((<McpUiHostContextChangedNotification>{
method: "ui/notifications/host-context-changed",
params,
}) as Notification);
}
/**
* Send complete tool arguments to the Guest UI.
*

View file

@ -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";
/**