Module: MCPClient::ServerSSE::JsonRpcTransport

Includes:
JsonRpcCommon
Included in:
MCPClient::ServerSSE
Defined in:
lib/mcp_client/server_sse/json_rpc_transport.rb

Overview

JSON-RPC request/notification plumbing for SSE transport

Instance Method Summary collapse

Methods included from JsonRpcCommon

#build_jsonrpc_notification, #build_jsonrpc_request, #initialization_params, #ping, #process_jsonrpc_response, #with_retry

Instance Method Details

#rpc_notify(method, params = {}) ⇒ void

This method returns an undefined value.

Send a JSON-RPC notification (no response expected)

Parameters:

  • method (String)

    JSON-RPC method name

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

    parameters for the notification



33
34
35
36
37
38
39
# File 'lib/mcp_client/server_sse/json_rpc_transport.rb', line 33

def rpc_notify(method, params = {})
  ensure_initialized
  notif = build_jsonrpc_notification(method, params)
  post_json_rpc_request(notif)
rescue MCPClient::Errors::ServerError, MCPClient::Errors::ConnectionError, Faraday::ConnectionFailed => e
  raise MCPClient::Errors::TransportError, "Failed to send notification: #{e.message}"
end

#rpc_request(method, params = {}) ⇒ Object

Generic JSON-RPC request: send method with params and return result

Parameters:

  • method (String)

    JSON-RPC method name

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

    parameters for the request

Returns:

  • (Object)

    result from JSON-RPC response

Raises:



19
20
21
22
23
24
25
26
27
# File 'lib/mcp_client/server_sse/json_rpc_transport.rb', line 19

def rpc_request(method, params = {})
  ensure_initialized

  with_retry do
    request_id = @mutex.synchronize { @request_id += 1 }
    request = build_jsonrpc_request(method, params, request_id)
    send_jsonrpc_request(request)
  end
end