Class: MCP::Tool::OutputSchema

Inherits:
Object
  • Object
show all
Defined in:
lib/mcp/tool/output_schema.rb

Defined Under Namespace

Classes: ValidationError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema = {}) ⇒ OutputSchema

Returns a new instance of OutputSchema.



12
13
14
15
16
# File 'lib/mcp/tool/output_schema.rb', line 12

def initialize(schema = {})
  @schema = deep_transform_keys(JSON.parse(JSON.dump(schema)), &:to_sym)
  @schema[:type] ||= "object"
  validate_schema!
end

Instance Attribute Details

#schemaObject (readonly)

Returns the value of attribute schema.



10
11
12
# File 'lib/mcp/tool/output_schema.rb', line 10

def schema
  @schema
end

Instance Method Details

#==(other) ⇒ Object



18
19
20
# File 'lib/mcp/tool/output_schema.rb', line 18

def ==(other)
  other.is_a?(OutputSchema) && schema == other.schema
end

#to_hObject



22
23
24
# File 'lib/mcp/tool/output_schema.rb', line 22

def to_h
  @schema
end

#validate_result(result) ⇒ Object



26
27
28
29
30
31
# File 'lib/mcp/tool/output_schema.rb', line 26

def validate_result(result)
  errors = JSON::Validator.fully_validate(to_h, result)
  if errors.any?
    raise ValidationError, "Invalid result: #{errors.join(", ")}"
  end
end