How do I cancel an in-flight MCP tool call?
Send a notifications/cancelled notification naming the request’s id, with an optional reason string, over the same connection the request went out on. The receiver should stop processing right away, free whatever it was holding, and skip sending a response, and the sender should ignore any response that shows up anyway. Both are “should,” not a guarantee: the notification can arrive after the call already finished, so a response and a cancellation can cross in transit, and either side may ignore a cancellation naming a request it doesn’t recognize or can’t actually stop partway through.
The mechanism is identical on stdio and Streamable HTTP; there’s no separate cancel verb per transport. What doesn’t work is closing the connection and assuming that counts: the current spec says a dropped stream should not be read as a cancellation, since disconnects happen for reasons that have nothing to do with the caller wanting to stop. A timeout is the other half of not waiting forever. A server that ignores the cancellation and keeps working just looks slow rather than broken, which is the shape a call-site’s own duration history is built to catch.