Class: SwarmSDK::V3::MCP::SslHttpTransport

Inherits:
Object
  • Object
show all
Defined in:
lib/swarm_sdk/v3/mcp/ssl_http_transport.rb

Overview

HTTP transport for MCP with configurable SSL verification.

Uses Net::HTTP directly instead of Faraday to avoid the async-http adapter that Faraday selects when running inside Async. The async-http adapter ignores Faraday’s SSL settings and uses IO::Endpoint::SSLEndpoint which enforces CRL checking on OpenSSL 3.6+, breaking most HTTPS MCP connections with “certificate verify failed (unable to get certificate CRL)”.

Conforms to the MCP transport interface: responds to send_request(request:) returning a parsed Hash.

Examples:

Default (SSL peer verification, no CRL checking)

SslHttpTransport.new(url: "https://api.example.com/mcp")

Disable SSL verification entirely

SslHttpTransport.new(url: "https://localhost/mcp", ssl_verify: false)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, headers: {}, ssl_verify: true) ⇒ SslHttpTransport

Returns a new instance of SslHttpTransport.

Parameters:

  • url (String)

    HTTP endpoint URL

  • headers (Hash) (defaults to: {})

    HTTP headers

  • ssl_verify (Boolean) (defaults to: true)

    Whether to verify SSL certificates (default: true)



29
30
31
32
33
34
# File 'lib/swarm_sdk/v3/mcp/ssl_http_transport.rb', line 29

def initialize(url:, headers: {}, ssl_verify: true)
  @url = url
  @headers = headers
  @ssl_verify = ssl_verify
  @uri = URI.parse(url)
end

Instance Attribute Details

#urlString (readonly)

Returns HTTP endpoint URL.

Returns:

  • (String)

    HTTP endpoint URL



24
25
26
# File 'lib/swarm_sdk/v3/mcp/ssl_http_transport.rb', line 24

def url
  @url
end

Instance Method Details

#send_request(request:) ⇒ Hash

Send a JSON-RPC request to the MCP server.

Parameters:

  • request (Hash)

    JSON-RPC request body

Returns:

  • (Hash)

    Parsed JSON response

Raises:

  • (MCP::Client::RequestHandlerError)

    On HTTP or connection errors



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/swarm_sdk/v3/mcp/ssl_http_transport.rb', line 41

def send_request(request:)
  http = build_http
  post = build_post(request)

  response = http.request(post)
  JSON.parse(response.body)
rescue OpenSSL::SSL::SSLError => e
  raise ::MCP::Client::RequestHandlerError.new(
    "SSL error connecting to MCP server #{@uri.host}: #{e.message}",
    extract_method_params(request),
    error_type: :internal_error,
    original_error: e,
  )
rescue Net::HTTPError, Net::OpenTimeout, Net::ReadTimeout, SocketError, Errno::ECONNREFUSED => e
  raise ::MCP::Client::RequestHandlerError.new(
    "Connection error to MCP server #{@uri.host}: #{e.message}",
    extract_method_params(request),
    error_type: :internal_error,
    original_error: e,
  )
end