Class: MCP::Tool::OutputSchema
- Inherits:
-
Object
- Object
- MCP::Tool::OutputSchema
- Defined in:
- lib/mcp/tool/output_schema.rb
Defined Under Namespace
Classes: ValidationError
Instance Attribute Summary collapse
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(schema = {}) ⇒ OutputSchema
constructor
A new instance of OutputSchema.
- #to_h ⇒ Object
- #validate_result(result) ⇒ Object
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
#schema ⇒ Object (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_h ⇒ Object
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 |