Skip to content

Commit 4dc2a8e

Browse files
committed
Fix logging/setLevel to return empty hash per MCP specification
This PR fixes `logging/setLevel` to return empty hash per MCP specification. The MCP specification requires `logging/setLevel` to return an empty result on success, not nil or the `LoggingMessageNotification` object. Specification reference: https://modelcontextprotocol.io/specification/2025-11-25/server/utilities/logging Fixes #229.
1 parent 2b790d6 commit 4dc2a8e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/mcp/server.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ def configure_logging_level(request)
362362
end
363363

364364
@logging_message_notification = logging_message_notification
365+
366+
{}
365367
end
366368

367369
def list_tools(request)

test/mcp/server_test.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,24 @@ class Example < Tool
810810
assert_instrumentation_data({ method: "resources/templates/list" })
811811
end
812812

813+
test "#configure_logging_level returns empty hash on success" do
814+
response = @server.handle(
815+
{
816+
jsonrpc: "2.0",
817+
id: 1,
818+
method: "logging/setLevel",
819+
params: {
820+
level: "info",
821+
},
822+
},
823+
)
824+
825+
assert_equal "2.0", response[:jsonrpc]
826+
assert_equal 1, response[:id]
827+
assert_empty(response[:result])
828+
refute response.key?(:error)
829+
end
830+
813831
test "#configure_logging_level returns an error object when invalid log level is provided" do
814832
server = Server.new(
815833
tools: [TestTool],

0 commit comments

Comments
 (0)