Skip to content

Commit 9e920c9

Browse files
committed
Update to update-model-context
1 parent 7392629 commit 9e920c9

File tree

9 files changed

+109
-114
lines changed

9 files changed

+109
-114
lines changed

specification/draft/apps.mdx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -533,14 +533,14 @@ Host SHOULD open the URL in the user's default browser or a new tab.
533533

534534
Host SHOULD add the message to the conversation thread, preserving the specified role.
535535

536-
`ui/update-context` - Update the agent's conversation context
536+
`ui/update-model-context` - Update the model context
537537

538538
```typescript
539539
// Request
540540
{
541541
jsonrpc: "2.0",
542542
id: 3,
543-
method: "ui/update-context",
543+
method: "ui/update-model-context",
544544
params: {
545545
role: "user",
546546
content: ContentBlock[]
@@ -565,12 +565,13 @@ Host SHOULD add the message to the conversation thread, preserving the specified
565565
}
566566
```
567567

568-
Guest UI MAY send this request to inform the agent about app state changes that should be stored in the conversation context for future reasoning. This event serves a different use case from `notifications/message` (logging) and `ui/message` (which also trigger follow-ups).
568+
Guest UI MAY send this request to update the Host's model context. This context will be used in future turns. Each request overwrites the previous context sent by the Guest UI.
569+
This event serves a different use case from `notifications/message` (logging) and `ui/message` (which also trigger follow-ups).
569570

570571
Host behavior:
571-
- SHOULD store the context update in the conversation context
572+
- SHOULD store the context snapshot in the conversation context
573+
- SHOULD overwrite the previous model context with the new update
572574
- MAY display context updates to the user
573-
- MAY filter or aggregate context updates
574575

575576
#### Notifications (Host → UI)
576577

@@ -806,9 +807,9 @@ sequenceDiagram
806807
H -->> UI: ui/message response
807808
H -->> H: Process message and follow up
808809
else Context update
809-
UI ->> H: ui/update-context
810-
H ->> H: Store in conversation context
811-
H -->> UI: ui/update-context response
810+
UI ->> H: ui/update-model-context
811+
H ->> H: Store model context (overwrite existing)
812+
H -->> UI: ui/update-model-context response
812813
else Log
813814
UI ->> H: notifications/message
814815
H ->> H: Record log for debugging/telemetry

src/app-bridge.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,15 @@ describe("App <-> AppBridge integration", () => {
213213
});
214214
});
215215

