Skip to content

Commit 521c2cc

Browse files
committed
Address review comments
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
1 parent 2d05308 commit 521c2cc

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/client/transport/WebClientStreamableHttpTransport.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ else if (mediaType.isCompatibleWith(MediaType.APPLICATION_JSON)) {
288288
logger.trace("Received response to POST for session {}", sessionRepresentation);
289289
// communicate to caller the message was delivered
290290
sink.success();
291-
return responseFlux(response);
291+
return statelessResponseFlux(message, response);
292292
}
293293
else {
294294
logger.warn("Unknown media type {} returned for POST in session {}", contentType,
@@ -385,17 +385,18 @@ private static String sessionIdOrPlaceholder(McpTransportSession<?> transportSes
385385
return transportSession.sessionId().orElse("[missing_session_id]");
386386
}
387387

388-
private Flux<McpSchema.JSONRPCMessage> responseFlux(ClientResponse response) {
388+
private Flux<McpSchema.JSONRPCMessage> statelessResponseFlux(McpSchema.JSONRPCMessage sendMessage,
389+
ClientResponse response) {
389390
return response.bodyToMono(String.class).<Iterable<McpSchema.JSONRPCMessage>>handle((responseMessage, s) -> {
390391
try {
391-
if (Utils.hasText(responseMessage) && !responseMessage.trim().equals("{}")) {
392+
if (sendMessage instanceof McpSchema.JSONRPCNotification && Utils.hasText(responseMessage)) {
393+
logger.warn("Notificaiton: {} received non-compliant response: {}", sendMessage, responseMessage);
394+
}
395+
else {
392396
McpSchema.JSONRPCMessage jsonRpcResponse = McpSchema.deserializeJsonRpcMessage(objectMapper,
393397
responseMessage);
394398
s.next(List.of(jsonRpcResponse));
395399
}
396-
else {
397-
logger.warn("Received empty response message: {}", responseMessage);
398-
}
399400
}
400401
catch (IOException e) {
401402
s.error(e);

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -436,19 +436,16 @@ else if (contentType.contains(TEXT_EVENT_STREAM)) {
436436
else if (contentType.contains(APPLICATION_JSON)) {
437437
messageSink.success();
438438
String data = ((ResponseSubscribers.AggregateResponseEvent) responseEvent).data();
439-
if (Utils.hasText(data) && !data.trim().equals("{}")) {
439+
if (sendMessage instanceof McpSchema.JSONRPCNotification && Utils.hasText(data)) {
440+
logger.warn("Notificaiton: {} received non-compliant response: {}", sendMessage, data);
441+
return Mono.empty();
442+
}
440443

441-
try {
442-
return Mono.just(McpSchema.deserializeJsonRpcMessage(objectMapper, data));
443-
}
444-
catch (IOException e) {
445-
return Mono.error(e);
446-
}
444+
try {
445+
return Mono.just(McpSchema.deserializeJsonRpcMessage(objectMapper, data));
447446
}
448-
else {
449-
// No content type means no response body
450-
logger.debug("No content type returned for POST in session {}", sessionRepresentation);
451-
return Mono.empty();
447+
catch (IOException e) {
448+
return Mono.error(e);
452449
}
453450
}
454451
logger.warn("Unknown media type {} returned for POST in session {}", contentType,

0 commit comments

Comments
 (0)