feat: add ui/update-model-context (#125)
--------- Co-authored-by: Olivier Chafik <ochafik@anthropic.com>
This commit is contained in:
parent
9acc52cb96
commit
b273279849
1 changed files with 918 additions and 3 deletions
48
src/app.ts
48
src/app.ts
|
|
@ -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.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue