Skip to content
Open
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
10 changes: 3 additions & 7 deletions lib/mcp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ class Server
UNSUPPORTED_PROPERTIES_UNTIL_2025_06_18 = [:description, :icons].freeze
UNSUPPORTED_PROPERTIES_UNTIL_2025_03_26 = [:title, :websiteUrl].freeze

DEFAULT_COMPLETION_RESULT = { completion: { values: [], hasMore: false } }.freeze

# Servers return an array of completion values ranked by relevance, with maximum 100 items per response.
# https://modelcontextprotocol.io/specification/2025-11-25/server/utilities/completion#completion-results
MAX_COMPLETION_VALUES = 100
Expand Down Expand Up @@ -295,7 +293,7 @@ def initialize(
Methods::NOTIFICATIONS_INITIALIZED => ->(_) {},
Methods::NOTIFICATIONS_PROGRESS => ->(_) {},
Methods::NOTIFICATIONS_ROOTS_LIST_CHANGED => ->(_) {},
Methods::COMPLETION_COMPLETE => ->(_) { DEFAULT_COMPLETION_RESULT },
Methods::COMPLETION_COMPLETE => ->(_) {},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing reads DEFAULT_COMPLETION_RESULT after this change. Could it be removed in this pull request as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks. Removed it in 6dd455e, and noted the removal of the public constant under Breaking Changes in the description.

Methods::LOGGING_SET_LEVEL => method(:configure_logging_level),
}
# The protocol's own request methods, as opposed to the notifications above and to custom methods
Expand Down Expand Up @@ -2308,10 +2306,8 @@ def validate_completion_params!(params)
end

def normalize_completion_result(result)
return DEFAULT_COMPLETION_RESULT unless result.is_a?(Hash)

completion = result[:completion] || result["completion"]
return DEFAULT_COMPLETION_RESULT unless completion.is_a?(Hash)
completion = result[:completion] || result["completion"] if result.is_a?(Hash)
completion = {} unless completion.is_a?(Hash)

values = completion[:values] || completion["values"] || []
total = completion[:total] || completion["total"]
Expand Down
20 changes: 16 additions & 4 deletions test/mcp/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3645,15 +3645,17 @@ def read_resource_request(uri)
server.handle({ jsonrpc: "2.0", method: "initialize", id: 1, params: initialize_params })
server.handle({ jsonrpc: "2.0", method: "notifications/initialized" })

response = server.handle({
request = {
jsonrpc: "2.0",
id: 2,
method: "completion/complete",
params: {
ref: { type: "ref/prompt", name: "test" },
argument: { name: "arg", value: "val" },
},
})
}
response = server.handle(request)
next_response = server.handle(request.merge(id: 3))

assert_equal(
{
Expand All @@ -3663,6 +3665,10 @@ def read_resource_request(uri)
},
response,
)
completion = response.fetch(:result).fetch(:completion)
next_completion = next_response.fetch(:result).fetch(:completion)
refute_same(completion, next_completion)
refute_same(completion.fetch(:values), next_completion.fetch(:values))
end

test "#handle completion/complete with custom handler for ref/prompt" do
Expand Down Expand Up @@ -4023,15 +4029,17 @@ def read_resource_request(uri)
server.handle({ jsonrpc: "2.0", method: "initialize", id: 1, params: initialize_params })
server.handle({ jsonrpc: "2.0", method: "notifications/initialized" })

response = server.handle({
request = {
jsonrpc: "2.0",
id: 2,
method: "completion/complete",
params: {
ref: { type: "ref/prompt", name: "test" },
argument: { name: "arg", value: "" },
},
})
}
response = server.handle(request)
next_response = server.handle(request.merge(id: 3))

assert_equal(
{
Expand All @@ -4041,6 +4049,10 @@ def read_resource_request(uri)
},
response,
)
completion = response.fetch(:result).fetch(:completion)
next_completion = next_response.fetch(:result).fetch(:completion)
refute_same(completion, next_completion)
refute_same(completion.fetch(:values), next_completion.fetch(:values))
end

test "#handle completion/complete with string-keyed handler result" do
Expand Down