Class: Mistri::MCP::Wires::Http

Inherits:
Object
  • Object
show all
Defined in:
lib/mistri/mcp/wires.rb

Overview

Streamable HTTP: requests POST to one endpoint, responses arrive as JSON or an SSE stream. Sessions and bearer auth live here.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, token:, headers:, open_timeout:, read_timeout:) ⇒ Http

Returns a new instance of Http.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mistri/mcp/wires.rb', line 16

def initialize(url:, token:, headers:, open_timeout:, read_timeout:)
  uri = URI(url)
  @path = uri.path.empty? ? "/" : uri.path
  @path = "#{@path}?#{uri.query}" if uri.query
  @transport = Transport.new(origin: "#{uri.scheme}://#{uri.host}:#{uri.port}",
                             open_timeout: open_timeout, read_timeout: read_timeout)
  @token = token
  @headers = headers
  @session_id = nil
  @protocol_version = nil
end

Instance Attribute Details

#protocol_version=(value) ⇒ Object (writeonly)

Sets the attribute protocol_version

Parameters:

  • value

    the value to set the attribute protocol_version to.



28
29
30
# File 'lib/mistri/mcp/wires.rb', line 28

def protocol_version=(value)
  @protocol_version = value
end

Instance Method Details

#call(payload) ⇒ Object



30
31
32
33
34
# File 'lib/mistri/mcp/wires.rb', line 30

def call(payload, &)
  meta = @transport.post_either(@path, body: payload, headers: request_headers, &)
  capture_session(meta)
  nil
end

#closeObject



48
# File 'lib/mistri/mcp/wires.rb', line 48

def close = @transport.close

#notify(payload) ⇒ Object



36
37
38
39
40
# File 'lib/mistri/mcp/wires.rb', line 36

def notify(payload)
  discard = ->(_record) {}
  @transport.post_either(@path, body: payload, headers: request_headers, &discard)
  nil
end

#refreshable?Boolean

Returns:

  • (Boolean)


44
# File 'lib/mistri/mcp/wires.rb', line 44

def refreshable? = @token.respond_to?(:call)

#reset_sessionObject



46
# File 'lib/mistri/mcp/wires.rb', line 46

def reset_session = @session_id = nil

#session?Boolean

Returns:

  • (Boolean)


42
# File 'lib/mistri/mcp/wires.rb', line 42

def session? = !@session_id.nil?