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:
parent
080098e48c
commit
3f7578b3ce
2 changed files with 6 additions and 4 deletions
|
|
@ -507,8 +507,9 @@ public class HttpClientStreamableHttpTransport implements McpClientTransport {
|
||||||
else if (contentType.contains(APPLICATION_JSON)) {
|
else if (contentType.contains(APPLICATION_JSON)) {
|
||||||
deliveredSink.success();
|
deliveredSink.success();
|
||||||
String data = ((ResponseSubscribers.AggregateResponseEvent) responseEvent).data();
|
String data = ((ResponseSubscribers.AggregateResponseEvent) responseEvent).data();
|
||||||
if (sentMessage instanceof McpSchema.JSONRPCNotification && Utils.hasText(data)) {
|
if (sentMessage instanceof McpSchema.JSONRPCNotification) {
|
||||||
logger.warn("Notification: {} received non-compliant response: {}", sentMessage, data);
|
logger.warn("Notification: {} received non-compliant response: {}", sentMessage,
|
||||||
|
Utils.hasText(data) ? data : "[empty]");
|
||||||
return Mono.empty();
|
return Mono.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -423,8 +423,9 @@ public class WebClientStreamableHttpTransport implements McpClientTransport {
|
||||||
ClientResponse response) {
|
ClientResponse response) {
|
||||||
return response.bodyToMono(String.class).<Iterable<McpSchema.JSONRPCMessage>>handle((responseMessage, s) -> {
|
return response.bodyToMono(String.class).<Iterable<McpSchema.JSONRPCMessage>>handle((responseMessage, s) -> {
|
||||||
try {
|
try {
|
||||||
if (sentMessage instanceof McpSchema.JSONRPCNotification && Utils.hasText(responseMessage)) {
|
if (sentMessage instanceof McpSchema.JSONRPCNotification) {
|
||||||
logger.warn("Notification: {} received non-compliant response: {}", sentMessage, responseMessage);
|
logger.warn("Notification: {} received non-compliant response: {}", sentMessage,
|
||||||
|
Utils.hasText(responseMessage) ? responseMessage : "[empty]");
|
||||||
s.complete();
|
s.complete();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue