Skip to content

Commit 6b49222

Browse files
authored
Merge pull request #22 from koic/fix_incorrect_capabilities_handling_for_completion_complete
Fix incorrect capabilities handling for `completion/complete`
2 parents 1ba438f + d3dcde2 commit 6b49222

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

lib/model_context_protocol/methods.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def initialize(method, capability)
3636

3737
def ensure_capability!(method, capabilities)
3838
case method
39-
when PROMPTS_GET, PROMPTS_LIST, COMPLETION_COMPLETE
39+
when PROMPTS_GET, PROMPTS_LIST
4040
unless capabilities[:prompts]
4141
raise MissingRequiredCapabilityError.new(method, :prompts)
4242
end
@@ -56,6 +56,10 @@ def ensure_capability!(method, capabilities)
5656
unless capabilities[:sampling]
5757
raise MissingRequiredCapabilityError.new(method, :sampling)
5858
end
59+
when COMPLETION_COMPLETE
60+
unless capabilities[:completions]
61+
raise MissingRequiredCapabilityError.new(method, :completions)
62+
end
5963
when LOGGING_SET_LEVEL
6064
# Logging is unsupported by the Server
6165
unless capabilities[:logging]

lib/model_context_protocol/server.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def initialize(
6060
# No op handlers for currently unsupported methods
6161
Methods::RESOURCES_SUBSCRIBE => ->(_) {},
6262
Methods::RESOURCES_UNSUBSCRIBE => ->(_) {},
63+
Methods::COMPLETION_COMPLETE => ->(_) {},
6364
Methods::LOGGING_SET_LEVEL => ->(_) {},
6465
}
6566
end

test/model_context_protocol/methods_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ class MethodsTest < ActiveSupport::TestCase
1919
assert_equal "Server does not support sampling (required for sampling/createMessage)", error.message
2020
end
2121

22+
test "ensure_capability! for completion/complete raises an error if completions capability is not present" do
23+
error = assert_raises(Methods::MissingRequiredCapabilityError) do
24+
Methods.ensure_capability!(Methods::COMPLETION_COMPLETE, {})
25+
end
26+
assert_equal "Server does not support completions (required for completion/complete)", error.message
27+
end
28+
2229
test "ensure_capability! for logging/setLevel raises an error if logging capability is not present" do
2330
error = assert_raises(Methods::MissingRequiredCapabilityError) do
2431
Methods.ensure_capability!(Methods::LOGGING_SET_LEVEL, {})

0 commit comments

Comments
 (0)