Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/mcp/tool/input_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ def initialize(properties: {}, required: [])
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)
Expand Down
6 changes: 6 additions & 0 deletions test/mcp/tool/input_schema_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class InputSchemaTest < ActiveSupport::TestCase
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" }))
Expand Down