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.
40 lines
1.3 KiB
Ruby
40 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "test_helper"
|
|
|
|
module MCP
|
|
class ResourceTemplateTest < ActiveSupport::TestCase
|
|
test "#to_h does not have `:icons` key when icons is empty" do
|
|
resource_template = ResourceTemplate.new(
|
|
uri_template: "file:///{path}",
|
|
name: "resource_template_without_icons",
|
|
description: "a resource template without icons",
|
|
)
|
|
|
|
refute resource_template.to_h.key?(:icons)
|
|
end
|
|
|
|
test "#to_h does not have `:icons` key when icons is nil" do
|
|
resource_template = ResourceTemplate.new(
|
|
uri_template: "file:///{path}",
|
|
name: "resource_template_without_icons",
|
|
description: "a resource template without icons",
|
|
icons: nil,
|
|
)
|
|
|
|
refute resource_template.to_h.key?(:icons)
|
|
end
|
|
|
|
test "#to_h includes icons when present" do
|
|
resource_template = ResourceTemplate.new(
|
|
uri_template: "file:///{path}",
|
|
name: "resource_template_with_icons",
|
|
description: "a resource template with icons",
|
|
icons: [Icon.new(mime_type: "image/png", sizes: ["48x48"], src: "https://example.com", theme: "light")],
|
|
)
|
|
expected_icons = [{ mimeType: "image/png", sizes: ["48x48"], src: "https://example.com", theme: "light" }]
|
|
|
|
assert_equal expected_icons, resource_template.to_h[:icons]
|
|
end
|
|
end
|
|
end
|