Skip to content

Commit b982074

Browse files
authored
Merge pull request #119 from koic/add_title_to_server_info
Add `title` to `serverInfo`
2 parents da471a2 + ef56280 commit b982074

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class ApplicationController < ActionController::Base
158158
def index
159159
server = MCP::Server.new(
160160
name: "my_server",
161+
title: "Example Server Display Name", # WARNING: This is a `Draft` and is not supported in the `Version 2025-06-18 (latest)` specification.
161162
version: "1.0.0",
162163
instructions: "Use the tools of this server as a last resort",
163164
tools: [SomeTool, AnotherTool],

lib/mcp/server.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ def initialize(method_name)
3131

3232
include Instrumentation
3333

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

3636
def initialize(
3737
name: "model_context_protocol",
38+
title: nil,
3839
version: DEFAULT_VERSION,
3940
instructions: nil,
4041
tools: [],
@@ -47,6 +48,7 @@ def initialize(
4748
transport: nil
4849
)
4950
@name = name
51+
@title = title
5052
@version = version
5153
@instructions = instructions
5254
@tools = tools.to_h { |t| [t.name_value, t] }
@@ -218,6 +220,7 @@ def default_capabilities
218220
def server_info
219221
@server_info ||= {
220222
name:,
223+
title:,
221224
version:,
222225
}
223226
end

test/mcp/server_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class ServerTest < ActiveSupport::TestCase
6969

7070
@server = Server.new(
7171
name: @server_name,
72+
title: "Example Server Display Name",
7273
version: "1.2.3",
7374
instructions: "Optional instructions for the client",
7475
tools: [@tool, @tool_that_raises],
@@ -140,6 +141,7 @@ class ServerTest < ActiveSupport::TestCase
140141
},
141142
serverInfo: {
142143
name: @server_name,
144+
title: "Example Server Display Name",
143145
version: "1.2.3",
144146
},
145147
instructions: "Optional instructions for the client",
@@ -769,6 +771,18 @@ def call(message:, server_context: nil)
769771
assert_equal Configuration::DEFAULT_PROTOCOL_VERSION, response[:result][:protocolVersion]
770772
end
771773

774+
test "server uses default title when not configured" do
775+
server = Server.new(name: "test_server")
776+
request = {
777+
jsonrpc: "2.0",
778+
method: "initialize",
779+
id: 1,
780+
}
781+
782+
response = server.handle(request)
783+
assert_nil response[:result][:serverInfo][:title]
784+
end
785+
772786
test "server uses default version when not configured" do
773787
server = Server.new(name: "test_server")
774788
request = {

0 commit comments

Comments
 (0)