Skip to content

Commit 5a2986b

Browse files
committed
Reuse HttpHeaders constants
Signed-off-by: Yanming Zhou <[email protected]>
1 parent a0afdcd commit 5a2986b

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import io.modelcontextprotocol.client.transport.customizer.McpSyncHttpClientRequestCustomizer;
2727
import io.modelcontextprotocol.client.transport.ResponseSubscribers.ResponseEvent;
2828
import io.modelcontextprotocol.common.McpTransportContext;
29+
import io.modelcontextprotocol.spec.HttpHeaders;
2930
import io.modelcontextprotocol.spec.McpClientTransport;
3031
import io.modelcontextprotocol.spec.McpSchema;
3132
import io.modelcontextprotocol.spec.McpSchema.JSONRPCMessage;
@@ -69,8 +70,6 @@ public class HttpClientSseClientTransport implements McpClientTransport {
6970

7071
private static final String MCP_PROTOCOL_VERSION = ProtocolVersions.MCP_2024_11_05;
7172

72-
private static final String MCP_PROTOCOL_VERSION_HEADER_NAME = "MCP-Protocol-Version";
73-
7473
private static final Logger logger = LoggerFactory.getLogger(HttpClientSseClientTransport.class);
7574

7675
/** SSE event type for JSON-RPC messages */
@@ -342,7 +341,7 @@ public Mono<Void> connect(Function<Mono<JSONRPCMessage>, Mono<JSONRPCMessage>> h
342341
.uri(uri)
343342
.header("Accept", "text/event-stream")
344343
.header("Cache-Control", "no-cache")
345-
.header(MCP_PROTOCOL_VERSION_HEADER_NAME, MCP_PROTOCOL_VERSION)
344+
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
346345
.GET();
347346
var transportContext = ctx.getOrDefault(McpTransportContext.KEY, McpTransportContext.EMPTY);
348347
return Mono.from(this.httpRequestCustomizer.customize(builder, "GET", uri, null, transportContext));
@@ -470,7 +469,7 @@ private Mono<HttpResponse<String>> sendHttpPost(final String endpoint, final Str
470469
var builder = this.requestBuilder.copy()
471470
.uri(requestUri)
472471
.header("Content-Type", "application/json")
473-
.header(MCP_PROTOCOL_VERSION_HEADER_NAME, MCP_PROTOCOL_VERSION)
472+
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
474473
.POST(HttpRequest.BodyPublishers.ofString(body));
475474
var transportContext = ctx.getOrDefault(McpTransportContext.KEY, McpTransportContext.EMPTY);
476475
return Mono.from(this.httpRequestCustomizer.customize(builder, "POST", requestUri, body, transportContext));

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

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

445445
})).flatMap(responseEvent -> {
446-
if (transportSession.markInitialized(
447-
responseEvent.responseInfo().headers().firstValue("mcp-session-id").orElseGet(() -> null))) {
446+
if (transportSession.markInitialized(responseEvent.responseInfo()
447+
.headers()
448+
.firstValue(HttpHeaders.MCP_SESSION_ID)
449+
.orElseGet(() -> null))) {
448450
// Once we have a session, we try to open an async stream for
449451
// the server to send notifications and requests out-of-band.
450452

0 commit comments

Comments
 (0)