feat: add ui/update-model-context (#125)

---------

Co-authored-by: Olivier Chafik <ochafik@anthropic.com>
This commit is contained in:
Ido Salomon 2026-01-12 17:21:45 +02:00 • committed by GitHub
commit b273279849
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -9,6 +9,7 @@ import {
CallToolRequestSchema,
CallToolResult,
CallToolResultSchema,
EmptyResultSchema,
Implementation,
ListToolsRequest,
ListToolsRequestSchema,
@ -20,6 +21,7 @@ import { PostMessageTransport } from "./message-transport";
import {
LATEST_PROTOCOL_VERSION,
McpUiAppCapabilities,
McpUiUpdateModelContextRequest,
McpUiHostCapabilities,
McpUiHostContext,
McpUiHostContextChangedNotification,
@ -809,6 +811,52 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
});
}
/**
* Update the host's model context with app state.
*
* Unlike `sendLog`, which is for debugging/telemetry, context updates
* are intended to be available to the model in future reasoning,
* without requiring a follow-up action (like `sendMessage`).
*
* The host will typically defer sending the context to the model until the
* next user message (including `ui/message`), and will only send the last
* update received. Each call overwrites any previous context update.
*
* @param params - Context content and/or structured content
* @param options - Request options (timeout, etc.)
*
* @throws {Error} If the host rejects the context update (e.g., unsupported content type)
*
* @example Update model context with current app state
* ```typescript
* await app.updateModelContext({
* content: [{ type: "text", text: "User selected 3 items totaling $150.00" }]
* });
* ```
*
* @example Update with structured content
* ```typescript
* await app.updateModelContext({
* structuredContent: { selectedItems: 3, total: 150.00, currency: "USD" }
* });
* ```
*
* @returns Promise that resolves when the context update is acknowledged
*/
updateModelContext(
params: McpUiUpdateModelContextRequest["params"],
options?: RequestOptions,
) {
return this.request(
<McpUiUpdateModelContextRequest>{
method: "ui/update-model-context",
params,
},
EmptyResultSchema,
options,
);
}
/**
* Request the host to open an external URL in the default browser.
*