Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/mcp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand All @@ -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] }
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -258,6 +260,7 @@ def server_info
name:,
title:,
version:,
websiteUrl: website_url,
}.compact
end

Expand Down
29 changes: 27 additions & 2 deletions test/mcp/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down