Class: Mistri::MCP::Wires::Http
- Inherits:
-
Object
- Object
- Mistri::MCP::Wires::Http
- 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
-
#protocol_version ⇒ Object
writeonly
Sets the attribute protocol_version.
Instance Method Summary collapse
- #call(payload) ⇒ Object
- #close ⇒ Object
-
#initialize(url:, token:, headers:, open_timeout:, read_timeout:) ⇒ Http
constructor
A new instance of Http.
- #notify(payload) ⇒ Object
- #refreshable? ⇒ Boolean
- #reset_session ⇒ Object
- #session? ⇒ Boolean
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
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, &) = @transport.post_either(@path, body: payload, headers: request_headers, &) capture_session() nil end |
#close ⇒ Object
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
44 |
# File 'lib/mistri/mcp/wires.rb', line 44 def refreshable? = @token.respond_to?(:call) |
#reset_session ⇒ Object
46 |
# File 'lib/mistri/mcp/wires.rb', line 46 def reset_session = @session_id = nil |
#session? ⇒ Boolean
42 |
# File 'lib/mistri/mcp/wires.rb', line 42 def session? = !@session_id.nil? |