Merge pull request #126 from koic/fix_errors_when_title_is_not_specified

Fix errors when `title` is not specified
This commit is contained in:
Koichi ITO 2025-09-11 10:30:15 +09:00 • committed by GitHub
commit dd5b318b11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 12 additions and 4 deletions

View file

@ -222,7 +222,7 @@ module MCP
name:,
title:,
version:,
}
}.compact
end
def init(request)

View file

@ -19,7 +19,7 @@ module MCP
title: title_value,
description: description_value,
inputSchema: input_schema_value.to_h,
}
}.compact
result[:annotations] = annotations_value.to_h if annotations_value
result
end

View file

@ -771,7 +771,7 @@ module MCP
assert_equal Configuration::DEFAULT_PROTOCOL_VERSION, response[:result][:protocolVersion]
end
test "server uses default title when not configured" do
test "server response does not include title when not configured" do
server = Server.new(name: "test_server")
request = {
jsonrpc: "2.0",
@ -780,7 +780,7 @@ module MCP
}
response = server.handle(request)
assert_nil response[:result][:serverInfo][:title]
refute response[:result][:serverInfo].key?(:title)
end
test "server uses default version when not configured" do

View file

@ -33,6 +33,14 @@ module MCP
assert_equal({ name: "mock_tool", title: "Mock Tool", description: "a mock tool for testing", inputSchema: { type: "object" } }, tool.to_h)
end
test "#to_h does not have `:title` key when title is omitted" do
tool = Tool.define(
name: "mock_tool",
description: "a mock tool for testing",
)
refute tool.to_h.key?(:title)
end
test "#to_h includes annotations when present" do
tool = TestTool
expected_annotations = {