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, replayable:) ⇒ Object
- #close ⇒ Object
-
#initialize(url:, token:, headers:, open_timeout:, read_timeout:, allow_non_public:, max_record_bytes: DEFAULT_MAX_RECORD_BYTES) ⇒ 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:, 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
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:, &) = @transport.post_either(@path, body: payload, headers: request_headers, replayable: replayable, &) capture_session() nil end |
#close ⇒ Object
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
56 |
# File 'lib/mistri/mcp/wires.rb', line 56 def refreshable? = @token.respond_to?(:call) |
#reset_session ⇒ Object
58 59 60 61 |
# File 'lib/mistri/mcp/wires.rb', line 58 def reset_session @session_id = nil @protocol_version = nil end |
#session? ⇒ Boolean
54 |
# File 'lib/mistri/mcp/wires.rb', line 54 def session? = !@session_id.nil? |