Class: RubyLLM::MCP::Native::JsonRpc::EnvelopeValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm/mcp/native/json_rpc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#envelopeObject (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

#errorsObject (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_messageObject



35
36
37
# File 'lib/ruby_llm/mcp/native/json_rpc.rb', line 35

def error_message
  @errors.join("; ") if @errors.any?
end

#notification?Boolean

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


30
31
32
33
# File 'lib/ruby_llm/mcp/native/json_rpc.rb', line 30

def valid?
  validate!
  @errors.empty?
end