Class: Ask::MCP::Transport::StreamableHTTP
- Inherits:
-
Object
- Object
- Ask::MCP::Transport::StreamableHTTP
- Defined in:
- lib/ask/mcp/transport/streamable_http.rb
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(url, options = {}) ⇒ StreamableHTTP
constructor
A new instance of StreamableHTTP.
- #on_message(&block) ⇒ Object
- #running? ⇒ Boolean
- #send(message) ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(url, options = {}) ⇒ StreamableHTTP
Returns a new instance of StreamableHTTP.
9 10 11 12 13 14 15 16 |
# File 'lib/ask/mcp/transport/streamable_http.rb', line 9 def initialize(url, = {}) @url = url @options = @running = false @message_handlers = [] @http = nil @session_id = nil end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
7 8 9 |
# File 'lib/ask/mcp/transport/streamable_http.rb', line 7 def url @url end |
Instance Method Details
#on_message(&block) ⇒ Object
18 19 20 |
# File 'lib/ask/mcp/transport/streamable_http.rb', line 18 def (&block) @message_handlers << block end |
#running? ⇒ Boolean
54 55 56 |
# File 'lib/ask/mcp/transport/streamable_http.rb', line 54 def running? @running end |
#send(message) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ask/mcp/transport/streamable_http.rb', line 42 def send() data = .is_a?(String) ? : .to_json if @options[:stream] send_streaming(data) else send_request_response(data) end rescue HTTPX::Error => e raise ConnectionError, "HTTP error: #{e.}" end |
#shutdown ⇒ Object
58 59 60 |
# File 'lib/ask/mcp/transport/streamable_http.rb', line 58 def shutdown stop end |
#start ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ask/mcp/transport/streamable_http.rb', line 22 def start require "httpx" headers = { "Content-Type" => "application/json" } headers["Accept"] = "text/event-stream" if @options[:stream] headers.merge!(@options[:headers]) if @options[:headers] @http = HTTPX.with( headers:, timeout: { request_timeout: @options[:timeout] || 30 } ) @running = true self end |
#stop ⇒ Object
37 38 39 40 |
# File 'lib/ask/mcp/transport/streamable_http.rb', line 37 def stop @running = false @http&.close end |