Add MCP Streamable HTTP specification support for the client#210
Add MCP Streamable HTTP specification support for the client#210keisku wants to merge 7 commits intomodelcontextprotocol:mainfrom
Conversation
| @@ -62,14 +40,10 @@ def connect_sse(session_id, logger) | |||
| response.read_body do |chunk| | |||
There was a problem hiding this comment.
Let's use https://rubygems.org/gems/event_stream_parser for parsing. SSE appears easy to parse but it has weird edge cases.
Thanks for kicking off the effort! I've been planning on porting this standalone client I had written for a project, but never got around to doing it: https://gist.github.com/atesgoral/75172912b5951d9be33497b80aba4397
You can see how event_stream_parser can be used for parsing chunks as they come in.
|
@atesgoral Thanks for reviewing this! I've addressed it. |
|
@atesgoral Any chance you could take a look at this PR? |
examples/streamable_http_client.rb
Outdated
| Choose an action:#{" "} | ||
| MENU | ||
|
|
||
| choice = gets&.chomp |
There was a problem hiding this comment.
The safe navigation operator doesn't seem necessary. Is there any case where this could be nil?
| choice = gets&.chomp | |
| choice = gets.chomp |
There was a problem hiding this comment.
Can you look over the other similar parts as well?
| module MCP | ||
| class Server | ||
| module Transports | ||
| # TODO: https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#resumability-and-redelivery |
There was a problem hiding this comment.
It would be helpful to describe what is expected to be done in this TODO.
There was a problem hiding this comment.
Thanks for the suggestion. I intentionally kept the TODOs minimal with just the spec URLs. The MCP spec already documents these requirements in detail with precise MUST/SHOULD/MAY language, so I'd avoid duplicating that here. What do you think?
| REQUIRED_GET_ACCEPT_TYPES = ["text/event-stream"].freeze | ||
|
|
||
| def handle_request(request) | ||
| # TODO: https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#security-warning |
Motivation and Context
Implements the MCP Streamable HTTP specification for the Ruby SDK client.
Already supported:
Accept: application/json, text/event-streamheaderapplication/jsonresponseThis PR adds:
text/event-stream(SSE) responseMCP-Session-Idheader)MCP-Protocol-Version)How Has This Been Tested?
Terminal 1 - Server
Terminal 2 - Client
Breaking Changes
None. The public
send_request(request:)method signature is preserved for backward compatibility.Types of changes
Checklist
Additional context
API Design
MCP::Client::HTTP#send_request(request:)- Returns body only (backward compatible)MCP::Client::HTTP#post(body:, headers:)- ReturnsResponsestruct with body + headers (for session management)MCP::Client::HTTP#delete(headers:)- For session terminationMCP::Client#connect(client_info:, protocol_version:, capabilities:)- Initialization handshakeMCP::Client#close- Session terminationPending TODOs
Last-Event-IDheader