Class: Tidewave::StreamableHttpTransport

Inherits:
FastMcp::Transports::BaseTransport
  • Object
show all
Defined in:
lib/tidewave/streamable_http_transport.rb

Overview

Streamable HTTP transport for MCP (POST-only, no SSE) This transport implements a simplified version of the MCP Streamable HTTP protocol that only supports POST requests for JSON-RPC messages. Unlike the full protocol, it does not support Server-Sent Events (SSE) for streaming responses.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, server, options = {}) ⇒ StreamableHttpTransport

Returns a new instance of StreamableHttpTransport.



15
16
17
18
19
20
# File 'lib/tidewave/streamable_http_transport.rb', line 15

def initialize(app, server, options = {})
  super(server, logger: options[:logger])
  @app = app
  @path = options[:path_prefix] || "/mcp"
  @running = false
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



13
14
15
# File 'lib/tidewave/streamable_http_transport.rb', line 13

def app
  @app
end

#pathObject (readonly)

Returns the value of attribute path.



13
14
15
# File 'lib/tidewave/streamable_http_transport.rb', line 13

def path
  @path
end

Instance Method Details

#call(env) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/tidewave/streamable_http_transport.rb', line 39

def call(env)
  request = Rack::Request.new(env)

  if request.path == @path
    @server.transport = self
    handle_mcp_request(request, env)
  else
    @app.call(env)
  end
end

#send_message(message) ⇒ Object

Send a message - capture response for synchronous HTTP Required by FastMCP::Transports::BaseTransport interface



34
35
36
37
# File 'lib/tidewave/streamable_http_transport.rb', line 34

def send_message(message)
  @logger.debug("send_message called, capturing response: #{message.inspect}")
  @captured_response = message
end

#startObject



22
23
24
25
# File 'lib/tidewave/streamable_http_transport.rb', line 22

def start
  @logger.debug("Starting Streamable HTTP transport (POST-only) at path: #{@path}")
  @running = true
end

#stopObject



27
28
29
30
# File 'lib/tidewave/streamable_http_transport.rb', line 27

def stop
  @logger.debug("Stopping Streamable HTTP transport")
  @running = false
end