216-
it("app.sendUpdateContext triggers bridge.onupdatecontext and returns result", async () => {
216+
it("app.sendUpdateModelContext triggers bridge.onupdatemodelcontext and returns result", async () => {
217217
const receivedContexts: unknown[] = [];
218-
bridge.onupdatecontext = async (params) => {
218+
bridge.onupdatemodelcontext = async (params) => {
219219
receivedContexts.push(params);
220220
return {};
221221
};
222222

223223
await app.connect(appTransport);
224-
const result = await app.sendUpdateContext({
224+
const result = await app.sendUpdateModelContext({
225225
role: "user",
226226
content: [{ type: "text", text: "User selected 3 items" }],
227227
});
@@ -234,15 +234,15 @@ describe("App <-> AppBridge integration", () => {
234234
expect(result).toEqual({});
235235
});
236236

237-
it("app.sendUpdateContext works with multiple content blocks", async () => {
237+
it("app.sendUpdateModelContext works with multiple content blocks", async () => {
238238
const receivedContexts: unknown[] = [];
239-
bridge.onupdatecontext = async (params) => {
239+
bridge.onupdatemodelcontext = async (params) => {
240240
receivedContexts.push(params);
241241
return {};
242242
};
243243

244244
await app.connect(appTransport);
245-
const result = await app.sendUpdateContext({
245+
const result = await app.sendUpdateModelContext({
246246
role: "user",
247247
content: [
248248
{ type: "text", text: "Filter applied" },
@@ -261,13 +261,13 @@ describe("App <-> AppBridge integration", () => {
261261
expect(result).toEqual({});
262262
});
263263

264-
it("app.sendUpdateContext returns error result when handler indicates error", async () => {
265-
bridge.onupdatecontext = async () => {
264+
it("app.sendUpdateModelContext returns error result when handler indicates error", async () => {
265+
bridge.onupdatemodelcontext = async () => {
266266
return { isError: true };
267267
};
268268

269269
await app.connect(appTransport);
270-
const result = await app.sendUpdateContext({
270+
const result = await app.sendUpdateModelContext({
271271
role: "user",
272272
content: [{ type: "text", text: "Test" }],
273273
});

src/app-bridge.ts

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ import {
3939
type McpUiToolResultNotification,
4040
LATEST_PROTOCOL_VERSION,
4141
McpUiAppCapabilities,
42-
McpUiUpdateContextRequest,
43-
McpUiUpdateContextRequestSchema,
44-
McpUiUpdateContextResult,
42+
McpUiUpdateModelContextRequest,
43+
McpUiUpdateModelContextRequestSchema,
44+
McpUiUpdateModelContextResult,
4545
McpUiHostCapabilities,
4646
McpUiHostContext,
4747
McpUiHostContextChangedNotification,
@@ -506,30 +506,24 @@ export class AppBridge extends Protocol<Request, Notification, Result> {
506506
}
507507

508508
/**
509-
* Register a handler for context updates from the Guest UI.
509+
* Register a handler for model context updates from the Guest UI.
510510
*
511-
* The Guest UI sends `ui/update-context` requests to inform the agent
512-
* about app state changes that should be stored in the conversation context for
513-
* future reasoning. Unlike logging messages, context updates are intended to be
514-
* available to the agent for decision making.
515-
*
516-
* @param callback - Handler that receives context update params and returns a result
517-
* - params.role - Message role (currently only "user")
518-
* - params.content - Content blocks (text, image, etc.)
519-
* - extra - Request metadata (abort signal, session info)
520-
* - Returns: Promise<McpUiUpdateContextResult> with optional isError flag
511+
* The Guest UI sends `ui/update-model-context` requests to update the Host's
512+
* model context. Each request overwrites the previous context stored by the Guest UI.
513+
* Unlike logging messages, context updates are intended to be available to
514+
* the model in future turns. Unlike messages, context updates do not trigger follow-ups
521515
*
522516
* @example
523517
* ```typescript
524-
* bridge.onupdatecontext = async ({ role, content }, extra) => {
518+
* bridge.onupdatemodelcontext = async ({ role, content }, extra) => {
525519
* try {
526-
* // Store context update for agent reasoning
527-
* conversationContext.push({
520+
* // Update the model context with the new snapshot
521+
* modelContext = {
528522
* type: "app_context",
529523
* role,
530524
* content,
531525
* timestamp: Date.now()
532-
* });
526+
* };
533527
* return {};
534528
* } catch (err) {
535529
* // Handle error and signal failure to the app
@@ -538,17 +532,17 @@ export class AppBridge extends Protocol<Request, Notification, Result> {
538532
* };
539533
* ```
540534
*
541-
* @see {@link McpUiUpdateContextRequest} for the request type
542-
* @see {@link McpUiUpdateContextResult} for the result type
535+
* @see {@link McpUiUpdateModelContextRequest} for the request type
536+
* @see {@link McpUiUpdateModelContextResult} for the result type
543537
*/
544-
set onupdatecontext(
538+
set onupdatemodelcontext(
545539
callback: (
546-
params: McpUiUpdateContextRequest["params"],
540+
params: McpUiUpdateModelContextRequest["params"],
547541
extra: RequestHandlerExtra,
548-
) => Promise<McpUiUpdateContextResult>,
542+
) => Promise<McpUiUpdateModelContextResult>,
549543
) {
550544
this.setRequestHandler(
551-
McpUiUpdateContextRequestSchema,
545+
McpUiUpdateModelContextRequestSchema,
552546
async (request, extra) => {
553547
return callback(request.params, extra);
554548
},

src/app.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import {
2121
import {
2222
LATEST_PROTOCOL_VERSION,
2323
McpUiAppCapabilities,
24-
McpUiUpdateContextRequest,
25-
McpUiUpdateContextResultSchema,
24+
McpUiUpdateModelContextRequest,
25+
McpUiUpdateModelContextResultSchema,
2626
McpUiHostCapabilities,
2727
McpUiHostContextChangedNotification,
2828
McpUiHostContextChangedNotificationSchema,
@@ -676,35 +676,35 @@ export class App extends Protocol<Request, Notification, Result> {
676676
}
677677

678678
/**
679-
* Send context updates to the host for storage in the agent's conversation context.
679+
* Send context updates to the host to be included in the agent's context.
680680
*
681-
* Unlike `sendLog` which is for debugging/telemetry, context updates are intended
682-
* to inform the agent about app state changes that should be available for future
683-
* reasoning without requiring a follow-up action (like `sendMessage`).
681+
* Unlike `sendLog`, which is for debugging/telemetry, context updates
682+
* are inteded to be available to the model in future reasoning,
683+
* without requiring a follow-up action (like `sendMessage`).
684684
*
685685
* @param params - Context role and content (same structure as ui/message)
686686
* @param options - Request options (timeout, etc.)
687687
*
688-
* @example Notify agent of significant state change
688+
* @example Update model context with current app state
689689
* ```typescript
690-
* await app.sendUpdateContext({
690+
* await app.sendUpdateModelContext({
691691
* role: "user",
692692
* content: [{ type: "text", text: "User selected 3 items totaling $150.00" }]
693693
* });
694694
* ```
695695
*
696696
* @returns Promise that resolves when the context update is acknowledged
697697
*/
698-
sendUpdateContext(
699-
params: McpUiUpdateContextRequest["params"],
698+
sendUpdateModelContext(
699+
params: McpUiUpdateModelContextRequest["params"],
700700
options?: RequestOptions,
701701
) {
702702
return this.request(
703-
<McpUiUpdateContextRequest>{
704-
method: "ui/update-context",
703+
<McpUiUpdateModelContextRequest>{
704+
method: "ui/update-model-context",
705705
params,
706706
},
707-
McpUiUpdateContextResultSchema,
707+
McpUiUpdateModelContextResultSchema,
708708
options,
709709
);
710710
}

0 commit comments

Comments
 (0)