Skip to content

Commit 1076b7d

Browse files
ochafikclaude
andcommitted
feat(examples): add onteardown handlers to demo apps
Demonstrate graceful shutdown with simulated 500ms cleanup work. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent bf3b1b3 commit 1076b7d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

examples/basic-server-react/src/mcp-app.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @file App that demonstrates a few features using MCP Apps SDK + React.
33
*/
4-
import type { App } from "@modelcontextprotocol/ext-apps";
4+
import type { App, McpUiResourceTeardownResult } from "@modelcontextprotocol/ext-apps";
55
import { useApp } from "@modelcontextprotocol/ext-apps/react";
66
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
77
import { StrictMode, useCallback, useEffect, useState } from "react";
@@ -35,6 +35,12 @@ function GetTimeApp() {
3535
appInfo: IMPLEMENTATION,
3636
capabilities: {},
3737
onAppCreated: (app) => {
38+
app.onteardown = async () => {
39+
log.info("App is being torn down");
40+
await new Promise((resolve) => setTimeout(resolve, 500)); // Simulate cleanup work
41+
log.info("App teardown complete");
42+
return {};
43+
};
3844
app.ontoolinput = async (input) => {
3945
log.info("Received tool call input:", input);
4046
};

examples/basic-server-vanillajs/src/mcp-app.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ const openLinkBtn = document.getElementById("open-link-btn")!;
3838
// Create app instance
3939
const app = new App({ name: "Get Time App", version: "1.0.0" });
4040

41+
app.onteardown = async () => {
42+
log.info("App is being torn down");
43+
await new Promise((resolve) => setTimeout(resolve, 500)); // Simulate cleanup work
44+
log.info("App teardown complete");
45+
return {};
46+
};
4147

4248
// Register handlers BEFORE connecting
4349
app.ontoolinput = (params) => {

0 commit comments

Comments
 (0)