diff --git a/lib/mcp/server.rb b/lib/mcp/server.rb index 80cacd6..30c569d 100644 --- a/lib/mcp/server.rb +++ b/lib/mcp/server.rb @@ -99,9 +99,9 @@ def initialize( Methods::LOGGING_SET_LEVEL => method(:configure_logging_level), # No op handlers for currently unsupported methods - Methods::RESOURCES_SUBSCRIBE => ->(_) {}, - Methods::RESOURCES_UNSUBSCRIBE => ->(_) {}, - Methods::COMPLETION_COMPLETE => ->(_) {}, + Methods::RESOURCES_SUBSCRIBE => ->(_) { {} }, + Methods::RESOURCES_UNSUBSCRIBE => ->(_) { {} }, + Methods::COMPLETION_COMPLETE => ->(_) { { completion: { values: [], hasMore: false } } }, Methods::ELICITATION_CREATE => ->(_) {}, } @transport = transport diff --git a/test/mcp/server_test.rb b/test/mcp/server_test.rb index d6a9b1b..cc25dc0 100644 --- a/test/mcp/server_test.rb +++ b/test/mcp/server_test.rb @@ -1540,6 +1540,87 @@ class Example < Tool assert_includes response[:result][:content][0][:text], "Invalid arguments" end + test "#handle completion/complete returns default completion result" do + server = Server.new( + name: "test_server", + capabilities: { completions: {} }, + ) + + server.handle({ jsonrpc: "2.0", method: "initialize", id: 1 }) + server.handle({ jsonrpc: "2.0", method: "notifications/initialized" }) + + response = server.handle({ + jsonrpc: "2.0", + id: 2, + method: "completion/complete", + params: { + ref: { type: "ref/prompt", name: "test" }, + argument: { name: "arg", value: "val" }, + }, + }) + + assert_equal( + { + jsonrpc: "2.0", + id: 2, + result: { completion: { values: [], hasMore: false } }, + }, + response, + ) + end + + test "#handle resources/subscribe returns empty result" do + server = Server.new( + name: "test_server", + capabilities: { resources: { subscribe: true } }, + ) + + server.handle({ jsonrpc: "2.0", method: "initialize", id: 1 }) + server.handle({ jsonrpc: "2.0", method: "notifications/initialized" }) + + response = server.handle({ + jsonrpc: "2.0", + id: 2, + method: "resources/subscribe", + params: { uri: "https://example.com/resource" }, + }) + + assert_equal( + { + jsonrpc: "2.0", + id: 2, + result: {}, + }, + response, + ) + end + + test "#handle resources/unsubscribe returns empty result" do + server = Server.new( + name: "test_server", + capabilities: { resources: { subscribe: true } }, + ) + + server.handle({ jsonrpc: "2.0", method: "initialize", id: 1 }) + server.handle({ jsonrpc: "2.0", method: "notifications/initialized" }) + + response = server.handle({ + jsonrpc: "2.0", + id: 2, + method: "resources/unsubscribe", + params: { uri: "https://example.com/resource" }, + }) + + assert_equal( + { + jsonrpc: "2.0", + id: 2, + result: {}, + }, + response, + ) + end + test "tools/call with no args" do server = Server.new(tools: [@tool_with_no_args])