fix: Handle non-compliant notification responses (#589)

Ensure warnings are logged for all non-compliant responses to JSON-RPC
notifications, including empty responses. Empty responses now display
as "[empty]" in log messages for better clarity.

Resolves #586

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
This commit is contained in:
Christian Tzolov 2025-10-01 23:14:29 +02:00 • committed by GitHub
commit 3f7578b3ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -423,8 +423,9 @@ public class WebClientStreamableHttpTransport implements McpClientTransport {
ClientResponse response) {
return response.bodyToMono(String.class).<Iterable<McpSchema.JSONRPCMessage>>handle((responseMessage, s) -> {
try {
if (sentMessage instanceof McpSchema.JSONRPCNotification && Utils.hasText(responseMessage)) {
logger.warn("Notification: {} received non-compliant response: {}", sentMessage, responseMessage);
if (sentMessage instanceof McpSchema.JSONRPCNotification) {
logger.warn("Notification: {} received non-compliant response: {}", sentMessage,
Utils.hasText(responseMessage) ? responseMessage : "[empty]");
s.complete();
}
else {