Skip to content
Open
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: 2 additions & 2 deletions lib/ruby_llm/mcp/tool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ class Annotation
def initialize(annotation)
@title = annotation["title"] || ""
@read_only_hint = annotation["readOnlyHint"] || false
@destructive_hint = annotation["destructiveHint"] || true
@destructive_hint = annotation.fetch("destructiveHint", true)
@idempotent_hint = annotation["idempotentHint"] || false
@open_world_hint = annotation["openWorldHint"] || true
@open_world_hint = annotation.fetch("openWorldHint", true)
end

def to_h
Expand Down
14 changes: 5 additions & 9 deletions spec/ruby_llm/mcp/tool_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -958,14 +958,12 @@ def execute
describe RubyLLM::MCP::Annotation do
describe "#initialize" do
it "parses truthy annotation fields from hash" do
# NOTE: The implementation uses || for defaults, so false values get
# replaced with defaults. Only truthy values are preserved.
annotation_data = {
"title" => "My Custom Tool",
"readOnlyHint" => true,
"destructiveHint" => true, # Using true since false gets default
"destructiveHint" => true,
"idempotentHint" => true,
"openWorldHint" => true # Using true since false gets default
"openWorldHint" => true
}

annotation = described_class.new(annotation_data)
Expand Down Expand Up @@ -1000,16 +998,14 @@ def execute
expect(annotation.open_world_hint).to be(true) # Default
end

it "applies defaults when false is provided (current || behavior)" do
# This test documents the current behavior: false values get defaults
it "preserves an explicit false instead of falling back to the default" do
annotation = described_class.new({
"destructiveHint" => false,
"openWorldHint" => false
})

# Because || false returns the right-hand side default
expect(annotation.destructive_hint).to be(true) # Got default
expect(annotation.open_world_hint).to be(true) # Got default
expect(annotation.destructive_hint).to be(false)
expect(annotation.open_world_hint).to be(false)
end
end

Expand Down