|
20 | 20 | import java.util.function.Consumer; |
21 | 21 | import java.util.function.Function; |
22 | 22 |
|
| 23 | +import io.modelcontextprotocol.client.McpAsyncClient; |
23 | 24 | import io.modelcontextprotocol.client.transport.ResponseSubscribers.ResponseEvent; |
24 | 25 | import io.modelcontextprotocol.client.transport.customizer.McpAsyncHttpClientRequestCustomizer; |
25 | 26 | import io.modelcontextprotocol.client.transport.customizer.McpSyncHttpClientRequestCustomizer; |
@@ -193,7 +194,9 @@ private Publisher<Void> createDelete(String sessionId) { |
193 | 194 | .uri(uri) |
194 | 195 | .header("Cache-Control", "no-cache") |
195 | 196 | .header(HttpHeaders.MCP_SESSION_ID, sessionId) |
196 | | - .header(HttpHeaders.PROTOCOL_VERSION, this.latestSupportedProtocolVersion) |
| 197 | + .header(HttpHeaders.PROTOCOL_VERSION, |
| 198 | + ctx.getOrDefault(McpAsyncClient.NEGOTIATED_PROTOCOL_VERSION, |
| 199 | + this.latestSupportedProtocolVersion)) |
197 | 200 | .DELETE(); |
198 | 201 | var transportContext = ctx.getOrDefault(McpTransportContext.KEY, McpTransportContext.EMPTY); |
199 | 202 | return Mono.from(this.httpRequestCustomizer.customize(builder, "DELETE", uri, null, transportContext)); |
@@ -264,7 +267,9 @@ private Mono<Disposable> reconnect(McpTransportStream<Disposable> stream) { |
264 | 267 | var builder = requestBuilder.uri(uri) |
265 | 268 | .header(HttpHeaders.ACCEPT, TEXT_EVENT_STREAM) |
266 | 269 | .header("Cache-Control", "no-cache") |
267 | | - .header(HttpHeaders.PROTOCOL_VERSION, this.latestSupportedProtocolVersion) |
| 270 | + .header(HttpHeaders.PROTOCOL_VERSION, |
| 271 | + connectionCtx.getOrDefault(McpAsyncClient.NEGOTIATED_PROTOCOL_VERSION, |
| 272 | + this.latestSupportedProtocolVersion)) |
268 | 273 | .GET(); |
269 | 274 | var transportContext = connectionCtx.getOrDefault(McpTransportContext.KEY, McpTransportContext.EMPTY); |
270 | 275 | return Mono.from(this.httpRequestCustomizer.customize(builder, "GET", uri, null, transportContext)); |
@@ -439,7 +444,9 @@ public Mono<Void> sendMessage(McpSchema.JSONRPCMessage sentMessage) { |
439 | 444 | .header(HttpHeaders.ACCEPT, APPLICATION_JSON + ", " + TEXT_EVENT_STREAM) |
440 | 445 | .header(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON) |
441 | 446 | .header(HttpHeaders.CACHE_CONTROL, "no-cache") |
442 | | - .header(HttpHeaders.PROTOCOL_VERSION, this.latestSupportedProtocolVersion) |
| 447 | + .header(HttpHeaders.PROTOCOL_VERSION, |
| 448 | + ctx.getOrDefault(McpAsyncClient.NEGOTIATED_PROTOCOL_VERSION, |
| 449 | + this.latestSupportedProtocolVersion)) |
443 | 450 | .POST(HttpRequest.BodyPublishers.ofString(jsonBody)); |
444 | 451 | var transportContext = ctx.getOrDefault(McpTransportContext.KEY, McpTransportContext.EMPTY); |
445 | 452 | return Mono |
|
0 commit comments