Internal Release v0.1.1
- implement `Prompt` - adjust Tool approach - update readme for tool calling - document usage of `Prompt`
This commit is contained in:
commit
a4df3b8688
1 changed files with 1530 additions and 0 deletions
50
lib/model_context_protocol/json_rpc/request.rb
Normal file
50
lib/model_context_protocol/json_rpc/request.rb
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "json"
|
||||
|
||||
module ModelContextProtocol
|
||||
module JsonRPC
|
||||
class Request
|
||||
class << self
|
||||
def parse(json)
|
||||
parsed = JSON.parse(json)
|
||||
from_h(parsed)
|
||||
rescue JSON::ParserError => e
|
||||
raise ParseError.new(message: e.message)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def from_h(hash)
|
||||
new(version: hash["jsonrpc"], method: hash["method"], params: hash["params"], id: hash["id"])
|
||||
end
|
||||
end
|
||||
|
||||
attr_reader :version, :method, :params, :id
|
||||
|
||||
def initialize(version:, method:, params: nil, id: nil)
|
||||
@version = version
|
||||
@method = method
|
||||
@params = params
|
||||
@id = id
|
||||
end
|
||||
|
||||
def notification?
|
||||
id.nil?
|
||||
end
|
||||
|
||||
def valid?
|
||||
@version == JsonRPC::VERSION && !method.start_with?("rpc.")
|
||||
end
|
||||
|
||||
def method_not_found!
|
||||
raise MethodNotFoundError.new(message: "Method not found #{method}")
|
||||
end
|
||||
|
||||
def validate!
|
||||
raise InvalidRequestError.new(message: "Method cannot start with 'rpc.'") if method.start_with?("rpc.")
|
||||
raise InvalidRequestError.new(message: "Invalid JSON-RPC version") unless valid?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue