Handle Cancellation Requests
Stop work cleanly when the client cancels.
Why Cancellation Exists
A user may close a chat or change their mind while a long tool runs. MCP lets the client send a cancellation so wasted work stops.
The cancelled Notification
The client signals this with a notifications/cancelled message naming the requestId it wants to stop. It is fire-and-forget, with no reply.
{"method": "notifications/cancelled",
"params": {"requestId": 7, "reason": "user aborted"}}All lessons in this course
- Send Progress for Long Tasks
- Handle Cancellation Requests
- Structured Logging to the Client
- Set Log Levels at Runtime