Class: OmniAI::MCP::JRPC::Request
- Inherits:
-
Object
- Object
- OmniAI::MCP::JRPC::Request
- Defined in:
- lib/omniai/mcp/jrpc/request.rb
Overview
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #generate ⇒ String
-
#initialize(id:, method:, params:) ⇒ Request
constructor
A new instance of Request.
- #inspect ⇒ String
Constructor Details
#initialize(id:, method:, params:) ⇒ Request
Returns a new instance of Request.
27 28 29 30 31 |
# File 'lib/omniai/mcp/jrpc/request.rb', line 27 def initialize(id:, method:, params:) @id = id @method = method @params = params end |
Instance Attribute Details
#id ⇒ Integer
14 15 16 |
# File 'lib/omniai/mcp/jrpc/request.rb', line 14 def id @id end |
#method ⇒ String
18 19 20 |
# File 'lib/omniai/mcp/jrpc/request.rb', line 18 def method @method end |
#params ⇒ Hash
22 23 24 |
# File 'lib/omniai/mcp/jrpc/request.rb', line 22 def params @params end |
Class Method Details
.parse(text) ⇒ OmniAI::MCP::JRPC::Request
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/omniai/mcp/jrpc/request.rb', line 53 def self.parse(text) data = begin JSON.parse(text) rescue JSON::ParserError => e raise Error.new(code: Error::Code::PARSE_ERROR, message: e.) end id = data["id"] || raise(Error.new(code: Error::Code::PARSE_ERROR, message: "missing id")) method = data["method"] || raise(Error.new(code: Error::Code::PARSE_ERROR, message: "missing method")) params = data["params"] || raise(Error.new(code: Error::Code::PARSE_ERROR, message: "missing params")) new(id:, method:, params:) end |
Instance Method Details
#generate ⇒ String
39 40 41 42 43 44 45 46 |
# File 'lib/omniai/mcp/jrpc/request.rb', line 39 def generate JSON.generate({ jsonrpc: VERSION, id: @id, method: @method, params: @params, }) end |
#inspect ⇒ String
34 35 36 |
# File 'lib/omniai/mcp/jrpc/request.rb', line 34 def inspect "#<#{self.class.name} id=#{@id} method=#{@method} params=#{@params}>" end |