Class: Whoosh::MCP::Transport::SSE
- Inherits:
-
Object
- Object
- Whoosh::MCP::Transport::SSE
- Defined in:
- lib/whoosh/mcp/transport/sse.rb
Instance Method Summary collapse
- #handle_request(body) ⇒ Object
-
#initialize(server) ⇒ SSE
constructor
A new instance of SSE.
Constructor Details
#initialize(server) ⇒ SSE
Returns a new instance of SSE.
8 9 10 |
# File 'lib/whoosh/mcp/transport/sse.rb', line 8 def initialize(server) @server = server end |
Instance Method Details
#handle_request(body) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/whoosh/mcp/transport/sse.rb', line 12 def handle_request(body) response = begin request = Protocol.parse(body) @server.handle(request) rescue Protocol::ParseError => e Protocol.error_response(id: nil, code: -32700, message: e.) end sse_body = response ? "data: #{Protocol.encode(response)}\n\n" : "" [200, { "content-type" => "text/event-stream", "cache-control" => "no-cache", "connection" => "keep-alive" }, [sse_body]] end |