Fix incorrect capabilities handling for completion/complete

This PR fixes incorrect capabilities handling for `completion/complete`.
As specified, the capability of `completion/complete` is `completions`, not `prompts`:
https://modelcontextprotocol.io/specification/2025-03-26/server/utilities/completion#capabilities

Note that in the Ruby SDK, `completion/complete`, like `logging/setLevel`, is not yet implemented.
Therefore, an empty implementation has been added to server.rb.
This commit is contained in:
Koichi ITO 2025-05-26 17:20:27 +09:00
commit d3dcde2460
3 changed files with 13 additions and 1 deletions

View file

@ -36,7 +36,7 @@ module ModelContextProtocol
def ensure_capability!(method, capabilities)
case method
when PROMPTS_GET, PROMPTS_LIST, COMPLETION_COMPLETE
when PROMPTS_GET, PROMPTS_LIST
unless capabilities[:prompts]
raise MissingRequiredCapabilityError.new(method, :prompts)
end
@ -56,6 +56,10 @@ module ModelContextProtocol
unless capabilities[:sampling]
raise MissingRequiredCapabilityError.new(method, :sampling)
end
when COMPLETION_COMPLETE
unless capabilities[:completions]
raise MissingRequiredCapabilityError.new(method, :completions)
end
when LOGGING_SET_LEVEL
# Logging is unsupported by the Server
unless capabilities[:logging]

View file

@ -60,6 +60,7 @@ module ModelContextProtocol
# No op handlers for currently unsupported methods
Methods::RESOURCES_SUBSCRIBE => ->(_) {},
Methods::RESOURCES_UNSUBSCRIBE => ->(_) {},
Methods::COMPLETION_COMPLETE => ->(_) {},
Methods::LOGGING_SET_LEVEL => ->(_) {},
}
end

View file

@ -19,6 +19,13 @@ module ModelContextProtocol
assert_equal "Server does not support sampling (required for sampling/createMessage)", error.message
end
test "ensure_capability! for completion/complete raises an error if completions capability is not present" do
error = assert_raises(Methods::MissingRequiredCapabilityError) do
Methods.ensure_capability!(Methods::COMPLETION_COMPLETE, {})
end
assert_equal "Server does not support completions (required for completion/complete)", error.message
end
test "ensure_capability! for logging/setLevel raises an error if logging capability is not present" do
error = assert_raises(Methods::MissingRequiredCapabilityError) do
Methods.ensure_capability!(Methods::LOGGING_SET_LEVEL, {})