Omit icons from responses when empty or nil

Previously, the `icons` parameter was always included in responses (as an empty array)
even when not configured. This differs from the response representation in MCP Ruby SDK 0.4.0.

Since `icons` is optional, it should be omitted from responses when unused to reduce
unnecessary context window usage.
https://modelcontextprotocol.io/specification/2025-11-25/schema#implementation

This fix applies to `Tool#to_h`, `Prompt#to_h`, `Resource#to_h`, `ResourceTemplate#to_h`,
and `Server#server_info`.

It doesn't seem critical, but if there are no other issues, it would be good to cut 0.5.1 bugfix release soon.
This commit is contained in:
Koichi ITO 2026-01-12 09:39:18 +09:00
commit bd416c7a5f

View file

@ -195,5 +195,24 @@ module MCP
assert_equal expected, prompt.to_h
end
test "#to_h does not have `:icons` key when icons is empty" do
prompt = Prompt.define(
name: "prompt_without_icons",
description: "a prompt without icons",
)
refute prompt.to_h.key?(:icons)
end
test "#to_h does not have `:icons` key when icons is nil" do
prompt = Prompt.define(
name: "prompt_without_icons",
description: "a prompt without icons",
icons: nil,
)
refute prompt.to_h.key?(:icons)
end
end
end