@@ -67,14 +67,26 @@ def handle_request(request); end
6767 assert_nil notification [ :params ]
6868 end
6969
70+ test "#notify_logging_message sends notification through transport" do
71+ @server . logging_message_notification = MCP ::LoggingMessageNotification . new ( level : "error" )
72+ @server . notify_logging_message ( data : { error : "Connection Failed" } , log_level : "error" )
73+
74+ assert_equal 1 , @mock_transport . notifications . size
75+ notification = @mock_transport . notifications . first
76+ assert_equal Methods ::NOTIFICATIONS_MESSAGE , notification [ :method ]
77+ assert_equal notification [ :params ] , { data : { error : "Connection Failed" } , level : "error" }
78+ end
79+
7080 test "notification methods work without transport" do
7181 server_without_transport = Server . new ( name : "test_server" )
82+ server_without_transport . logging_message_notification = MCP ::LoggingMessageNotification . new ( level : "error" )
7283
7384 # Should not raise any errors
7485 assert_nothing_raised do
7586 server_without_transport . notify_tools_list_changed
7687 server_without_transport . notify_prompts_list_changed
7788 server_without_transport . notify_resources_list_changed
89+ server_without_transport . notify_logging_message ( data : { error : "Connection Failed" } , log_level : "error" )
7890 end
7991 end
8092
@@ -87,16 +99,18 @@ def send_notification(method, params = nil)
8799 end . new ( @server )
88100
89101 @server . transport = error_transport
102+ @server . logging_message_notification = MCP ::LoggingMessageNotification . new ( level : "error" )
90103
91104 # Mock the exception reporter
92105 expected_contexts = [
93106 { notification : "tools_list_changed" } ,
94107 { notification : "prompts_list_changed" } ,
95108 { notification : "resources_list_changed" } ,
109+ { notification : "logging_message_notification" } ,
96110 ]
97111
98112 call_count = 0
99- @server . configuration . exception_reporter . expects ( :call ) . times ( 3 ) . with do |exception , context |
113+ @server . configuration . exception_reporter . expects ( :call ) . times ( 4 ) . with do |exception , context |
100114 assert_kind_of StandardError , exception
101115 assert_equal "Transport error" , exception . message
102116 assert_includes expected_contexts , context
@@ -109,22 +123,26 @@ def send_notification(method, params = nil)
109123 @server . notify_tools_list_changed
110124 @server . notify_prompts_list_changed
111125 @server . notify_resources_list_changed
126+ @server . notify_logging_message ( data : { error : "Connection Failed" } , log_level : "error" )
112127 end
113128
114- assert_equal 3 , call_count
129+ assert_equal 4 , call_count
115130 end
116131
117132 test "multiple notification methods can be called in sequence" do
118133 @server . notify_tools_list_changed
119134 @server . notify_prompts_list_changed
120135 @server . notify_resources_list_changed
136+ @server . logging_message_notification = MCP ::LoggingMessageNotification . new ( level : "error" )
137+ @server . notify_logging_message ( data : { error : "Connection Failed" } , log_level : "error" )
121138
122- assert_equal 3 , @mock_transport . notifications . size
139+ assert_equal 4 , @mock_transport . notifications . size
123140
124141 notifications = @mock_transport . notifications
125142 assert_equal Methods ::NOTIFICATIONS_TOOLS_LIST_CHANGED , notifications [ 0 ] [ :method ]
126143 assert_equal Methods ::NOTIFICATIONS_PROMPTS_LIST_CHANGED , notifications [ 1 ] [ :method ]
127144 assert_equal Methods ::NOTIFICATIONS_RESOURCES_LIST_CHANGED , notifications [ 2 ] [ :method ]
145+ assert_equal Methods ::NOTIFICATIONS_MESSAGE , notifications [ 3 ] [ :method ]
128146 end
129147 end
130148end
0 commit comments