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
6 changes: 3 additions & 3 deletions lib/mcp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
81 changes: 81 additions & 0 deletions test/mcp/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down