Skip to content

Reuse HttpHeaders constants #495

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 @@ -23,6 +23,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;

import io.modelcontextprotocol.client.transport.ResponseSubscribers.ResponseEvent;
import io.modelcontextprotocol.spec.HttpHeaders;
import io.modelcontextprotocol.spec.McpClientTransport;
import io.modelcontextprotocol.spec.McpSchema;
import io.modelcontextprotocol.spec.ProtocolVersions;
Expand Down Expand Up @@ -66,8 +67,6 @@ public class HttpClientSseClientTransport implements McpClientTransport {

private static final String MCP_PROTOCOL_VERSION = ProtocolVersions.MCP_2024_11_05;

private static final String MCP_PROTOCOL_VERSION_HEADER_NAME = "MCP-Protocol-Version";

private static final Logger logger = LoggerFactory.getLogger(HttpClientSseClientTransport.class);

/** SSE event type for JSON-RPC messages */
Expand Down Expand Up @@ -403,7 +402,7 @@ public Mono<Void> connect(Function<Mono<JSONRPCMessage>, Mono<JSONRPCMessage>> h
.uri(uri)
.header("Accept", "text/event-stream")
.header("Cache-Control", "no-cache")
.header(MCP_PROTOCOL_VERSION_HEADER_NAME, MCP_PROTOCOL_VERSION)
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
.GET();
return Mono.from(this.httpRequestCustomizer.customize(builder, "GET", uri, null));
}).flatMap(requestBuilder -> Mono.create(sink -> {
Expand Down Expand Up @@ -529,7 +528,7 @@ private Mono<HttpResponse<String>> sendHttpPost(final String endpoint, final Str
return Mono.defer(() -> {
var builder = this.requestBuilder.copy()
.uri(requestUri)
.header(MCP_PROTOCOL_VERSION_HEADER_NAME, MCP_PROTOCOL_VERSION)
.header(HttpHeaders.PROTOCOL_VERSION, MCP_PROTOCOL_VERSION)
.POST(HttpRequest.BodyPublishers.ofString(body));
return Mono.from(this.httpRequestCustomizer.customize(builder, "POST", requestUri, body));
}).flatMap(customizedBuilder -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,10 @@ public Mono<Void> sendMessage(McpSchema.JSONRPCMessage sentMessage) {
})).onErrorMap(CompletionException.class, t -> t.getCause()).onErrorComplete().subscribe();

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

Expand Down