Streamable HTTP
Transports - Model Context Protocol
In the Streamable HTTP transport, the server operates as an independent process that can handle multiple client connections. This transport uses HTTP POST and GET requests. Server can optionally make use of Server-Sent Events (SSE) to stream multiple server messages. This permits basic MCP servers, as well as more feature-rich servers supporting streaming and server-to-client notifications and requests.
The server MUST provide a single HTTP endpoint path (hereafter referred to as the MCP endpoint) that supports both POST and GET methods. For example, this could be a URL like https://example.com/mcp.
ステートレスな通常のHTTP通信とSSEを使い分けることができるようにしたもの、かな。
code:rb
# config.ru
app = Proc.new do |env|
[
200,
{ "Content-Type" => "text/plain", "Transfer-Encoding" => "chunked" },
Enumerator.new do |yielder|
5.times do |i|
yielder << "Chunk #{i}\n"
sleep 1
end
end
]
end
run app
code:rb
require 'net/http'
uri = URI('http://localhost:9292/')
Net::HTTP.start(uri.host, uri.port) do |http|
request = Net::HTTP::Get.new(uri)
http.request(request) do |response|
response.read_body do |chunk|
puts "Received chunk: #{chunk.inspect}"
end
end
end
mcp