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 <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Rob Findley 2025-05-09 14:47:48 +00:00 • committed by Robert Findley
commit e2248b0f80

View file

@ -420,7 +420,20 @@ func (*Server) Run(context.Context, Transport)
### Cancellation
<!-- TODO: a brief section discussing how cancellation is handled. -->
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