Skip to content

Commit e700236

Browse files
committed
Use MCP_PROTOCOL_VERSION to align with MCP_SESSION_ID
Signed-off-by: Yanming Zhou <[email protected]>
1 parent 5e035ea commit e700236

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ private DefaultMcpTransportSession createTransportSession() {
143143
Function<String, Publisher<Void>> onClose = sessionId -> sessionId == null ? Mono.empty()
144144
: webClient.delete()
145145
.uri(this.endpoint)
146-
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
146+
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
147147
.headers(httpHeaders -> {
148148
httpHeaders.add(HttpHeaders.MCP_SESSION_ID, sessionId);
149-
httpHeaders.add(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION);
149+
httpHeaders.add(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION);
150150
})
151151
.retrieve()
152152
.toBodilessEntity()
@@ -207,7 +207,7 @@ private Mono<Disposable> reconnect(McpTransportStream<Disposable> stream) {
207207
Disposable connection = webClient.get()
208208
.uri(this.endpoint)
209209
.accept(MediaType.TEXT_EVENT_STREAM)
210-
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
210+
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
211211
.headers(httpHeaders -> {
212212
transportSession.sessionId().ifPresent(id -> httpHeaders.add(HttpHeaders.MCP_SESSION_ID, id));
213213
if (stream != null) {
@@ -268,7 +268,7 @@ public Mono<Void> sendMessage(McpSchema.JSONRPCMessage message) {
268268
Disposable connection = webClient.post()
269269
.uri(this.endpoint)
270270
.accept(MediaType.APPLICATION_JSON, MediaType.TEXT_EVENT_STREAM)
271-
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
271+
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
272272
.headers(httpHeaders -> {
273273
transportSession.sessionId().ifPresent(id -> httpHeaders.add(HttpHeaders.MCP_SESSION_ID, id));
274274
})

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)