Class: Whoosh::MCP::Transport::SSE

Inherits:
Object
  • Object
show all
Defined in:
lib/whoosh/mcp/transport/sse.rb

Instance Method Summary collapse

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.message)
  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