Class: RubyLLM::MCP::Native::JsonRpc::EnvelopeValidator
- Inherits:
-
Object
- Object
- RubyLLM::MCP::Native::JsonRpc::EnvelopeValidator
- Defined in:
- lib/ruby_llm/mcp/native/json_rpc.rb
Instance Attribute Summary collapse
-
#envelope ⇒ Object
readonly
Returns the value of attribute envelope.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
- #error_message ⇒ Object
-
#initialize(envelope) ⇒ EnvelopeValidator
constructor
A new instance of EnvelopeValidator.
- #notification? ⇒ Boolean
- #request? ⇒ Boolean
- #response? ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(envelope) ⇒ EnvelopeValidator
Returns a new instance of EnvelopeValidator.
25 26 27 28 |
# File 'lib/ruby_llm/mcp/native/json_rpc.rb', line 25 def initialize(envelope) @envelope = envelope @errors = [] end |
Instance Attribute Details
#envelope ⇒ Object (readonly)
Returns the value of attribute envelope.
23 24 25 |
# File 'lib/ruby_llm/mcp/native/json_rpc.rb', line 23 def envelope @envelope end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
23 24 25 |
# File 'lib/ruby_llm/mcp/native/json_rpc.rb', line 23 def errors @errors end |
Instance Method Details
#error_message ⇒ Object
35 36 37 |
# File 'lib/ruby_llm/mcp/native/json_rpc.rb', line 35 def @errors.join("; ") if @errors.any? end |
#notification? ⇒ Boolean
39 40 41 |
# File 'lib/ruby_llm/mcp/native/json_rpc.rb', line 39 def notification? !envelope.key?("id") && envelope.key?("method") end |
#request? ⇒ Boolean
43 44 45 46 |
# File 'lib/ruby_llm/mcp/native/json_rpc.rb', line 43 def request? envelope.key?("id") && envelope.key?("method") && !envelope.key?("result") && !envelope.key?("error") end |
#response? ⇒ Boolean
48 49 50 51 |
# File 'lib/ruby_llm/mcp/native/json_rpc.rb', line 48 def response? envelope.key?("id") && !envelope.key?("method") && (envelope.key?("result") || envelope.key?("error")) end |
#valid? ⇒ Boolean
30 31 32 33 |
# File 'lib/ruby_llm/mcp/native/json_rpc.rb', line 30 def valid? validate! @errors.empty? end |