-
Notifications
You must be signed in to change notification settings - Fork 49
feat: implement ui/notifications/tool-cancelled + add missing App.onteardown #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Wire the tool-cancelled notification that hosts MUST send when tool execution is cancelled (user action, timeout, classifier intervention, etc.): - Add McpUiToolCancelledNotification type in spec.types.ts - Generate Zod schema via ts-to-zod - Add AppBridge.sendToolCancelled() method for hosts - Add App.ontoolcancelled setter for guest UIs - Export type and schema from types.ts - Add tests for notification with/without reason 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Wire the guest UI side of ui/resource-teardown request: - Add onteardown setter in App class for guest UIs to handle teardown - Allow ui/resource-teardown in assertRequestHandlerCapability - Import McpUiResourceTeardownRequest/Result types - Add tests for sync and async cleanup handlers 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
commit: |
Update basic-host example to properly use the new notifications: - Send sendToolCancelled when tool call promise rejects - Send sendResourceTeardown when React component unmounts - Store appBridge ref for cleanup access 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
examples/basic-host/src/index.tsx
Outdated
| return () => { | ||
| if (appBridgeRef.current) { | ||
| log.info("Sending teardown notification to MCP App"); | ||
| appBridgeRef.current.sendResourceTeardown({}).catch((err) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ochafik it's worth noting here that this doesn't actually wait for the UI to terminate gracefully before unmounting, which is against against the spec's recommendation (Host SHOULD wait for a response before tearing down the resource (to prevent data loss).)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Fixed in bf3b1b3 - the host now waits for the guest's teardown response before unmounting, per the spec recommendation.
Changes:
- Added close button (×) to tool call panels
- Two-phase unmount: clicking close sets
isDestroyingstate which dims the panel and disables pointer events sendResourceTeardown()completes (or errors) before the component is removed- Also handles edge case where user closes before bridge is ready
Demo apps now also have onteardown handlers with simulated 500ms cleanup to demonstrate the flow.
Address review feedback: the host now waits for guest's teardown response before unmounting, following the spec: "Host SHOULD wait for a response before tearing down the resource (to prevent data loss)." Changes: - Add close button to tool call panels - Two-phase unmount: isDestroying state dims panel and disables events - sendResourceTeardown() completes before component removal - Non-app tool results close immediately 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Demonstrate graceful shutdown with simulated 500ms cleanup work. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Summary
ui/notifications/tool-cancelledthroughout the SDK - hosts MUST send this when tool execution is cancelled (user action, timeout, classifier intervention, etc.)App.onteardownhandler for guest UIs to handle graceful shutdown requestsChanges
tool-cancelled notification
src/spec.types.tsMcpUiToolCancelledNotificationinterfacesrc/generated/schema.tssrc/app-bridge.tssendToolCancelled()src/app.tsontoolcancelledsettersrc/types.tssrc/app-bridge.test.tsonteardown handler
src/app.tsonteardownsettersrc/app.tsui/resource-teardownin request handlersrc/app-bridge.test.tsUsage
tool-cancelled (Host → Guest):
teardown (Host → Guest):
Test plan
🤖 Generated with Claude Code