go-sdk/internal/jsonrpc2
Repository files (latest commit first)
Filename Latest commit message Latest commit date
José M. Requena Plens 3210c2b34c
mcp: carry a cancelled notification's reason as the request's cancel cause (#1255)
The canceller read `CancelledParams.Reason` off the wire and dropped it:
`Connection.Cancel` cancelled the request's context with a nil cause, so
a handler that looked at `context.Cause` saw a bare `context.Canceled`
and nothing of what the peer said. The specification asks
implementations to log cancellation reasons, and the handler is the one
place that can act on one; #1100 had already given the request context a
cause, so the reason has a natural place to travel.

`Connection.CancelCause` is `Cancel` with a cause. The canceller now
cancels with an error that carries the peer's reason and unwraps to
`context.Canceled`, so `errors.Is` keeps classifying the cancellation as
one while `context.Cause` reads `request cancelled by the peer:
<reason>`. It also logs the id and the reason at debug level through the
logger the connection already carries, which is the SDK's own answer to
the SHOULD. No exported API changes: the cause type stays unexported and
is read through `context.Cause` and `Error()`.

`TestCancellation` now asserts the cause the SDK's own client produces
(its context's error, which the client sends as the reason), and
`TestCancellationReason` writes the call and the cancelled notification
to the connection directly with a reason the client would never send, on
a session pinned to 2025-11-25 so the hand-written request needs no
`_meta`. Both fail without the change.

Fixes #1254

Co-authored-by: Guglielmo Colombo <guglielmoc@google.com>
2026-09-14 11:33:30 +00:00
..
conn.go mcp: carry a cancelled notification's reason as the request's cancel cause (#1255) 2026-09-14 11:33:30 +00:00
conn_test.go jsonrpc2: wrap write error in server-closing error (#1186) 2026-08-27 14:12:53 +00:00
jsonrpc2.go internal/jsonrpc2: remove unused code (#910) 2026-04-28 09:56:15 +02:00
messages.go fix(jsonrpc2): decode requests when method key is present (#1000) 2026-06-16 09:57:18 +02:00
wire.go internal/jsonrpc2: test WireError.Is and fix nil target panic (#1079) 2026-08-21 10:56:31 +02:00
wire_test.go internal/jsonrpc2: test WireError.Is and fix nil target panic (#1079) 2026-08-21 10:56:31 +02:00