Skip to content

Use MCP_PROTOCOL_VERSION to align with MCP_SESSION_ID #447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private DefaultMcpTransportSession createTransportSession() {
: webClient.delete()
.uri(this.endpoint)
.header(HttpHeaders.MCP_SESSION_ID, sessionId)
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
.retrieve()
.toBodilessEntity()
.onErrorComplete(e -> {
Expand Down Expand Up @@ -204,7 +204,7 @@ private Mono<Disposable> reconnect(McpTransportStream<Disposable> stream) {
Disposable connection = webClient.get()
.uri(this.endpoint)
.accept(MediaType.TEXT_EVENT_STREAM)
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
.headers(httpHeaders -> {
transportSession.sessionId().ifPresent(id -> httpHeaders.add(HttpHeaders.MCP_SESSION_ID, id));
if (stream != null) {
Expand Down Expand Up @@ -265,7 +265,7 @@ public Mono<Void> sendMessage(McpSchema.JSONRPCMessage message) {
Disposable connection = webClient.post()
.uri(this.endpoint)
.accept(MediaType.APPLICATION_JSON, MediaType.TEXT_EVENT_STREAM)
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
.headers(httpHeaders -> {
transportSession.sessionId().ifPresent(id -> httpHeaders.add(HttpHeaders.MCP_SESSION_ID, id));
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public Mono<Void> sendMessage(JSONRPCMessage message) {
return webClient.post()
.uri(messageEndpointUri)
.contentType(MediaType.APPLICATION_JSON)
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
.bodyValue(jsonText)
.retrieve()
.toBodilessEntity()
Expand Down Expand Up @@ -295,7 +295,7 @@ protected Flux<ServerSentEvent<String>> eventStream() {// @formatter:off
.get()
.uri(this.sseEndpoint)
.accept(MediaType.TEXT_EVENT_STREAM)
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
.retrieve()
.bodyToFlux(SSE_TYPE)
.retryWhen(Retry.from(retrySignal -> retrySignal.handle(inboundRetryHandler)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private Publisher<Void> createDelete(String sessionId) {
.uri(uri)
.header("Cache-Control", "no-cache")
.header(HttpHeaders.MCP_SESSION_ID, sessionId)
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
.DELETE();
return Mono.from(this.httpRequestCustomizer.customize(builder, "DELETE", uri, null));
}).flatMap(requestBuilder -> {
Expand Down Expand Up @@ -243,7 +243,7 @@ private Mono<Disposable> reconnect(McpTransportStream<Disposable> stream) {
var builder = requestBuilder.uri(uri)
.header("Accept", TEXT_EVENT_STREAM)
.header("Cache-Control", "no-cache")
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
.GET();
return Mono.from(this.httpRequestCustomizer.customize(builder, "GET", uri, null));
})
Expand Down Expand Up @@ -398,7 +398,7 @@ public Mono<Void> sendMessage(McpSchema.JSONRPCMessage sentMessage) {
.header("Accept", APPLICATION_JSON + ", " + TEXT_EVENT_STREAM)
.header("Content-Type", APPLICATION_JSON)
.header("Cache-Control", "no-cache")
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
.header(HttpHeaders.MCP_PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
.POST(HttpRequest.BodyPublishers.ofString(jsonBody));
return Mono.from(this.httpRequestCustomizer.customize(builder, "GET", uri, jsonBody));
}).flatMapMany(requestBuilder -> Flux.<ResponseEvent>create(responseEventSink -> {
Expand Down
10 changes: 9 additions & 1 deletion mcp/src/main/java/io/modelcontextprotocol/spec/HttpHeaders.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Names of HTTP headers in use by MCP HTTP transports.
*
* @author Dariusz Jędrzejczyk
* @author Yanming Zhou
*/
public interface HttpHeaders {

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

/**
* Identifies the MCP protocol version.
*/
String MCP_PROTOCOL_VERSION = "MCP-Protocol-Version";

/**
* Identifies events within an SSE Stream.
*/
String LAST_EVENT_ID = "Last-Event-ID";

/**
* Identifies the MCP protocol version.
* @deprecated use {@link MCP_PROTOCOL_VERSION} instead
*/
String PROTOCOL_VERSION = "MCP-Protocol-Version";
@Deprecated(forRemoval = true)
String PROTOCOL_VERSION = MCP_PROTOCOL_VERSION;

}
Loading