diff --git a/lib/mcp/server.rb b/lib/mcp/server.rb index 33fa8c1..74a4d09 100644 --- a/lib/mcp/server.rb +++ b/lib/mcp/server.rb @@ -31,12 +31,13 @@ def initialize(method_name) include Instrumentation - attr_accessor :name, :title, :version, :instructions, :tools, :prompts, :resources, :server_context, :configuration, :capabilities, :transport + attr_accessor :name, :title, :version, :website_url, :instructions, :tools, :prompts, :resources, :server_context, :configuration, :capabilities, :transport def initialize( name: "model_context_protocol", title: nil, version: DEFAULT_VERSION, + website_url: nil, instructions: nil, tools: [], prompts: [], @@ -50,6 +51,7 @@ def initialize( @name = name @title = title @version = version + @website_url = website_url @instructions = instructions @tools = tools.to_h { |t| [t.name_value, t] } @prompts = prompts.to_h { |p| [p.name_value, p] } @@ -176,8 +178,8 @@ def prompts_get_handler(&block) def validate! # NOTE: The draft protocol version is the next version after 2025-03-26. if @configuration.protocol_version <= "2025-03-26" - if server_info.key?(:title) - message = "Error occurred in server_info. `title` is not supported in protocol version 2025-03-26 or earlier" + if server_info.key?(:title) || server_info.key?(:websiteUrl) + message = "Error occurred in server_info. `title` or `website_url` are not supported in protocol version 2025-03-26 or earlier" raise ArgumentError, message end @@ -258,6 +260,7 @@ def server_info name:, title:, version:, + websiteUrl: website_url, }.compact end diff --git a/test/mcp/server_test.rb b/test/mcp/server_test.rb index dba9b80..cc7fa04 100644 --- a/test/mcp/server_test.rb +++ b/test/mcp/server_test.rb @@ -779,7 +779,22 @@ def call(message:, server_context: nil) assert_equal Configuration::DRAFT_PROTOCOL_VERSION, response[:result][:protocolVersion] end - test "server response does not include title when not configured" do + test "server response does not include optionnal parameters when configured" do + server = Server.new(title: "Example Server Display Name", name: "test_server", website_url: "https://example.com") + request = { + jsonrpc: "2.0", + method: "initialize", + id: 1, + } + + response = server.handle(request) + server_info = response[:result][:serverInfo] + + assert_equal("Example Server Display Name", server_info[:title]) + assert_equal("https://example.com", server_info[:websiteUrl]) + end + + test "server response does not include optionnal parameters when not configured" do server = Server.new(name: "test_server") request = { jsonrpc: "2.0", @@ -789,6 +804,7 @@ def call(message:, server_context: nil) response = server.handle(request) refute response[:result][:serverInfo].key?(:title) + refute response[:result][:serverInfo].key?(:website_url) end test "server uses default version when not configured" do @@ -858,7 +874,16 @@ def call(message:, server_context: nil) exception = assert_raises(ArgumentError) do Server.new(name: "test_server", title: "Example Server Display Name", configuration: configuration) end - assert_equal("Error occurred in server_info. `title` is not supported in protocol version 2025-03-26 or earlier", exception.message) + assert_equal("Error occurred in server_info. `title` or `website_url` are not supported in protocol version 2025-03-26 or earlier", exception.message) + end + + test "raises error if `website_url` of `server_info` is used with protocol version 2025-03-26" do + configuration = Configuration.new(protocol_version: "2025-03-26") + + exception = assert_raises(ArgumentError) do + Server.new(name: "test_server", website_url: "https://example.com", configuration: configuration) + end + assert_equal("Error occurred in server_info. `title` or `website_url` are not supported in protocol version 2025-03-26 or earlier", exception.message) end test "raises error if `title` of tool is used with protocol version 2025-03-26" do