Class: ModelContextProtocol::RSpec::Matchers::BeValidMcpToolResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/model_context_protocol/rspec/matchers/be_valid_mcp_tool_response.rb

Constant Summary collapse

MCP_CONTENT_TYPES =
%w[text image audio resource resource_link].freeze

Instance Method Summary collapse

Constructor Details

#initializeBeValidMcpToolResponse

Returns a new instance of BeValidMcpToolResponse.



18
19
20
# File 'lib/model_context_protocol/rspec/matchers/be_valid_mcp_tool_response.rb', line 18

def initialize
  @failure_reasons = []
end

Instance Method Details

#descriptionObject



43
44
45
# File 'lib/model_context_protocol/rspec/matchers/be_valid_mcp_tool_response.rb', line 43

def description
  "be a valid MCP tool response"
end

#failure_messageObject



34
35
36
37
# File 'lib/model_context_protocol/rspec/matchers/be_valid_mcp_tool_response.rb', line 34

def failure_message
  "expected #{@actual.class} to be a valid MCP tool response, but:\n" +
    @failure_reasons.map { |reason| "  - #{reason}" }.join("\n")
end

#failure_message_when_negatedObject



39
40
41
# File 'lib/model_context_protocol/rspec/matchers/be_valid_mcp_tool_response.rb', line 39

def failure_message_when_negated
  "expected #{@actual.class} not to be a valid MCP tool response, but it was"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
31
32
# File 'lib/model_context_protocol/rspec/matchers/be_valid_mcp_tool_response.rb', line 22

def matches?(actual)
  @actual = actual
  @failure_reasons = []
  @serialized = serialize_response(actual)

  return false if @serialized.nil?

  validate_structure &&
    validate_content &&
    validate_is_error_flag
end