Module: GroqRuby::MCP::JsonRpc
- Defined in:
- lib/groq_ruby/mcp/json_rpc.rb
Overview
Pure builders for JSON-RPC 2.0 messages. No IO, no state — call these to produce the Hash you’ll hand to a transport.
Constant Summary collapse
- VERSION =
"2.0".freeze
Class Method Summary collapse
-
.classify(message) ⇒ Symbol
Categorise a parsed inbound message.
-
.notification(method:, params: nil) ⇒ Hash
Build a notification envelope (request without id — no response).
-
.request(id:, method:, params: nil) ⇒ Hash
Build a request envelope.
Class Method Details
.classify(message) ⇒ Symbol
Categorise a parsed inbound message. Returns one of: ‘:response`, `:notification`, `:request`, `:invalid`.
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/groq_ruby/mcp/json_rpc.rb', line 37 def self.classify() return :invalid unless .is_a?(Hash) && ["jsonrpc"] == VERSION if .key?("id") && (.key?("result") || .key?("error")) :response elsif .key?("method") && !.key?("id") :notification elsif .key?("method") && .key?("id") :request else :invalid end end |
.notification(method:, params: nil) ⇒ Hash
Build a notification envelope (request without id — no response).
26 27 28 29 30 |
# File 'lib/groq_ruby/mcp/json_rpc.rb', line 26 def self.notification(method:, params: nil) payload = {jsonrpc: VERSION, method: method} payload[:params] = params unless params.nil? payload end |
.request(id:, method:, params: nil) ⇒ Hash
Build a request envelope. Pair ‘id` with the Hash returned from a subsequent inbound response to correlate.
15 16 17 18 19 |
# File 'lib/groq_ruby/mcp/json_rpc.rb', line 15 def self.request(id:, method:, params: nil) payload = {jsonrpc: VERSION, id: id, method: method} payload[:params] = params unless params.nil? payload end |