Skip to content

Commit 225d9cf

Browse files
committed
feat(ext-apps): add widgetSessionId to spec
- Add McpUiToolResultMeta interface with widgetSessionId field - Document Widget Session Consolidation in apps.mdx spec - When multiple tool results share the same widgetSessionId, only the latest widget is displayed - Previous widgets are gracefully torn down via ui/resource-teardown
1 parent 8c3b1da commit 225d9cf

5 files changed

Lines changed: 96 additions & 0 deletions

File tree

specification/draft/apps.mdx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,44 @@ This pattern enables interactive, self-updating widgets.
14101410

14111411
Note: Tools with `visibility: ["app"]` are hidden from the agent but remain callable by apps via `tools/call`. This enables UI-only interactions (refresh buttons, form submissions) without exposing implementation details to the model. See the Visibility section under Resource Discovery for details.
14121412

1413+
### Widget Session Consolidation
1414+
1415+
When the same logical widget is updated multiple times during a conversation,
1416+
hosts can consolidate these into a single visible widget using `widgetSessionId`:
1417+
1418+
```typescript
1419+
{
1420+
content: [{ type: "text", text: "Cart updated" }],
1421+
structuredContent: { items: [...] },
1422+
_meta: {
1423+
ui: {
1424+
widgetSessionId: "user-cart-abc123"
1425+
}
1426+
}
1427+
}
1428+
```
1429+
1430+
**Host Behavior:**
1431+
1432+
1. When a tool result with `_meta.ui.widgetSessionId` is rendered
1433+
2. Find any earlier widgets in the conversation with the same `widgetSessionId`
1434+
3. Call `ui/resource-teardown` on superseded widgets (allows graceful cleanup)
1435+
4. Hide superseded widgets from the UI (model context unaffected)
1436+
5. Only the latest widget remains visible
1437+
1438+
**Use Cases:**
1439+
1440+
- Shopping cart that updates as items are added/removed
1441+
- Live data dashboards that refresh with new data
1442+
- Multi-step forms that show only the current state
1443+
1444+
**Implementation Notes:**
1445+
1446+
- Scope is conversation-wide (widgets persist across turns)
1447+
- Model context remains unaffected (all tool results still visible to model)
1448+
- Teardown allows apps to save state before being hidden
1449+
- Only applies to MCP App widgets (tools with `_meta.ui.resourceUri`)
1450+
14131451
### Client\<\>Server Capability Negotiation
14141452

14151453
Clients and servers negotiate MCP Apps support through the standard MCP extensions capability mechanism (defined in SEP-1724).

src/generated/schema.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/generated/schema.test.ts

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/generated/schema.ts

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/spec.types.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,22 @@ export interface McpUiToolMeta {
630630
visibility?: McpUiToolVisibility[];
631631
}
632632

633+
/**
634+
* @description UI-related metadata for tool results.
635+
* Used in CallToolResult._meta.ui to provide rendering hints to the host.
636+
*/
637+
export interface McpUiToolResultMeta {
638+
/**
639+
* @description Unique session identifier for widget consolidation.
640+
* When multiple tool results share the same widgetSessionId,
641+
* only the latest widget is displayed. Previous widgets are
642+
* gracefully torn down via ui/resource-teardown and hidden.
643+
*
644+
* @example "shopping-cart-session-123"
645+
*/
646+
widgetSessionId?: string;
647+
}
648+
633649
/**
634650
* Method string constants for MCP Apps protocol messages.
635651
*

0 commit comments

Comments
 (0)