fixes input schema validation for schemas without required fields

This commit is contained in:
Jens Kraemer 2025-07-11 11:27:59 +02:00
commit 271ccb43d0
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" }))