Skip to content
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 @@ -466,19 +466,21 @@ 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))) {
// Once we have a session, we try to open an async stream for
// the server to send notifications and requests out-of-band.

reconnect(null).contextWrite(deliveredSink.contextView()).subscribe();
}

String sessionRepresentation = sessionIdOrPlaceholder(transportSession);

int statusCode = responseEvent.responseInfo().statusCode();

if (statusCode >= 200 && statusCode < 300) {
// Only initialize session and open async stream for successful
// responses
if (transportSession.markInitialized(responseEvent.responseInfo()
.headers()
.firstValue("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.
reconnect(null).contextWrite(deliveredSink.contextView()).subscribe();
}

String contentType = responseEvent.responseInfo()
.headers()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,18 +310,19 @@ public Mono<Void> sendMessage(McpSchema.JSONRPCMessage message) {
})
.bodyValue(jsonText)
.exchangeToFlux(response -> {
if (transportSession
.markInitialized(response.headers().asHttpHeaders().getFirst(HttpHeaders.MCP_SESSION_ID))) {
// Once we have a session, we try to open an async stream for
// the server to send notifications and requests out-of-band.
reconnect(null).contextWrite(sink.contextView()).subscribe();
}

String sessionRepresentation = sessionIdOrPlaceholder(transportSession);

// The spec mentions only ACCEPTED, but the existing SDKs can return
// 200 OK for notifications
if (response.statusCode().is2xxSuccessful()) {
// Only initialize session and open async stream for successful
// responses
if (transportSession
.markInitialized(response.headers().asHttpHeaders().getFirst(HttpHeaders.MCP_SESSION_ID))) {
// Once we have a session, we try to open an async stream for
// the server to send notifications and requests out-of-band.
reconnect(null).contextWrite(sink.contextView()).subscribe();
}
Optional<MediaType> contentType = response.headers().contentType();
long contentLength = response.headers().contentLength().orElse(-1);
// Existing SDKs consume notifications with no response body nor
Expand Down