Class: SolidLoop::Mcp::HttpTransport

Inherits:
Object
  • Object
show all
Includes:
Transport
Defined in:
lib/solid_loop/mcp/http_transport.rb

Overview

Reference adapter: Streamable-HTTP MCP over Faraday. JSON request/response, Authorization: Bearer, Mcp-Session-Id header mapped to the port's session_id, custom headers, timeout.

Instance Method Summary collapse

Constructor Details

#initialize(url:, token: nil, timeout: 60, headers: {}) ⇒ HttpTransport

Returns a new instance of HttpTransport.



11
12
13
14
15
16
# File 'lib/solid_loop/mcp/http_transport.rb', line 11

def initialize(url:, token: nil, timeout: 60, headers: {})
  @url = url
  @token = token
  @timeout = timeout
  @extra_headers = headers
end

Instance Method Details

#deliver(payload, session_id: nil, context: nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/solid_loop/mcp/http_transport.rb', line 18

def deliver(payload, session_id: nil, context: nil)
  response = connection(session_id).post("", payload)

  Result.new(
    body:         response.body,
    session_id:   response.headers["Mcp-Session-Id"],
    raw_request:  payload,
    raw_response: response.body,
    status:       response.status
  )
rescue Faraday::Error => e
  raise SolidLoop::McpError, "MCP transport error: #{e.class}: #{e.message}"
end