Commit 009c16d
Gorre Surya
fix: use negotiated protocol version in GET SSE reconnect after initialize
When the server negotiates down to an older protocol version during the
initialize handshake, the subsequent GET request to open the SSE stream
was still sending the client's latest supported version in the
MCP-Protocol-Version header. This caused servers that strictly validate
the header (e.g. rmcp) to reject the GET with 400 Bad Request.
Root cause: the GET reconnect is triggered inside sendMessage() via
reconnect(null).contextWrite(deliveredSink.contextView()) at the point
where markInitialized() returns true. At that moment the Reactor context
has not yet been populated with NEGOTIATED_PROTOCOL_VERSION by
LifecycleInitializer (which runs after sendMessage() completes), so
reconnect() falls back to latestSupportedProtocolVersion.
Fix: add a negotiatedProtocolVersion AtomicReference to the transport.
When markInitialized() returns true, extract the protocolVersion from
the initialize response body (available in the AggregateResponseEvent or
SseResponseEvent) and store it. The reconnect() method then uses this
stored value as a fallback when the Reactor context is not yet populated,
which covers the initial GET reconnect. Subsequent reconnects continue
to read from the context as before.
The existing usesServerSupportedVersion integration test, which had a
FIXME acknowledging the bug, now also verifies the GET request uses the
negotiated version.
Fixes #8831 parent c00b87d commit 009c16d
2 files changed
Lines changed: 52 additions & 7 deletions
File tree
- mcp-core/src/main/java/io/modelcontextprotocol/client/transport
- mcp-test/src/test/java/io/modelcontextprotocol/common
Lines changed: 49 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
136 | 137 | | |
137 | 138 | | |
138 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
139 | 148 | | |
140 | 149 | | |
141 | 150 | | |
| |||
277 | 286 | | |
278 | 287 | | |
279 | 288 | | |
280 | | - | |
| 289 | + | |
| 290 | + | |
281 | 291 | | |
282 | 292 | | |
283 | 293 | | |
| |||
450 | 460 | | |
451 | 461 | | |
452 | 462 | | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
453 | 496 | | |
454 | 497 | | |
455 | 498 | | |
| |||
514 | 557 | | |
515 | 558 | | |
516 | 559 | | |
517 | | - | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
518 | 565 | | |
519 | 566 | | |
520 | 567 | | |
| |||
Lines changed: 3 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
111 | 109 | | |
112 | 110 | | |
113 | 111 | | |
| |||
0 commit comments