Class: MCP::Tool::InputSchema
- Inherits:
-
Object
- Object
- MCP::Tool::InputSchema
- Defined in:
- lib/mcp/tool/input_schema.rb
Defined Under Namespace
Classes: ValidationError
Instance Attribute Summary collapse
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(properties: {}, required: []) ⇒ InputSchema
constructor
A new instance of InputSchema.
- #missing_required_arguments(arguments) ⇒ Object
- #missing_required_arguments?(arguments) ⇒ Boolean
- #to_h ⇒ Object
- #validate_arguments(arguments) ⇒ Object
Constructor Details
#initialize(properties: {}, required: []) ⇒ InputSchema
Returns a new instance of InputSchema.
12 13 14 15 16 |
# File 'lib/mcp/tool/input_schema.rb', line 12 def initialize(properties: {}, required: []) @properties = properties @required = required.map(&:to_sym) validate_schema! end |
Instance Attribute Details
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
10 11 12 |
# File 'lib/mcp/tool/input_schema.rb', line 10 def properties @properties end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
10 11 12 |
# File 'lib/mcp/tool/input_schema.rb', line 10 def required @required end |
Instance Method Details
#==(other) ⇒ Object
18 19 20 |
# File 'lib/mcp/tool/input_schema.rb', line 18 def ==(other) other.is_a?(InputSchema) && properties == other.properties && required == other.required end |
#missing_required_arguments(arguments) ⇒ Object
33 34 35 |
# File 'lib/mcp/tool/input_schema.rb', line 33 def missing_required_arguments(arguments) (required - arguments.keys.map(&:to_sym)) end |
#missing_required_arguments?(arguments) ⇒ Boolean
29 30 31 |
# File 'lib/mcp/tool/input_schema.rb', line 29 def missing_required_arguments?(arguments) missing_required_arguments(arguments).any? end |
#to_h ⇒ Object
22 23 24 25 26 27 |
# File 'lib/mcp/tool/input_schema.rb', line 22 def to_h { type: "object" }.tap do |hsh| hsh[:properties] = properties if properties.any? hsh[:required] = required if required.any? end end |
#validate_arguments(arguments) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/mcp/tool/input_schema.rb', line 37 def validate_arguments(arguments) errors = JSON::Validator.fully_validate(to_h, arguments) if errors.any? raise ValidationError, "Invalid arguments: #{errors.join(", ")}" end end |