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 @@ -574,17 +574,18 @@ public Mono<Void> sendMessage(McpSchema.JSONRPCMessage sentMessage) {
"Authorization error when sending message", requestSnapshot, responseEvent.responseInfo()));
}

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);

if (statusCode >= 200 && statusCode < 300) {
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 @@ -389,6 +389,22 @@ void test405OnConnectReturnsEmptyFlux() {
StepVerifier.create(transport.closeGracefully()).verifyComplete();
}

@Test
void test405OnSendMessageDoesNotOpenSseConnection() {
serverResponseStatus.set(405);
currentServerSessionId.set("ignored-session-id");

StepVerifier.create(transport.sendMessage(createTestRequestMessage()))
.expectErrorMatches(
error -> error instanceof McpTransportException && error.getMessage().contains("Status code: 405"))
.verify();

Awaitility.await()
.during(Duration.ofMillis(300))
.atMost(Duration.ofSeconds(1))
.untilAsserted(() -> assertThat(processedSseConnectCount.get()).isZero());
}

@Nested
class AuthorizationError {

Expand Down
Loading