From 7a5bd7c18fc68b3073ae5faa546113fae96f0502 Mon Sep 17 00:00:00 2001 From: dak2 Date: Sat, 21 Jun 2025 15:42:20 +0900 Subject: [PATCH] Fix handling response when sending notifications in `examples/streamable_http_client.rb` Even though the 'tools/call' request to 'notification_tool' is successful and an 'MCP::Tool::Response' is returned, the logger still prints 'Error:'. ``` % ruby examples/streamable_http_client.rb === MCP SSE Test Client === [CLIENT] INFO 15:41:04.696 - Initializing session... [CLIENT] INFO 15:41:04.698 - Session initialized: SESSION_ID [CLIENT] INFO 15:41:04.698 - Server info: {"name" => "sse_test_server", "version" => "0.1.0"} [CLIENT] INFO 15:41:04.698 - Connecting to SSE stream... [CLIENT] INFO 15:41:04.698 - SSE stream connected successfully === Available Actions === 1. Send custom notification 2. Test echo 3. List tools 0. Exit Choose an action: 1 Enter notification message: notification test Enter delay in seconds (0 for immediate): [CLIENT] INFO 15:41:11.248 - SSE data: {"jsonrpc":"2.0","id":"0f657eeb-3e05-47bb-b7b4-898e2cb503af","result":{"content":[{"type":"text","text":"Notification: notification test (timestamp: 2025-06-21T15:41:11+09:00)"}],"isError":false}} [CLIENT] ERROR 15:41:11.249 - Error: === Available Actions === 1. Send custom notification 2. Test echo 3. List tools 0. Exit ``` It is probably trying to output an MCP::Tool::Response, but these appear in the SSE stream. Therefore, the response it is handling this time should either be accepted or an error. I modified it so that it could handle them. --- examples/streamable_http_client.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/streamable_http_client.rb b/examples/streamable_http_client.rb index cd24ab37..f0abe18e 100644 --- a/examples/streamable_http_client.rb +++ b/examples/streamable_http_client.rb @@ -163,9 +163,8 @@ def main }, }, ) - - if response[:body]["result"] - logger.info("Notification tool response: #{response[:body]["result"]["content"]}") + if response[:body]["accepted"] + logger.info("Notification sent successfully") else logger.error("Error: #{response[:body]["error"]}") end