Skip to content

Commit e4b43eb

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

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ private Publisher<Void> createDelete(String sessionId) {
177177
.uri(uri)
178178
.header("Cache-Control", "no-cache")
179179
.header(HttpHeaders.MCP_SESSION_ID, sessionId)
180-
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
180+
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
181181
.DELETE();
182182
var transportContext = ctx.getOrDefault(McpTransportContext.KEY, McpTransportContext.EMPTY);
183183
return Mono.from(this.httpRequestCustomizer.customize(builder, "DELETE", uri, null, transportContext));
@@ -248,7 +248,7 @@ private Mono<Disposable> reconnect(McpTransportStream<Disposable> stream) {
248248
var builder = requestBuilder.uri(uri)
249249
.header("Accept", TEXT_EVENT_STREAM)
250250
.header("Cache-Control", "no-cache")
251-
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
251+
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
252252
.GET();
253253
var transportContext = connectionCtx.getOrDefault(McpTransportContext.KEY, McpTransportContext.EMPTY);
254254
return Mono.from(this.httpRequestCustomizer.customize(builder, "GET", uri, null, transportContext));
@@ -423,7 +423,7 @@ public Mono<Void> sendMessage(McpSchema.JSONRPCMessage sentMessage) {
423423
.header("Accept", APPLICATION_JSON + ", " + TEXT_EVENT_STREAM)
424424
.header("Content-Type", APPLICATION_JSON)
425425
.header("Cache-Control", "no-cache")
426-
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
426+
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
427427
.POST(HttpRequest.BodyPublishers.ofString(jsonBody));
428428
var transportContext = ctx.getOrDefault(McpTransportContext.KEY, McpTransportContext.EMPTY);
429429
return Mono

mcp-core/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
}

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
@@ -148,7 +148,7 @@ private DefaultMcpTransportSession createTransportSession() {
148148
: webClient.delete()
149149
.uri(this.endpoint)
150150
.header(HttpHeaders.MCP_SESSION_ID, sessionId)
151-
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
151+
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
152152
.retrieve()
153153
.toBodilessEntity()
154154
.onErrorComplete(e -> {
@@ -208,7 +208,7 @@ private Mono<Disposable> reconnect(McpTransportStream<Disposable> stream) {
208208
Disposable connection = webClient.get()
209209
.uri(this.endpoint)
210210
.accept(MediaType.TEXT_EVENT_STREAM)
211-
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
211+
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
212212
.headers(httpHeaders -> {
213213
transportSession.sessionId().ifPresent(id -> httpHeaders.add(HttpHeaders.MCP_SESSION_ID, id));
214214
if (stream != null) {
@@ -274,7 +274,7 @@ public Mono<Void> sendMessage(McpSchema.JSONRPCMessage message) {
274274
Disposable connection = webClient.post()
275275
.uri(this.endpoint)
276276
.accept(MediaType.APPLICATION_JSON, MediaType.TEXT_EVENT_STREAM)
277-
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
277+
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
278278
.headers(httpHeaders -> {
279279
transportSession.sessionId().ifPresent(id -> httpHeaders.add(HttpHeaders.MCP_SESSION_ID, id));
280280
})

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
@@ -247,7 +247,7 @@ public Mono<Void> sendMessage(JSONRPCMessage message) {
247247
return webClient.post()
248248
.uri(messageEndpointUri)
249249
.contentType(MediaType.APPLICATION_JSON)
250-
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
250+
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
251251
.bodyValue(jsonText)
252252
.retrieve()
253253
.toBodilessEntity()
@@ -280,7 +280,7 @@ protected Flux<ServerSentEvent<String>> eventStream() {// @formatter:off
280280
.get()
281281
.uri(this.sseEndpoint)
282282
.accept(MediaType.TEXT_EVENT_STREAM)
283-
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
283+
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
284284
.retrieve()
285285
.bodyToFlux(SSE_TYPE)
286286
.retryWhen(Retry.from(retrySignal -> retrySignal.handle(inboundRetryHandler)));

0 commit comments

Comments
 (0)