Merge pull request #73 from planio-gmbh/fix/input-schema-without-required-fields

fixes input schema validation for schemas without required fields
This commit is contained in:
Ateş Göral 2025-07-11 07:18:49 -04:00 • committed by GitHub
commit 2a7511c8f2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View file

@ -16,7 +16,9 @@ module MCP
end
def to_h
{ type: "object", properties:, required: }
{ type: "object", properties: }.tap do |hsh|
hsh[:required] = required if required.any?
end
end
def missing_required_arguments?(arguments)

View file

@ -40,6 +40,12 @@ module MCP
end
end
test "schema without required arguments is valid" do
assert_nothing_raised do
InputSchema.new(properties: { foo: { type: "string" } })
end
end
test "validate arguments with valid data" do
schema = InputSchema.new(properties: { foo: { type: "string" } }, required: [:foo])
assert_nil(schema.validate_arguments({ foo: "bar" }))