Skip to content

Commit 3f7578b

Browse files
authored
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>
1 parent 080098e commit 3f7578b

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,9 @@ else if (contentType.contains(TEXT_EVENT_STREAM)) {
507507
else if (contentType.contains(APPLICATION_JSON)) {
508508
deliveredSink.success();
509509
String data = ((ResponseSubscribers.AggregateResponseEvent) responseEvent).data();
510-
if (sentMessage instanceof McpSchema.JSONRPCNotification && Utils.hasText(data)) {
511-
logger.warn("Notification: {} received non-compliant response: {}", sentMessage, data);
510+
if (sentMessage instanceof McpSchema.JSONRPCNotification) {
511+
logger.warn("Notification: {} received non-compliant response: {}", sentMessage,
512+
Utils.hasText(data) ? data : "[empty]");
512513
return Mono.empty();
513514
}
514515

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,9 @@ private Flux<McpSchema.JSONRPCMessage> directResponseFlux(McpSchema.JSONRPCMessa
423423
ClientResponse response) {
424424
return response.bodyToMono(String.class).<Iterable<McpSchema.JSONRPCMessage>>handle((responseMessage, s) -> {
425425
try {
426-
if (sentMessage instanceof McpSchema.JSONRPCNotification && Utils.hasText(responseMessage)) {
427-
logger.warn("Notification: {} received non-compliant response: {}", sentMessage, responseMessage);
426+
if (sentMessage instanceof McpSchema.JSONRPCNotification) {
427+
logger.warn("Notification: {} received non-compliant response: {}", sentMessage,
428+
Utils.hasText(responseMessage) ? responseMessage : "[empty]");
428429
s.complete();
429430
}
430431
else {

0 commit comments

Comments
 (0)