Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class ApplicationController < ActionController::Base
def index
server = MCP::Server.new(
name: "my_server",
title: "Example Server Display Name", # WARNING: This is a `Draft` and is not supported in the `Version 2025-06-18 (latest)` specification.
version: "1.0.0",
instructions: "Use the tools of this server as a last resort",
tools: [SomeTool, AnotherTool],
Expand Down
5 changes: 4 additions & 1 deletion lib/mcp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ def initialize(method_name)

include Instrumentation

attr_accessor :name, :version, :instructions, :tools, :prompts, :resources, :server_context, :configuration, :capabilities, :transport
attr_accessor :name, :title, :version, :instructions, :tools, :prompts, :resources, :server_context, :configuration, :capabilities, :transport

def initialize(
name: "model_context_protocol",
title: nil,
version: DEFAULT_VERSION,
instructions: nil,
tools: [],
Expand All @@ -47,6 +48,7 @@ def initialize(
transport: nil
)
@name = name
@title = title
@version = version
@instructions = instructions
@tools = tools.to_h { |t| [t.name_value, t] }
Expand Down Expand Up @@ -218,6 +220,7 @@ def default_capabilities
def server_info
@server_info ||= {
name:,
title:,
version:,
}
end
Expand Down
14 changes: 14 additions & 0 deletions test/mcp/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class ServerTest < ActiveSupport::TestCase

@server = Server.new(
name: @server_name,
title: "Example Server Display Name",
version: "1.2.3",
instructions: "Optional instructions for the client",
tools: [@tool, @tool_that_raises],
Expand Down Expand Up @@ -140,6 +141,7 @@ class ServerTest < ActiveSupport::TestCase
},
serverInfo: {
name: @server_name,
title: "Example Server Display Name",
version: "1.2.3",
},
instructions: "Optional instructions for the client",
Expand Down Expand Up @@ -769,6 +771,18 @@ def call(message:, server_context: nil)
assert_equal Configuration::DEFAULT_PROTOCOL_VERSION, response[:result][:protocolVersion]
end

test "server uses default title when not configured" do
server = Server.new(name: "test_server")
request = {
jsonrpc: "2.0",
method: "initialize",
id: 1,
}

response = server.handle(request)
assert_nil response[:result][:serverInfo][:title]
end

test "server uses default version when not configured" do
server = Server.new(name: "test_server")
request = {
Expand Down