Add logging support
A server can send structured logging messages to the client. https://modelcontextprotocol.io/specification/2025-06-18/server/utilities/logging#logging Logging was specified in the 2024-11-05 specification, but since it was not supported in ruby-sdk, I implemented it. https://modelcontextprotocol.io/specification/2024-11-05/server/utilities/logging I also made it possible to output a simple notification message in the examples.
This commit is contained in:
parent
830913be5a
commit
afa2fb4077
1 changed files with 434 additions and 7 deletions
47
test/mcp/logging_message_notification_test.rb
Normal file
47
test/mcp/logging_message_notification_test.rb
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "test_helper"
|
||||
|
||||
module MCP
|
||||
class LoggingMessageNotificationTest < ActiveSupport::TestCase
|
||||
test "valid_level? returns true for valid levels" do
|
||||
LoggingMessageNotification::LOG_LEVEL_SEVERITY.keys.each do |level|
|
||||
logging_message_notification = LoggingMessageNotification.new(level: level)
|
||||
assert logging_message_notification.valid_level?, "#{level} should be valid"
|
||||
end
|
||||
end
|
||||
|
||||
test "valid_level? returns false for invalid levels" do
|
||||
invalid_levels = ["invalid", 1, "", nil, :fatal]
|
||||
invalid_levels.each do |level|
|
||||
logging_message_notification = LoggingMessageNotification.new(level: level)
|
||||
refute logging_message_notification.valid_level?, "#{level} should be invalid"
|
||||
end
|
||||
end
|
||||
|
||||
test "should_notify? returns true when notification level is higher priority than threshold level or equals to it" do
|
||||
logging_message_notification = LoggingMessageNotification.new(level: "warning")
|
||||
assert logging_message_notification.should_notify?("warning")
|
||||
assert logging_message_notification.should_notify?("error")
|
||||
assert logging_message_notification.should_notify?("critical")
|
||||
assert logging_message_notification.should_notify?("alert")
|
||||
assert logging_message_notification.should_notify?("emergency")
|
||||
end
|
||||
|
||||
test "should_notify? returns false when notification level is lower priority than threshold level" do
|
||||
logging_message_notification = LoggingMessageNotification.new(level: "warning")
|
||||
refute logging_message_notification.should_notify?("notice")
|
||||
refute logging_message_notification.should_notify?("info")
|
||||
refute logging_message_notification.should_notify?("debug")
|
||||
end
|
||||
|
||||
test "should_notify? returns false for invalid log levels" do
|
||||
logging_message_notification = LoggingMessageNotification.new(level: "warning")
|
||||
refute logging_message_notification.should_notify?("invalid")
|
||||
refute logging_message_notification.should_notify?(1)
|
||||
refute logging_message_notification.should_notify?("")
|
||||
refute logging_message_notification.should_notify?(nil)
|
||||
refute logging_message_notification.should_notify?(:fatal)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue