MCP Academy · Lesson

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

  1. Send Progress for Long Tasks
  2. Handle Cancellation Requests
  3. Structured Logging to the Client
  4. Set Log Levels at Runtime
← Back to MCP Academy