Skip to content

Commit 43f9409

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 d31c3da commit 43f9409

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,12 +31,13 @@ def initialize(method_name)
3131

3232
include Instrumentation
3333

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

3636
def initialize(
3737
name: "model_context_protocol",
3838
title: nil,
3939
version: DEFAULT_VERSION,
40+
website_url: nil,
4041
instructions: nil,
4142
tools: [],
4243
prompts: [],
@@ -50,6 +51,7 @@ def initialize(
5051
@name = name
5152
@title = title
5253
@version = version
54+
@website_url = website_url
5355
@instructions = instructions
5456
@tools = tools.to_h { |t| [t.name_value, t] }
5557
@prompts = prompts.to_h { |p| [p.name_value, p] }
@@ -176,8 +178,8 @@ def prompts_get_handler(&block)
176178
def validate!
177179
# NOTE: The draft protocol version is the next version after 2025-03-26.
178180
if @configuration.protocol_version <= "2025-03-26"
179-
if server_info.key?(:title)
180-
message = "Error occurred in server_info. `title` is not supported in protocol version 2025-03-26 or earlier"
181+
if server_info.key?(:title) || server_info.key?(:websiteUrl)
182+
message = "Error occurred in server_info. `title` or `website_url` are not supported in protocol version 2025-03-26 or earlier"
181183
raise ArgumentError, message
182184
end
183185

@@ -258,6 +260,7 @@ def server_info
258260
name:,
259261
title:,
260262
version:,
263+
websiteUrl: website_url,
261264
}.compact
262265
end
263266

test/mcp/server_test.rb

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

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

790805
response = server.handle(request)
791806
refute response[:result][:serverInfo].key?(:title)
807+
refute response[:result][:serverInfo].key?(:website_url)
792808
end
793809

794810
test "server uses default version when not configured" do
@@ -858,7 +874,16 @@ def call(message:, server_context: nil)
858874
exception = assert_raises(ArgumentError) do
859875
Server.new(name: "test_server", title: "Example Server Display Name", configuration: configuration)
860876
end
861-
assert_equal("Error occurred in server_info. `title` is not supported in protocol version 2025-03-26 or earlier", exception.message)
877+
assert_equal("Error occurred in server_info. `title` or `website_url` are not supported in protocol version 2025-03-26 or earlier", exception.message)
878+
end
879+
880+
test "raises error if `website_url` of `server_info` is used with protocol version 2025-03-26" do
881+
configuration = Configuration.new(protocol_version: "2025-03-26")
882+
883+
exception = assert_raises(ArgumentError) do
884+
Server.new(name: "test_server", website_url: "https://example.com", configuration: configuration)
885+
end
886+
assert_equal("Error occurred in server_info. `title` or `website_url` are not supported in protocol version 2025-03-26 or earlier", exception.message)
862887
end
863888

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

0 commit comments

Comments
 (0)