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:, allow_non_public:, max_record_bytes: DEFAULT_MAX_RECORD_BYTES) ⇒ Http

Returns a new instance of Http.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/mistri/mcp/wires.rb', line 24

def initialize(url:, token:, headers:, open_timeout:, read_timeout:, allow_non_public:,
               max_record_bytes: DEFAULT_MAX_RECORD_BYTES)
  uri, resolver = Egress.resolver(url, allow_non_public:, label: "MCP URL",
                                       timeout: open_timeout)
  @path = uri.path.empty? ? "/" : uri.path
  @path = "#{@path}?#{uri.query}" if uri.query
  @transport = Transport.new(origin: Egress.origin(uri), address_resolver: resolver,
                             open_timeout: open_timeout, read_timeout: read_timeout,
                             max_record_bytes: max_record_bytes)
  @token = token
  @headers = normalized_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.



39
40
41
# File 'lib/mistri/mcp/wires.rb', line 39

def protocol_version=(value)
  @protocol_version = value
end

Instance Method Details

#call(payload, replayable:) ⇒ Object



41
42
43
44
45
46
# File 'lib/mistri/mcp/wires.rb', line 41

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

#closeObject



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

def close = @transport.close

#notify(payload) ⇒ Object



48
49
50
51
52
# File 'lib/mistri/mcp/wires.rb', line 48

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

#refreshable?Boolean

Returns:

  • (Boolean)


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

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

#reset_sessionObject



58
59
60
61
# File 'lib/mistri/mcp/wires.rb', line 58

def reset_session
  @session_id = nil
  @protocol_version = nil
end

#session?Boolean

Returns:

  • (Boolean)


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

def session? = !@session_id.nil?