Skip to content

Commit 771163c

Browse files
authored
Merge pull request #188 from koic/add_website_url_to_server_info
Add support for the optional `websiteUrl` parameter in `serverInfo`
2 parents 8d68fc0 + 62615d6 commit 771163c

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
@@ -40,13 +40,14 @@ def initialize(method_name)
4040

4141
include Instrumentation
4242

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

4545
def initialize(
4646
description: nil,
4747
name: "model_context_protocol",
4848
title: nil,
4949
version: DEFAULT_VERSION,
50+
website_url: nil,
5051
instructions: nil,
5152
tools: [],
5253
prompts: [],
@@ -61,6 +62,7 @@ def initialize(
6162
@name = name
6263
@title = title
6364
@version = version
65+
@website_url = website_url
6466
@instructions = instructions
6567
@tool_names = tools.map(&:name_value)
6668
@tools = tools.to_h { |t| [t.name_value, t] }
@@ -200,8 +202,8 @@ def validate!
200202
end
201203

202204
if @configuration.protocol_version <= "2025-03-26"
203-
if server_info.key?(:title)
204-
message = "Error occurred in server_info. `title` is not supported in protocol version 2025-03-26 or earlier"
205+
if server_info.key?(:title) || server_info.key?(:websiteUrl)
206+
message = "Error occurred in server_info. `title` or `website_url` are not supported in protocol version 2025-03-26 or earlier"
205207
raise ArgumentError, message
206208
end
207209

@@ -289,6 +291,7 @@ def server_info
289291
name:,
290292
title:,
291293
version:,
294+
websiteUrl: website_url,
292295
}.compact
293296
end
294297

test/mcp/server_test.rb

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,22 @@ class Example < Tool
819819
assert_equal Configuration::LATEST_STABLE_PROTOCOL_VERSION, response[:result][:protocolVersion]
820820
end
821821

822-
test "server response does not include title when not configured" do
822+
test "server response does not include optional parameters when configured" do
823+
server = Server.new(title: "Example Server Display Name", name: "test_server", website_url: "https://example.com")
824+
request = {
825+
jsonrpc: "2.0",
826+
method: "initialize",
827+
id: 1,
828+
}
829+
830+
response = server.handle(request)
831+
server_info = response[:result][:serverInfo]
832+
833+
assert_equal("Example Server Display Name", server_info[:title])
834+
assert_equal("https://example.com", server_info[:websiteUrl])
835+
end
836+
837+
test "server response does not include optional parameters when not configured" do
823838
server = Server.new(name: "test_server")
824839
request = {
825840
jsonrpc: "2.0",
@@ -829,6 +844,7 @@ class Example < Tool
829844

830845
response = server.handle(request)
831846
refute response[:result][:serverInfo].key?(:title)
847+
refute response[:result][:serverInfo].key?(:website_url)
832848
end
833849

834850
test "server uses default version when not configured" do
@@ -913,7 +929,16 @@ class Example < Tool
913929
exception = assert_raises(ArgumentError) do
914930
Server.new(name: "test_server", title: "Example Server Display Name", configuration: configuration)
915931
end
916-
assert_equal("Error occurred in server_info. `title` is not supported in protocol version 2025-03-26 or earlier", exception.message)
932+
assert_equal("Error occurred in server_info. `title` or `website_url` are not supported in protocol version 2025-03-26 or earlier", exception.message)
933+
end
934+
935+
test "raises error if `website_url` of `server_info` is used with protocol version 2025-03-26" do
936+
configuration = Configuration.new(protocol_version: "2025-03-26")
937+
938+
exception = assert_raises(ArgumentError) do
939+
Server.new(name: "test_server", website_url: "https://example.com", configuration: configuration)
940+
end
941+
assert_equal("Error occurred in server_info. `title` or `website_url` are not supported in protocol version 2025-03-26 or earlier", exception.message)
917942
end
918943

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

0 commit comments

Comments
 (0)