Skip to content

Commit 271ccb4

Browse files
committed
fixes input schema validation for schemas without required fields
1 parent b94a938 commit 271ccb4

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/mcp/tool/input_schema.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ def initialize(properties: {}, required: [])
1616
end
1717

1818
def to_h
19-
{ type: "object", properties:, required: }
19+
{ type: "object", properties: }.tap do |hsh|
20+
hsh[:required] = required if required.any?
21+
end
2022
end
2123

2224
def missing_required_arguments?(arguments)

test/mcp/tool/input_schema_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ class InputSchemaTest < ActiveSupport::TestCase
4040
end
4141
end
4242

43+
test "schema without required arguments is valid" do
44+
assert_nothing_raised do
45+
InputSchema.new(properties: { foo: { type: "string" } })
46+
end
47+
end
48+
4349
test "validate arguments with valid data" do
4450
schema = InputSchema.new(properties: { foo: { type: "string" } }, required: [:foo])
4551
assert_nil(schema.validate_arguments({ foo: "bar" }))

0 commit comments

Comments
 (0)