From e2248b0f80517e94fead66dab6768ce5cf12755b Mon Sep 17 00:00:00 2001 From: Rob Findley Date: Fri, 9 May 2025 14:47:48 +0000 Subject: [PATCH] internal/mcp/design: add a section on cancellation Change-Id: If18a7d8efa37a6f34ae42f4d1896464800ebcdc7 Reviewed-on: https://go-review.googlesource.com/c/tools/+/671435 Reviewed-by: Jonathan Amsterdam LUCI-TryBot-Result: Go LUCI --- design/design.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/design/design.md b/design/design.md index 10e2fb3..c4b6637 100644 --- a/design/design.md +++ b/design/design.md @@ -420,7 +420,20 @@ func (*Server) Run(context.Context, Transport) ### Cancellation - +Cancellation is implemented transparently using context cancellation. The user +can cancel an operation by cancelling the associated context: + +```go +ctx, cancel := context.WithCancel(ctx) +go session.CallTool(ctx, "slow", map[string]any{}) +cancel() +``` + +When this client call is cancelled, a `"notifications/cancelled"` notification +is sent to the server. However, the client call returns immediately with +`ctx.Err()`: it does not wait for the result from the server. + +The server observes a client cancellation as cancelled context. ### Progress handling