Skip to content

Commit 881bc83

Browse files
committed
Use MCP_PROTOCOL_VERSION to align with MCP_SESSION_ID
Signed-off-by: Yanming Zhou <[email protected]>
1 parent 110a8d1 commit 881bc83

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebClientStreamableHttpTransport.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private DefaultMcpTransportSession createTransportSession() {
144144
: webClient.delete()
145145
.uri(this.endpoint)
146146
.header(HttpHeaders.MCP_SESSION_ID, sessionId)
147-
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
147+
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
148148
.retrieve()
149149
.toBodilessEntity()
150150
.onErrorComplete(e -> {
@@ -204,7 +204,7 @@ private Mono<Disposable> reconnect(McpTransportStream<Disposable> stream) {
204204
Disposable connection = webClient.get()
205205
.uri(this.endpoint)
206206
.accept(MediaType.TEXT_EVENT_STREAM)
207-
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
207+
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
208208
.headers(httpHeaders -> {
209209
transportSession.sessionId().ifPresent(id -> httpHeaders.add(HttpHeaders.MCP_SESSION_ID, id));
210210
if (stream != null) {
@@ -265,7 +265,7 @@ public Mono<Void> sendMessage(McpSchema.JSONRPCMessage message) {
265265
Disposable connection = webClient.post()
266266
.uri(this.endpoint)
267267
.accept(MediaType.APPLICATION_JSON, MediaType.TEXT_EVENT_STREAM)
268-
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
268+
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
269269
.headers(httpHeaders -> {
270270
transportSession.sessionId().ifPresent(id -> httpHeaders.add(HttpHeaders.MCP_SESSION_ID, id));
271271
})

mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebFluxSseClientTransport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public Mono<Void> sendMessage(JSONRPCMessage message) {
262262
return webClient.post()
263263
.uri(messageEndpointUri)
264264
.contentType(MediaType.APPLICATION_JSON)
265-
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
265+
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
266266
.bodyValue(jsonText)
267267
.retrieve()
268268
.toBodilessEntity()
@@ -295,7 +295,7 @@ protected Flux<ServerSentEvent<String>> eventStream() {// @formatter:off
295295
.get()
296296
.uri(this.sseEndpoint)
297297
.accept(MediaType.TEXT_EVENT_STREAM)
298-
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
298+
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
299299
.retrieve()
300300
.bodyToFlux(SSE_TYPE)
301301
.retryWhen(Retry.from(retrySignal -> retrySignal.handle(inboundRetryHandler)));

mcp/src/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ private Publisher<Void> createDelete(String sessionId) {
173173
.uri(uri)
174174
.header("Cache-Control", "no-cache")
175175
.header(HttpHeaders.MCP_SESSION_ID, sessionId)
176-
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
176+
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
177177
.DELETE();
178178
return Mono.from(this.httpRequestCustomizer.customize(builder, "DELETE", uri, null));
179179
}).flatMap(requestBuilder -> {
@@ -243,7 +243,7 @@ private Mono<Disposable> reconnect(McpTransportStream<Disposable> stream) {
243243
var builder = requestBuilder.uri(uri)
244244
.header("Accept", TEXT_EVENT_STREAM)
245245
.header("Cache-Control", "no-cache")
246-
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
246+
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
247247
.GET();
248248
return Mono.from(this.httpRequestCustomizer.customize(builder, "GET", uri, null));
249249
})
@@ -398,7 +398,7 @@ public Mono<Void> sendMessage(McpSchema.JSONRPCMessage sentMessage) {
398398
.header("Accept", APPLICATION_JSON + ", " + TEXT_EVENT_STREAM)
399399
.header("Content-Type", APPLICATION_JSON)
400400
.header("Cache-Control", "no-cache")
401-
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
401+
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
402402
.POST(HttpRequest.BodyPublishers.ofString(jsonBody));
403403
return Mono.from(this.httpRequestCustomizer.customize(builder, "GET", uri, jsonBody));
404404
}).flatMapMany(requestBuilder -> Flux.<ResponseEvent>create(responseEventSink -> {

mcp/src/main/java/io/modelcontextprotocol/spec/HttpHeaders.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Names of HTTP headers in use by MCP HTTP transports.
99
*
1010
* @author Dariusz Jędrzejczyk
11+
* @author Yanming Zhou
1112
*/
1213
public interface HttpHeaders {
1314

@@ -16,14 +17,21 @@ public interface HttpHeaders {
1617
*/
1718
String MCP_SESSION_ID = "mcp-session-id";
1819

20+
/**
21+
* Identifies the MCP protocol version.
22+
*/
23+
String MCP_PROTOCOL_VERSION = "MCP-Protocol-Version";
24+
1925
/**
2026
* Identifies events within an SSE Stream.
2127
*/
2228
String LAST_EVENT_ID = "Last-Event-ID";
2329

2430
/**
2531
* Identifies the MCP protocol version.
32+
* @deprecated use {@link MCP_PROTOCOL_VERSION} instead
2633
*/
27-
String PROTOCOL_VERSION = "MCP-Protocol-Version";
34+
@Deprecated(forRemoval = true)
35+
String PROTOCOL_VERSION = MCP_PROTOCOL_VERSION;
2836

2937
}

0 commit comments

Comments
 (0)