feat: implement ui/notifications/tool-cancelled + add missing App.onteardown - #120
Merged
Merged
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: |
ochafik
marked this pull request as ready for review
December 10, 2025 02:30
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>
idosal
reviewed
Dec 10, 2025
| return () => { | ||
| if (appBridgeRef.current) { | ||
| log.info("Sending teardown notification to MCP App"); | ||
| appBridgeRef.current.sendResourceTeardown({}).catch((err) => { |
Contributor
There was a problem hiding this comment.
@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).)
Contributor
Author
There was a problem hiding this comment.
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>
idosal
approved these changes
Dec 11, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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