What is MCP cancellation? Stopping a tool request
By Flavio
MCP cancellation asks a server to stop an active request. Learn how stdio and HTTP differ, how Claude Code stops tasks, and why completed effects remain.
MCP cancellation is a client’s request to stop work it has already started on an MCP server. The signal depends on the transport, and the server needs to handle it.
For a working example of cooperative stopping, see MCP Tasks and Elicitations in Claude Code. That tutorial keeps the task implementation and setup in one place.
How cancellation works
The current MCP cancellation specification distinguishes the transports.
With stdio, the client sends notifications/cancelled with the active request’s ID. With Streamable HTTP, closing the request’s SSE response stream signals cancellation.
Cancellation can race with completion. A server can receive the signal after the request has finished, or be unable to cancel the operation.
An MCP task has a separate task handle and uses tasks/cancel. Keep that handle separate from the original JSON-RPC request ID.
In coding tools
Claude Code lets you select a server task in /tasks and press x.
It stops following the task and asks the server to cancel. The server may still finish.
Codex documents tool_timeout_sec.
Cursor documents failed calls and MCP logs. Grok Build documents tool timeouts and server diagnostics. Those guides don’t describe an equivalent server-task cancellation interface.
Details checked against each vendor’s documentation in November 2026.
An example from the task tutorial
The simulated build checks for cancellation between steps:
if (await task.isCancelled()) return {}
The tutorial’s handler waits ten seconds per step, so stopping can take until the next check. Use the complete server to try it.
When to use it
Cancellation helps when a request is taking too long or you no longer need its result. When debugging a stuck call, check whether the server handles the stop signal and whether its underlying operation can stop too.
Pitfalls
Check what the tool already changed before retrying. A stop request leaves completed effects in place. For a purchase, the confirmation must happen before the billable action, as in the Cloudflare Domains Toolkit tutorial.
Related glossary entries
- MCP tasks: MCP tasks give long-running server operations an ID. Learn how clients follow progress, retrieve results, and handle cancellation in coding workflows.
- MCP progress notifications: MCP progress notifications report work during an active request. Learn what progressToken means, how updates differ from tasks, and how timeouts apply.
- MCP tool errors: MCP tool errors report failures inside a tool result. Learn how isError differs from a protocol error, with real validation and empty-search examples.
All AI glossary entries → · AI for coding hub →
Want me to talk about your product? You can sponsor this site.