Skip to content

Commit b50ae66

Browse files
committed
add sendHostContextChange
1 parent 6823c4b commit b50ae66

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/app-bridge.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ type RequestHandlerExtra = Parameters<
154154
*/
155155
export class AppBridge extends Protocol<Request, Notification, Result> {
156156
private _appCapabilities?: McpUiAppCapabilities;
157+
private _hostContext: McpUiHostContext = {};
157158
private _appInfo?: Implementation;
158-
private _hostContext: McpUiHostContext;
159159

160160
/**
161161
* Create a new AppBridge instance.
@@ -626,13 +626,23 @@ export class AppBridge extends Protocol<Request, Notification, Result> {
626626
}
627627
if (hasChanges) {
628628
this._hostContext = hostContext;
629-
this.notification((<McpUiHostContextChangedNotification>{
630-
method: "ui/notifications/host-context-changed",
631-
params: changes,
632-
}) as Notification); // Cast needed because McpUiHostContext is a params type that doesn't allow arbitrary keys.
629+
this.sendHostContextChange(changes);
633630
}
634631
}
635632

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+
636646
/**
637647
* Send complete tool arguments to the Guest UI.
638648
*

0 commit comments

Comments
 (0)