Skip to content

Commit 3aa93db

Browse files
authored
Add AppBridge.sendHostContextChange + reexport RESOURCE_URI_META_KEY (#87)
* Export RESOURCE_URI_META_KEY from app-bridge * add sendHostContextChange * nit
1 parent 43214f9 commit 3aa93db

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/app-bridge.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import {
6060
McpUiSizeChangedNotificationSchema,
6161
} from "./types";
6262
export * from "./types";
63+
export { RESOURCE_URI_META_KEY } from "./app";
6364
export { PostMessageTransport } from "./message-transport";
6465

6566
/**
@@ -153,8 +154,8 @@ type RequestHandlerExtra = Parameters<
153154
*/
154155
export class AppBridge extends Protocol<Request, Notification, Result> {
155156
private _appCapabilities?: McpUiAppCapabilities;
157+
private _hostContext: McpUiHostContext = {};
156158
private _appInfo?: Implementation;
157-
private _hostContext: McpUiHostContext;
158159

159160
/**
160161
* Create a new AppBridge instance.
@@ -625,13 +626,23 @@ export class AppBridge extends Protocol<Request, Notification, Result> {
625626
}
626627
if (hasChanges) {
627628
this._hostContext = hostContext;
628-
this.notification((<McpUiHostContextChangedNotification>{
629-
method: "ui/notifications/host-context-changed",
630-
params: changes,
631-
}) as Notification); // Cast needed because McpUiHostContext is a params type that doesn't allow arbitrary keys.
629+
this.sendHostContextChange(changes);
632630
}
633631
}
634632

633+
/**
634+
* Send a host context change notification to the app.
635+
* Only sends the fields that have changed (partial update).
636+
*/
637+
sendHostContextChange(
638+
params: McpUiHostContextChangedNotification["params"],
639+
): Promise<void> | void {
640+
return this.notification((<McpUiHostContextChangedNotification>{
641+
method: "ui/notifications/host-context-changed",
642+
params,
643+
}) as Notification);
644+
}
645+
635646
/**
636647
* Send complete tool arguments to the Guest UI.
637648
*

src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import {
4141
} from "./types";
4242
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
4343

44-
export { PostMessageTransport } from "./message-transport.js";
44+
export { PostMessageTransport } from "./message-transport";
4545
export * from "./types";
4646

4747
/**

0 commit comments

Comments
 (0)