Fix handling response when sending notifications in examples/streamable_http_client.rb#70
Merged
koic merged 1 commit intomodelcontextprotocol:mainfrom Jun 21, 2025
Conversation
9a4fa58 to
efb7689
Compare
koic
reviewed
Jun 21, 2025
examples/streamable_http_client.rb
Outdated
| if response[:body]["result"] | ||
| logger.info("Notification tool response: #{response[:body]["result"]["content"]}") | ||
| if response[:body]["accepted"] | ||
| logger.info("Notification was sent successfully") |
Member
There was a problem hiding this comment.
I’ve confirmed the behavior, and indeed the response here is {"accepted" => true}.
https://github.com/modelcontextprotocol/ruby-sdk/blob/0fe0289/lib/mcp/server/transports/streamable_http_transport.rb#L205
Just one thing. The message seems quite simple. What do you think?
Suggested change
| logger.info("Notification was sent successfully") | |
| logger.info("Notification sent successfully") |
Contributor
Author
There was a problem hiding this comment.
Yeah, it can be expressed as a simple message.
Thanks!
…ble_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.
efb7689 to
7a5bd7c
Compare
koic
approved these changes
Jun 21, 2025
Member
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
Even though the
tools/callrequest tonotification_toolis successful and anMCP::Tool::Responseis returned, the logger still printsError:.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.
How Has This Been Tested?
I have confirmed by running the modified
examples/streamable_http_client.rbthat thetools/callrequest tonotification_toolis successful, but does not print an error in the logger.Breaking Changes
Nothing
Types of changes
Checklist
Additional context