Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion lib/ruby_llm/mcp/parameter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(name, type: "string", desc: nil, required: true, default: nil, un
end

def item_type
@items["type"].to_sym
@items&.[]("type")&.to_sym
Copy link
Copy Markdown
Owner

@patvice patvice Jul 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible to use dig on this, that's the pattern that used in other locations in the codebase

@items&.dig("type")&.to_sym

end
end
end
Expand Down
54 changes: 54 additions & 0 deletions spec/ruby_llm/mcp/parameter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true

RSpec.describe RubyLLM::MCP::Parameter do
describe "#item_type" do
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at your specs, we are missing the case that kicked off the issue in the first place. An array type without a item type attached. Possible to add that case?

context "when @items is nil" do
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These context block was just on it statments - can you collapse them down or bucket some it statements together

it "returns nil" do
parameter = described_class.new("test_param", type: "string")
expect(parameter.item_type).to be_nil
end
end

context "when @items is empty hash" do
it "returns nil" do
parameter = described_class.new("test_param", type: "string")
parameter.items = {}
expect(parameter.item_type).to be_nil
end
end

context "when @items['type'] is nil" do
it "returns nil" do
parameter = described_class.new("test_param", type: "string")
parameter.items = { "other_key" => "value" }
expect(parameter.item_type).to be_nil
end
end

context "when @items['type'] has a value" do
it "returns the type as a symbol" do
parameter = described_class.new("test_param", type: "array")
parameter.items = { "type" => "string" }
expect(parameter.item_type).to eq(:string)
end
end
end

describe "#initialize" do
it "creates a parameter with default values" do
parameter = described_class.new("test_param")
expect(parameter.name).to eq("test_param")
expect(parameter.type).to eq(:string)
expect(parameter.required).to be(true)
expect(parameter.items).to be_nil
end

it "creates a parameter with custom values" do
parameter = described_class.new("test_param", type: "array", desc: "Test description", required: false)
expect(parameter.name).to eq("test_param")
expect(parameter.type).to eq(:array)
expect(parameter.desc).to eq("Test description")
expect(parameter.required).to be(false)
end
end
end
Loading