Merge pull request #201 from koic/add_description_to_server_info
Add support for the optional `description` parameter in `serverInfo`
This commit is contained in:
commit
171baa876e
2 changed files with 28 additions and 1 deletions
|
|
@ -31,9 +31,10 @@ module MCP
|
|||
|
||||
include Instrumentation
|
||||
|
||||
attr_accessor :name, :title, :version, :instructions, :tools, :prompts, :resources, :server_context, :configuration, :capabilities, :transport
|
||||
attr_accessor :description, :name, :title, :version, :instructions, :tools, :prompts, :resources, :server_context, :configuration, :capabilities, :transport
|
||||
|
||||
def initialize(
|
||||
description: nil,
|
||||
name: "model_context_protocol",
|
||||
title: nil,
|
||||
version: DEFAULT_VERSION,
|
||||
|
|
@ -47,6 +48,7 @@ module MCP
|
|||
capabilities: nil,
|
||||
transport: nil
|
||||
)
|
||||
@description = description
|
||||
@name = name
|
||||
@title = title
|
||||
@version = version
|
||||
|
|
@ -175,6 +177,13 @@ module MCP
|
|||
|
||||
def validate!
|
||||
# NOTE: The draft protocol version is the next version after 2025-11-25.
|
||||
if @configuration.protocol_version <= "2025-06-18"
|
||||
if server_info.key?(:description)
|
||||
message = "Error occurred in server_info. `description` is not supported in protocol version 2025-06-18 or earlier"
|
||||
raise ArgumentError, message
|
||||
end
|
||||
end
|
||||
|
||||
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"
|
||||
|
|
@ -255,6 +264,7 @@ module MCP
|
|||
|
||||
def server_info
|
||||
@server_info ||= {
|
||||
description:,
|
||||
name:,
|
||||
title:,
|
||||
version:,
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ module MCP
|
|||
configuration.instrumentation_callback = instrumentation_helper.callback
|
||||
|
||||
@server = Server.new(
|
||||
description: "Test server",
|
||||
name: @server_name,
|
||||
title: "Example Server Display Name",
|
||||
version: "1.2.3",
|
||||
|
|
@ -140,6 +141,7 @@ module MCP
|
|||
tools: { listChanged: true },
|
||||
},
|
||||
serverInfo: {
|
||||
description: "Test server",
|
||||
name: @server_name,
|
||||
title: "Example Server Display Name",
|
||||
version: "1.2.3",
|
||||
|
|
@ -815,6 +817,21 @@ module MCP
|
|||
refute response[:result].key?(:instructions)
|
||||
end
|
||||
|
||||
test "server uses description when configured with protocol version 2025-11-25" do
|
||||
configuration = Configuration.new(protocol_version: "2025-11-25")
|
||||
server = Server.new(description: "This is the MCP server used during tests.", name: "test_server", configuration: configuration)
|
||||
assert_equal("This is the MCP server used during tests.", server.description)
|
||||
end
|
||||
|
||||
test "raises error if description is used with protocol version 2025-06-18" do
|
||||
configuration = Configuration.new(protocol_version: "2025-06-18")
|
||||
|
||||
exception = assert_raises(ArgumentError) do
|
||||
Server.new(description: "This is the MCP server used during tests.", name: "test_server", configuration: configuration)
|
||||
end
|
||||
assert_equal("Error occurred in server_info. `description` is not supported in protocol version 2025-06-18 or earlier", exception.message)
|
||||
end
|
||||
|
||||
test "server uses instructions when configured with protocol version 2025-03-26" do
|
||||
configuration = Configuration.new(protocol_version: "2025-03-26")
|
||||
server = Server.new(name: "test_server", instructions: "The server instructions.", configuration: configuration)
|
||||
|
|
|
|||
Loading…
Reference in a new issue