Skip to content

Commit c4d7582

Browse files
Align spec terminology to teardown/termination instead of close/clearnup
1 parent 9a71800 commit c4d7582

9 files changed

Lines changed: 89 additions & 96 deletions

File tree

specification/draft/apps.mdx

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,9 +1285,11 @@ Host MUST send this notification if the tool execution was cancelled, for any re
12851285
}
12861286
```
12871287

1288-
Host MUST send this notification before tearing down the UI resource, for any reason, including user action, resource re-allocation, etc. The Host MAY specify the reason.
1288+
Host MUST send this notification before tearing down the UI resource, for any reason, including user action, view-initiated teardown, resource re-allocation, etc. The Host MAY specify the reason.
12891289
Host SHOULD wait for a response before tearing down the resource (to prevent data loss).
12901290

1291+
#### Notifications (View → Host)
1292+
12911293
`ui/notifications/size-changed` - View's size changed
12921294

12931295
```typescript
@@ -1303,30 +1305,25 @@ Host SHOULD wait for a response before tearing down the resource (to prevent dat
13031305

13041306
The View SHOULD send this notification when rendered content body size changes (e.g. using ResizeObserver API to report up to date size).
13051307

1306-
#### Notifications (View → Host)
1307-
1308-
`ui/notifications/request-close` - View requests host to close it
1308+
`ui/notifications/request-teardown` - View requests host to tear it down
13091309

13101310
```typescript
13111311
{
13121312
jsonrpc: "2.0",
1313-
method: "ui/notifications/request-close",
1313+
method: "ui/notifications/request-teardown",
13141314
params: {}
13151315
}
13161316
```
13171317

1318-
The View MAY send this notification to request that the host close it. This enables View-initiated close flows (e.g., user clicks a "Done" button in the View).
1318+
The View MAY send this notification to request that the host tear it down. This enables View-initiated teardown flows (e.g., user clicks a "Done" button in the View).
13191319

13201320
**Host behavior:**
1321-
- Host decides whether to proceed with the close
1322-
- If approved, Host MUST send `ui/resource-teardown` to allow the View to perform cleanup
1323-
- Host MUST wait for the View's teardown response before unmounting the iframe
1324-
- Host MAY deny or defer the close request (e.g., if there are unsaved changes elsewhere)
1321+
- Host decides whether to proceed with the teardown
1322+
- If the Host accepts the request, it MUST follow the graceful termination process by sending `ui/resource-teardown` to the View. The Host SHOULD wait for a response before tearing down the resource (to prevent data loss).
13251323

13261324
**View behavior:**
1327-
- View SHOULD NOT perform cleanup before sending this notification
1328-
- View SHOULD handle cleanup in its `ui/resource-teardown` handler
1329-
- This ensures the View has a single cleanup procedure regardless of whether the close was initiated by the View or the Host
1325+
- View MAY persist unsaved state before sending this notification. processes MUST be completed before responding to `ui/resource-teardown` Host request.
1326+
- View SHOULD NOT teardown its UI and assume it's going to be removed when sending this notification. Final teardown decision and timing remains Host responsibility.
13301327

13311328
`ui/notifications/host-context-changed` - Host context has changed
13321329

@@ -1480,24 +1477,24 @@ sequenceDiagram
14801477
end
14811478
```
14821479

1483-
#### 4. Cleanup
1480+
#### 4. Teardown
14841481

1485-
Cleanup can be initiated by either the Host or the View. In both cases, the Host sends `ui/resource-teardown` to allow the View to perform cleanup before unmounting.
1482+
The Host can tear down Views. Views may request teardown by sending `ui/notifications/request-teardown` to the Host. In any case, the Host MUST send `ui/resource-teardown` to allow the View to terminate gracefully.
14861483

14871484
```mermaid
14881485
sequenceDiagram
14891486
participant H as Host
14901487
participant UI as View (iframe)
1491-
opt View-initiated close
1492-
UI ->> H: ui/notifications/request-close
1488+
opt View-initiated teardown
1489+
UI ->> H: ui/notifications/request-teardown
14931490
end
14941491
H ->> UI: ui/resource-teardown
14951492
UI --> UI: Graceful termination
14961493
UI -->> H: ui/resource-teardown response
14971494
H -x H: Tear down iframe and listeners
14981495
```
14991496

1500-
Note: Cleanup may be triggered at any point in the lifecycle following View initialization. If the View sends `ui/notifications/request-close`, the Host MAY deny or defer the request.
1497+
Note: Teardown may be triggered at any point in the lifecycle following View initialization.
15011498

15021499
#### Key Differences from Pre-SEP MCP-UI:
15031500

src/app-bridge.test.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -521,30 +521,26 @@ describe("App <-> AppBridge integration", () => {
521521
).rejects.toThrow("Context update failed");
522522
});
523523

524-
it("app.requestClose allows host to initiate teardown flow", async () => {
524+
it("app.requestTeardown allows host to initiate teardown flow", async () => {
525525
const events: string[] = [];
526526

527-
// Host handles close request by initiating teardown
528-
bridge.onrequestclose = async () => {
529-
events.push("close-requested");
530-
// Host decides to proceed with close - initiate teardown
527+
bridge.onrequestteardown = async () => {
528+
events.push("teardown-requested");
531529
await bridge.teardownResource({});
532530
events.push("teardown-complete");
533531
};
534532

535-
// App handles teardown (cleanup before unmount)
536533
app.onteardown = async () => {
537534
events.push("app-cleanup");
538535
return {};
539536
};
540537

541538
await app.connect(appTransport);
542-
await app.requestClose();
539+
await app.requestTeardown();
543540
await flush();
544541

545-
// Verify the full flow: request → teardown → cleanup
546542
expect(events).toEqual([
547-
"close-requested",
543+
"teardown-requested",
548544
"app-cleanup",
549545
"teardown-complete",
550546
]);

src/app-bridge.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ import {
7474
McpUiDownloadFileResult,
7575
McpUiResourceTeardownRequest,
7676
McpUiResourceTeardownResultSchema,
77-
McpUiRequestCloseNotification,
78-
McpUiRequestCloseNotificationSchema,
77+
McpUiRequestTeardownNotification,
78+
McpUiRequestTeardownNotificationSchema,
7979
McpUiSandboxProxyReadyNotification,
8080
McpUiSandboxProxyReadyNotificationSchema,
8181
McpUiSizeChangedNotificationSchema,
@@ -676,20 +676,20 @@ export class AppBridge extends Protocol<
676676
}
677677

678678
/**
679-
* Register a handler for app-initiated close request notifications from the view.
679+
* Register a handler for app-initiated teardown request notifications from the view.
680680
*
681-
* The view sends `ui/notifications/request-close` when it wants the host to close it.
682-
* If the host decides to proceed with the close, it should send
681+
* The view sends `ui/notifications/request-teardown` when it wants the host to tear it down.
682+
* If the host decides to proceed, it should send
683683
* `ui/resource-teardown` (via {@link teardownResource `teardownResource`}) to allow
684684
* the view to perform cleanup, then unmount the iframe after the view responds.
685685
*
686-
* @param callback - Handler that receives close request params
686+
* @param callback - Handler that receives teardown request params
687687
* - params - Empty object (reserved for future use)
688688
*
689689
* @example
690690
* ```typescript
691-
* bridge.onrequestclose = async (params) => {
692-
* console.log("App requested close");
691+
* bridge.onrequestteardown = async (params) => {
692+
* console.log("App requested teardown");
693693
* // Initiate teardown to allow the app to clean up
694694
* // Alternatively, the callback can early return to prevent teardown
695695
* await bridge.teardownResource({});
@@ -698,14 +698,14 @@ export class AppBridge extends Protocol<
698698
* };
699699
* ```
700700
*
701-
* @see {@link McpUiRequestCloseNotification `McpUiRequestCloseNotification`} for the notification type
701+
* @see {@link McpUiRequestTeardownNotification `McpUiRequestTeardownNotification`} for the notification type
702702
* @see {@link teardownResource `teardownResource`} for initiating teardown
703703
*/
704-
set onrequestclose(
705-
callback: (params: McpUiRequestCloseNotification["params"]) => void,
704+
set onrequestteardown(
705+
callback: (params: McpUiRequestTeardownNotification["params"]) => void,
706706
) {
707707
this.setNotificationHandler(
708-
McpUiRequestCloseNotificationSchema,
708+
McpUiRequestTeardownNotificationSchema,
709709
(request) => callback(request.params),
710710
);
711711
}

src/app.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import {
4444
McpUiResourceTeardownRequest,
4545
McpUiResourceTeardownRequestSchema,
4646
McpUiResourceTeardownResult,
47-
McpUiRequestCloseNotification,
47+
McpUiRequestTeardownNotification,
4848
McpUiSizeChangedNotification,
4949
McpUiToolCancelledNotification,
5050
McpUiToolCancelledNotificationSchema,
@@ -1136,45 +1136,45 @@ export class App extends Protocol<AppRequest, AppNotification, AppResult> {
11361136
}
11371137

11381138
/**
1139-
* Request the host to close this app.
1139+
* Request the host to tear down this app.
11401140
*
1141-
* Apps call this method to request that the host close them. The host decides
1142-
* whether to proceed with the close - if approved, the host will send
1141+
* Apps call this method to request that the host tear them down. The host
1142+
* decides whether to proceed - if approved, the host will send
11431143
* `ui/resource-teardown` to allow the app to perform cleanup before being
11441144
* unmounted. This piggybacks on the existing teardown mechanism, ensuring
11451145
* the app only needs a single shutdown procedure (via {@link onteardown `onteardown`})
1146-
* regardless of whether the close was initiated by the app or the host.
1146+
* regardless of whether the teardown was initiated by the app or the host.
11471147
*
11481148
* This is a fire-and-forget notification - no response is expected.
1149-
* If the host approves the close, the app will receive a `ui/resource-teardown`
1149+
* If the host approves, the app will receive a `ui/resource-teardown`
11501150
* request via the {@link onteardown `onteardown`} handler to perform cleanup.
11511151
*
11521152
* @param params - Empty params object (reserved for future use)
11531153
* @returns Promise that resolves when the notification is sent
11541154
*
1155-
* @example App-initiated close after user action
1155+
* @example App-initiated teardown after user action
11561156
* ```typescript
11571157
* // User clicks "Done" button in the app
11581158
* async function handleDoneClick() {
1159-
* // Request the host to close the app
1160-
* await app.requestClose();
1159+
* // Request the host to tear down the app
1160+
* await app.requestTeardown();
11611161
* // If host approves, onteardown handler will be called for cleanup
11621162
* }
11631163
*
1164-
* // Set up teardown handler (called for both app-initiated and host-initiated close)
1164+
* // Set up teardown handler (called for both app-initiated and host-initiated teardown)
11651165
* app.onteardown = async () => {
11661166
* await saveState();
11671167
* closeConnections();
11681168
* return {};
11691169
* };
11701170
* ```
11711171
*
1172-
* @see {@link McpUiRequestCloseNotification `McpUiRequestCloseNotification`} for notification structure
1172+
* @see {@link McpUiRequestTeardownNotification `McpUiRequestTeardownNotification`} for notification structure
11731173
* @see {@link onteardown `onteardown`} for the cleanup handler
11741174
*/
1175-
requestClose(params: McpUiRequestCloseNotification["params"] = {}) {
1176-
return this.notification(<McpUiRequestCloseNotification>{
1177-
method: "ui/notifications/request-close",
1175+
requestTeardown(params: McpUiRequestTeardownNotification["params"] = {}) {
1176+
return this.notification(<McpUiRequestTeardownNotification>{
1177+
method: "ui/notifications/request-teardown",
11781178
params,
11791179
});
11801180
}

src/generated/schema.json

Lines changed: 17 additions & 17 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: 6 additions & 6 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: 6 additions & 6 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: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -475,15 +475,15 @@ export interface McpUiSupportedContentBlockModalities {
475475
}
476476

477477
/**
478-
* @description Notification for app-initiated close request (View -> Host).
479-
* Views send this to request that the host close them. The host decides
480-
* whether to proceed with the close - if approved, the host will send
478+
* @description Notification for app-initiated teardown request (View -> Host).
479+
* Views send this to request that the host tear them down. The host decides
480+
* whether to proceed - if approved, the host will send
481481
* `ui/resource-teardown` to allow the view to perform cleanup before being
482482
* unmounted.
483-
* @see {@link app.App.requestClose} for the app method that sends this
483+
* @see {@link app.App.requestTeardown} for the app method that sends this
484484
*/
485-
export interface McpUiRequestCloseNotification {
486-
method: "ui/notifications/request-close";
485+
export interface McpUiRequestTeardownNotification {
486+
method: "ui/notifications/request-teardown";
487487
params?: {};
488488
}
489489

@@ -813,8 +813,8 @@ export const TOOL_CANCELLED_METHOD: McpUiToolCancelledNotification["method"] =
813813
"ui/notifications/tool-cancelled";
814814
export const HOST_CONTEXT_CHANGED_METHOD: McpUiHostContextChangedNotification["method"] =
815815
"ui/notifications/host-context-changed";
816-
export const REQUEST_CLOSE_METHOD: McpUiRequestCloseNotification["method"] =
817-
"ui/notifications/request-close";
816+
export const REQUEST_TEARDOWN_METHOD: McpUiRequestTeardownNotification["method"] =
817+
"ui/notifications/request-teardown";
818818
export const RESOURCE_TEARDOWN_METHOD: McpUiResourceTeardownRequest["method"] =
819819
"ui/resource-teardown";
820820
export const INITIALIZE_METHOD: McpUiInitializeRequest["method"] =

0 commit comments

Comments
 (0)