Skip to content

Commit 245ae91

Browse files
ochafikclaude
andcommitted
docs: add JSDoc for setHostContext and sendToolInputPartial
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent d40149f commit 245ae91

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

src/app-bridge.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,37 @@ export class AppBridge extends Protocol<Request, Notification, Result> {
562562
};
563563
}
564564

565+
/**
566+
* Update the host context and notify the Guest UI of changes.
567+
*
568+
* Compares the new context with the current context and sends a
569+
* `ui/notifications/host-context-changed` notification containing only the
570+
* fields that have changed. If no fields have changed, no notification is sent.
571+
*
572+
* Common use cases include notifying the Guest UI when:
573+
* - Theme changes (light/dark mode toggle)
574+
* - Viewport size changes (window resize)
575+
* - Display mode changes (inline/fullscreen)
576+
* - Locale or timezone changes
577+
*
578+
* @param hostContext - The complete new host context state
579+
*
580+
* @example Update theme when user toggles dark mode
581+
* ```typescript
582+
* bridge.setHostContext({ theme: "dark" });
583+
* ```
584+
*
585+
* @example Update multiple context fields
586+
* ```typescript
587+
* bridge.setHostContext({
588+
* theme: "dark",
589+
* viewport: { width: 800, height: 600 }
590+
* });
591+
* ```
592+
*
593+
* @see {@link McpUiHostContext} for the context structure
594+
* @see {@link McpUiHostContextChangedNotification} for the notification type
595+
*/
565596
setHostContext(hostContext: McpUiHostContext) {
566597
const changes: McpUiHostContext = {};
567598
let hasChanges = false;
@@ -614,6 +645,33 @@ export class AppBridge extends Protocol<Request, Notification, Result> {
614645
});
615646
}
616647

648+
/**
649+
* Send streaming partial tool arguments to the Guest UI.
650+
*
651+
* The host MAY send this notification zero or more times while tool arguments
652+
* are being streamed, before {@link sendToolInput} is called with complete
653+
* arguments. This enables progressive rendering of tool arguments in the
654+
* Guest UI.
655+
*
656+
* The arguments represent best-effort recovery of incomplete JSON. Guest UIs
657+
* SHOULD handle missing or changing fields gracefully between notifications.
658+
*
659+
* @param params - Partial tool call arguments (may be incomplete)
660+
*
661+
* @example Stream partial arguments as they arrive
662+
* ```typescript
663+
* // As streaming progresses...
664+
* bridge.sendToolInputPartial({ arguments: { loc: "N" } });
665+
* bridge.sendToolInputPartial({ arguments: { location: "New" } });
666+
* bridge.sendToolInputPartial({ arguments: { location: "New York" } });
667+
*
668+
* // When complete, send final input
669+
* bridge.sendToolInput({ arguments: { location: "New York", units: "metric" } });
670+
* ```
671+
*
672+
* @see {@link McpUiToolInputPartialNotification} for the notification type
673+
* @see {@link sendToolInput} for sending complete arguments
674+
*/
617675
sendToolInputPartial(params: McpUiToolInputPartialNotification["params"]) {
618676
return this.notification(<McpUiToolInputPartialNotification>{
619677
method: "ui/notifications/tool-input-partial",

0 commit comments

Comments
 (0)