Commit 8cd2d22
committed
Stop answering cancelled requests
When a peer sent notifications/cancelled for an in-flight request, the
dispatcher interrupted the handler and then answered the request anyway
with a synthesized JSON-RPC error, {"code": 0, "message": "Request
cancelled"} - a v1 carry-over pinned as a spec divergence. The
2026-07-28 transport rules say a cancelled request MUST NOT be answered,
and code 0 is not a valid JSON-RPC error code, so a cancelled request now
settles with no response at all: no result if the handler runs to
completion, no error if it fails. Both seats change (the server for
cancelled client requests, the client for cancelled server-initiated
ones).
The error frame had been doing a second job on the 2025-era streamable
HTTP wire, where each request's POST stays open until its response
arrives: it was what let the POST complete. So the dispatcher now tells
the transport when a request settles unanswered (an
on_request_unanswered hook on the inbound message metadata), and the
transport ends that request's stream on it - an empty 202 in
JSON-response mode, a cleanly-ended event stream in SSE mode - instead
of parking the POST until the session ends.
For the same reason the client transport now releases an abandoned
request's own POST at every protocol era, not just 2026-07-28: with no
response coming, a stream left open would sit parked, or - against an
event-store server - resume via Last-Event-ID for an answer that will
never exist. At 2025 the cancellation frame is still POSTed; only the
lingering stream goes away.
The built-in client's abandon and timeout paths never waited on that
error frame, so they are unaffected; a caller that hand-sends
notifications/cancelled while still awaiting a call now waits rather
than receiving the code-0 error, which docs/migration.md notes.1 parent e8ef138 commit 8cd2d22
12 files changed
Lines changed: 439 additions & 241 deletions
File tree
- docs
- src/mcp
- client
- server
- tests
- client
- interaction
- lowlevel
- transports
- server
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1584 | 1584 | | |
1585 | 1585 | | |
1586 | 1586 | | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
1587 | 1595 | | |
1588 | 1596 | | |
1589 | 1597 | | |
| |||
1933 | 1941 | | |
1934 | 1942 | | |
1935 | 1943 | | |
1936 | | - | |
| 1944 | + | |
1937 | 1945 | | |
1938 | | - | |
| 1946 | + | |
1939 | 1947 | | |
1940 | 1948 | | |
1941 | 1949 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
| 105 | + | |
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
110 | | - | |
| 109 | + | |
| 110 | + | |
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| |||
268 | 268 | | |
269 | 269 | | |
270 | 270 | | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
285 | 283 | | |
286 | 284 | | |
287 | 285 | | |
288 | 286 | | |
289 | 287 | | |
290 | 288 | | |
291 | 289 | | |
292 | | - | |
293 | | - | |
294 | 290 | | |
295 | 291 | | |
296 | | - | |
| 292 | + | |
297 | 293 | | |
298 | 294 | | |
299 | 295 | | |
| |||
302 | 298 | | |
303 | 299 | | |
304 | 300 | | |
305 | | - | |
| 301 | + | |
306 | 302 | | |
307 | 303 | | |
308 | 304 | | |
| |||
548 | 544 | | |
549 | 545 | | |
550 | 546 | | |
551 | | - | |
| 547 | + | |
552 | 548 | | |
553 | 549 | | |
554 | 550 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
| 265 | + | |
| 266 | + | |
265 | 267 | | |
| 268 | + | |
266 | 269 | | |
267 | 270 | | |
268 | 271 | | |
| |||
276 | 279 | | |
277 | 280 | | |
278 | 281 | | |
| 282 | + | |
279 | 283 | | |
280 | 284 | | |
281 | | - | |
| 285 | + | |
282 | 286 | | |
283 | 287 | | |
284 | 288 | | |
| |||
390 | 394 | | |
391 | 395 | | |
392 | 396 | | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
393 | 407 | | |
394 | 408 | | |
395 | 409 | | |
| |||
555 | 569 | | |
556 | 570 | | |
557 | 571 | | |
558 | | - | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
559 | 576 | | |
560 | 577 | | |
561 | 578 | | |
| |||
573 | 590 | | |
574 | 591 | | |
575 | 592 | | |
576 | | - | |
577 | 593 | | |
578 | 594 | | |
579 | 595 | | |
580 | | - | |
581 | | - | |
582 | | - | |
583 | | - | |
584 | | - | |
585 | | - | |
586 | | - | |
587 | | - | |
588 | | - | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
589 | 602 | | |
590 | 603 | | |
591 | 604 | | |
| |||
0 commit comments