Class: ActionMCP::Session::SSEEvent

Inherits:
ApplicationRecord show all
Defined in:
app/models/action_mcp/session/sse_event.rb

Overview

Represents a Server-Sent Event (SSE) in an MCP session These events are stored for potential resumption when a client reconnects

Instance Method Summary collapse

Instance Method Details

#data_for_streamObject

Serializes the data as JSON if it’s not already a string



49
50
51
52
53
# File 'app/models/action_mcp/session/sse_event.rb', line 49

def data_for_stream
  return data if data.is_a?(String)

  data.is_a?(Hash) ? data.to_json : data.to_s
end

#to_sseString

Generates the SSE formatted event string

Returns:

  • (String)

    The formatted SSE event



57
58
59
# File 'app/models/action_mcp/session/sse_event.rb', line 57

def to_sse
  "id: #{event_id}\ndata: #{data_for_stream}\n\n"
end