Merge pull request #205 from koic/add_icons

Support `icons` parameter
This commit is contained in:
Koichi ITO 2026-01-03 01:46:43 +09:00 • committed by GitHub
commit ab4f0807d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 139 additions and 15 deletions

48
test/mcp/icon_test.rb Normal file
View file

@ -0,0 +1,48 @@
# frozen_string_literal: true
require "test_helper"
module MCP
class IconTest < ActiveSupport::TestCase
def test_initialization
icon = Icon.new(mime_type: "image/png", sizes: ["48x48", "96x96"], src: "https://example.com", theme: "light")
assert_equal("image/png", icon.mime_type)
assert_equal(["48x48", "96x96"], icon.sizes)
assert_equal("https://example.com", icon.src)
assert_equal("light", icon.theme)
assert_equal({ mimeType: "image/png", sizes: ["48x48", "96x96"], src: "https://example.com", theme: "light" }, icon.to_h)
end
def test_initialization_by_default
icon = Icon.new
assert_nil(icon.mime_type)
assert_nil(icon.sizes)
assert_nil(icon.src)
assert_nil(icon.theme)
assert_empty(icon.to_h)
end
def test_valid_theme_for_light
assert_nothing_raised do
Icon.new(theme: "light")
end
end
def test_valid_theme_for_dark
assert_nothing_raised do
Icon.new(theme: "dark")
end
end
def test_invalid_theme
exception = assert_raises(ArgumentError) do
Icon.new(theme: "unexpected")
end
assert_equal('The value of theme must specify "light" or "dark".', exception.message)
end
end
end

View file

@ -6,6 +6,7 @@ module MCP
class PromptTest < ActiveSupport::TestCase
class TestPrompt < Prompt
description "Test prompt"
icons [{ mimeType: "image/png", sizes: ["48x48", "96x96"], src: "https://example.com", theme: "light" }]
arguments [
Prompt::Argument.new(name: "test_argument", description: "Test argument", required: true),
]
@ -43,6 +44,7 @@ module MCP
class MockPrompt < Prompt
prompt_name "my_mock_prompt"
description "a mock prompt for testing"
icons [{ mimeType: "image/png", sizes: ["48x48", "96x96"], src: "https://example.com", theme: "light" }]
arguments [
Prompt::Argument.new(name: "test_argument", description: "Test argument", required: true),
]
@ -64,6 +66,7 @@ module MCP
assert_equal "my_mock_prompt", prompt.name_value
assert_equal "a mock prompt for testing", prompt.description
assert_equal([{ mimeType: "image/png", sizes: ["48x48", "96x96"], src: "https://example.com", theme: "light" }], prompt.icons)
assert_equal "test_argument", prompt.arguments.first.name
assert_equal "Test argument", prompt.arguments.first.description
assert prompt.arguments.first.required
@ -112,6 +115,7 @@ module MCP
name: "mock_prompt",
title: "Mock Prompt",
description: "a mock prompt for testing",
icons: [{ mimeType: "image/png", sizes: ["48x48", "96x96"], src: "https://example.com", theme: "light" }],
arguments: [
Prompt::Argument.new(
name: "test_argument",
@ -135,6 +139,7 @@ module MCP
assert_equal "mock_prompt", prompt.name_value
assert_equal "a mock prompt for testing", prompt.description
assert_equal([{ mimeType: "image/png", sizes: ["48x48", "96x96"], src: "https://example.com", theme: "light" }], prompt.icons)
assert_equal "test_argument", prompt.arguments.first.name
assert_equal "Test argument title", prompt.arguments.first.title
assert_equal "This is a test argument description", prompt.arguments.first.description

View file

@ -52,6 +52,7 @@ module MCP
name: "test-resource",
title: "Test Resource",
description: "Test resource",
icons: [{ mimeType: "image/png", sizes: ["48x48", "96x96"], src: "https://example.com", theme: "light" }],
mime_type: "text/plain",
)
@ -60,6 +61,7 @@ module MCP
name: "test-resource",
title: "Test Resource",
description: "Test resource",
icons: [{ mimeType: "image/png", sizes: ["48x48", "96x96"], src: "https://example.com", theme: "light" }],
mime_type: "text/plain",
)
@ -69,6 +71,7 @@ module MCP
@server = Server.new(
description: "Test server",
icons: [{ mimeType: "image/png", sizes: ["48x48", "96x96"], src: "https://example.com", theme: "light" }],
name: @server_name,
title: "Example Server Display Name",
version: "1.2.3",
@ -142,6 +145,7 @@ module MCP
},
serverInfo: {
description: "Test server",
icons: [{ mimeType: "image/png", sizes: ["48x48", "96x96"], src: "https://example.com", theme: "light" }],
name: @server_name,
title: "Example Server Display Name",
version: "1.2.3",

View file

@ -7,6 +7,7 @@ module MCP
class TestTool < Tool
tool_name "test_tool"
description "a test tool for testing"
icons [Icon.new(mime_type: "image/png", sizes: ["48x48", "96x96"], src: "https://example.com", theme: "light")]
input_schema({ properties: { message: { type: "string" } }, required: ["message"] })
annotations(
destructive_hint: false,
@ -26,13 +27,22 @@ module MCP
end
end
test "#to_h returns a hash with name, description, and inputSchema" do
test "#to_h returns a hash including name, description, icons, and inputSchema" do
expected = {
name: "mock_tool",
title: "Mock Tool",
description: "a mock tool for testing",
icons: [{ mimeType: "image/png", sizes: ["48x48", "96x96"], src: "https://example.com", theme: "light" }],
inputSchema: { type: "object" },
}
tool = Tool.define(
name: "mock_tool",
title: "Mock Tool",
description: "a mock tool for testing",
icons: [Icon.new(mime_type: "image/png", sizes: ["48x48", "96x96"], src: "https://example.com", theme: "light")],
)
assert_equal({ name: "mock_tool", title: "Mock Tool", description: "a mock tool for testing", inputSchema: { type: "object" } }, tool.to_h)
assert_equal(expected, tool.to_h)
end
test "#to_h does not have `:title` key when title is omitted" do
@ -308,19 +318,22 @@ module MCP
end
test "#to_h includes outputSchema when present" do
tool = Tool.define(
name: "mock_tool",
title: "Mock Tool",
description: "a mock tool for testing",
output_schema: { properties: { result: { type: "string" } }, required: ["result"] },
)
expected = {
name: "mock_tool",
title: "Mock Tool",
description: "a mock tool for testing",
icons: [{ mimeType: "image/png", sizes: ["48x48", "96x96"], src: "https://example.com", theme: "light" }],
inputSchema: { type: "object" },
outputSchema: { type: "object", properties: { result: { type: "string" } }, required: ["result"] },
}
tool = Tool.define(
name: "mock_tool",
title: "Mock Tool",
description: "a mock tool for testing",
icons: [Icon.new(mime_type: "image/png", sizes: ["48x48", "96x96"], src: "https://example.com", theme: "light")],
output_schema: { properties: { result: { type: "string" } }, required: ["result"] },
)
assert_equal expected, tool.to_h
end