ruby-sdk/lib/model_context_protocol/json_rpc/response.rb
Topher Bullock a4df3b8688 Internal Release v0.1.1
- implement `Prompt`
- adjust Tool approach
- update readme for tool calling
- document usage of `Prompt`
2025-05-08 17:37:27 -04:00

29 lines
681 B
Ruby

# frozen_string_literal: true
module ModelContextProtocol
module JsonRPC
class Response
attr_reader :version, :result, :error, :id
def initialize(result: nil, error: nil, id: nil)
@version = VERSION
@result = result
@error = error
@id = id
validate!
end
def to_h
{ id:, result:, jsonrpc: @version, error: @error&.to_h }.compact
end
private
def validate!
raise InvalidResponse, "Result and error cannot both be present" if @result && @error
raise InvalidResponse, "Either result or error must be present" if @result.nil? && @error.nil?
end
end
end
end