Skip to content

Commit bfa66b4

Browse files
committed
Reuse HttpHeaders constants
Signed-off-by: Yanming Zhou <[email protected]>
1 parent 713ee1a commit bfa66b4

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.fasterxml.jackson.databind.ObjectMapper;
2424

2525
import io.modelcontextprotocol.client.transport.ResponseSubscribers.ResponseEvent;
26+
import io.modelcontextprotocol.spec.HttpHeaders;
2627
import io.modelcontextprotocol.spec.McpClientTransport;
2728
import io.modelcontextprotocol.spec.McpSchema;
2829
import io.modelcontextprotocol.spec.ProtocolVersions;
@@ -66,8 +67,6 @@ public class HttpClientSseClientTransport implements McpClientTransport {
6667

6768
private static final String MCP_PROTOCOL_VERSION = ProtocolVersions.MCP_2024_11_05;
6869

69-
private static final String MCP_PROTOCOL_VERSION_HEADER_NAME = "MCP-Protocol-Version";
70-
7170
private static final Logger logger = LoggerFactory.getLogger(HttpClientSseClientTransport.class);
7271

7372
/** SSE event type for JSON-RPC messages */
@@ -403,7 +402,7 @@ public Mono<Void> connect(Function<Mono<JSONRPCMessage>, Mono<JSONRPCMessage>> h
403402
.uri(uri)
404403
.header("Accept", "text/event-stream")
405404
.header("Cache-Control", "no-cache")
406-
.header(MCP_PROTOCOL_VERSION_HEADER_NAME, MCP_PROTOCOL_VERSION)
405+
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
407406
.GET();
408407
return Mono.from(this.httpRequestCustomizer.customize(builder, "GET", uri, null));
409408
}).flatMap(requestBuilder -> Mono.create(sink -> {
@@ -529,7 +528,7 @@ private Mono<HttpResponse<String>> sendHttpPost(final String endpoint, final Str
529528
return Mono.defer(() -> {
530529
var builder = this.requestBuilder.copy()
531530
.uri(requestUri)
532-
.header(MCP_PROTOCOL_VERSION_HEADER_NAME, MCP_PROTOCOL_VERSION)
531+
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
533532
.POST(HttpRequest.BodyPublishers.ofString(body));
534533
return Mono.from(this.httpRequestCustomizer.customize(builder, "POST", requestUri, body));
535534
}).flatMap(customizedBuilder -> {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,10 @@ public Mono<Void> sendMessage(McpSchema.JSONRPCMessage sentMessage) {
435435
})).onErrorMap(CompletionException.class, t -> t.getCause()).onErrorComplete().subscribe();
436436

437437
})).flatMap(responseEvent -> {
438-
if (transportSession.markInitialized(
439-
responseEvent.responseInfo().headers().firstValue("mcp-session-id").orElseGet(() -> null))) {
438+
if (transportSession.markInitialized(responseEvent.responseInfo()
439+
.headers()
440+
.firstValue(HttpHeaders.MCP_SESSION_ID)
441+
.orElseGet(() -> null))) {
440442
// Once we have a session, we try to open an async stream for
441443
// the server to send notifications and requests out-of-band.
442444

0 commit comments

Comments
 (0)