Skip to content

Commit 2fa9916

Browse files
committed
Add support for the optional websiteUrl parameter in serverInfo
This PR adds support for the optional `websiteUrl` parameter in `serverInfo`. This parameter has been supported since the 2025-11-25 MCP specification. This PR also implements part of #127.
1 parent 171baa8 commit 2fa9916

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

lib/mcp/server.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ def initialize(method_name)
3131

3232
include Instrumentation
3333

34-
attr_accessor :description, :name, :title, :version, :instructions, :tools, :prompts, :resources, :server_context, :configuration, :capabilities, :transport
34+
attr_accessor :description, :name, :title, :version, :website_url, :instructions, :tools, :prompts, :resources, :server_context, :configuration, :capabilities, :transport
3535

3636
def initialize(
3737
description: nil,
3838
name: "model_context_protocol",
3939
title: nil,
4040
version: DEFAULT_VERSION,
41+
website_url: nil,
4142
instructions: nil,
4243
tools: [],
4344
prompts: [],
@@ -52,6 +53,7 @@ def initialize(
5253
@name = name
5354
@title = title
5455
@version = version
56+
@website_url = website_url
5557
@instructions = instructions
5658
@tools = tools.to_h { |t| [t.name_value, t] }
5759
@prompts = prompts.to_h { |p| [p.name_value, p] }
@@ -185,8 +187,8 @@ def validate!
185187
end
186188

187189
if @configuration.protocol_version <= "2025-03-26"
188-
if server_info.key?(:title)
189-
message = "Error occurred in server_info. `title` is not supported in protocol version 2025-03-26 or earlier"
190+
if server_info.key?(:title) || server_info.key?(:websiteUrl)
191+
message = "Error occurred in server_info. `title` or `website_url` are not supported in protocol version 2025-03-26 or earlier"
190192
raise ArgumentError, message
191193
end
192194

@@ -268,6 +270,7 @@ def server_info
268270
name:,
269271
title:,
270272
version:,
273+
websiteUrl: website_url,
271274
}.compact
272275
end
273276

test/mcp/server_test.rb

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,22 @@ def call(message:, server_context: nil)
781781
assert_equal Configuration::LATEST_STABLE_PROTOCOL_VERSION, response[:result][:protocolVersion]
782782
end
783783

784-
test "server response does not include title when not configured" do
784+
test "server response does not include optionnal parameters when configured" do
785+
server = Server.new(title: "Example Server Display Name", name: "test_server", website_url: "https://example.com")
786+
request = {
787+
jsonrpc: "2.0",
788+
method: "initialize",
789+
id: 1,
790+
}
791+
792+
response = server.handle(request)
793+
server_info = response[:result][:serverInfo]
794+
795+
assert_equal("Example Server Display Name", server_info[:title])
796+
assert_equal("https://example.com", server_info[:websiteUrl])
797+
end
798+
799+
test "server response does not include optionnal parameters when not configured" do
785800
server = Server.new(name: "test_server")
786801
request = {
787802
jsonrpc: "2.0",
@@ -791,6 +806,7 @@ def call(message:, server_context: nil)
791806

792807
response = server.handle(request)
793808
refute response[:result][:serverInfo].key?(:title)
809+
refute response[:result][:serverInfo].key?(:website_url)
794810
end
795811

796812
test "server uses default version when not configured" do
@@ -875,7 +891,16 @@ def call(message:, server_context: nil)
875891
exception = assert_raises(ArgumentError) do
876892
Server.new(name: "test_server", title: "Example Server Display Name", configuration: configuration)
877893
end
878-
assert_equal("Error occurred in server_info. `title` is not supported in protocol version 2025-03-26 or earlier", exception.message)
894+
assert_equal("Error occurred in server_info. `title` or `website_url` are not supported in protocol version 2025-03-26 or earlier", exception.message)
895+
end
896+
897+
test "raises error if `website_url` of `server_info` is used with protocol version 2025-03-26" do
898+
configuration = Configuration.new(protocol_version: "2025-03-26")
899+
900+
exception = assert_raises(ArgumentError) do
901+
Server.new(name: "test_server", website_url: "https://example.com", configuration: configuration)
902+
end
903+
assert_equal("Error occurred in server_info. `title` or `website_url` are not supported in protocol version 2025-03-26 or earlier", exception.message)
879904
end
880905

881906
test "raises error if `title` of tool is used with protocol version 2025-03-26" do

0 commit comments

Comments
 (0)