@@ -344,7 +344,8 @@ func (s *MCPServer) DeleteSessionTools(sessionID string, names ...string) error
344344 return nil
345345}
346346
347- // SendLogMessageToClient sends a log message to the current client
347+ // SendLogMessageToClient sends a log message notification to the current client.
348+ // The client sesssion is expected to be an instance of server.SessionWithLogging to support setting and getting minimum log level
348349func (s * MCPServer ) SendLogMessageToClient (ctx context.Context , msg mcp.LoggingMessageNotification ) error {
349350 if s .capabilities .logging == nil || ! (* s .capabilities .logging ) {
350351 return fmt .Errorf ("server does not support emitting log message notifications" )
@@ -375,37 +376,10 @@ func(s *MCPServer) SendLogMessageToClient(ctx context.Context, msg mcp.LoggingMe
375376 return fmt .Errorf ("message level(%s) is lower than client level(%s)" , msg .Params .Level , clientLogLevel )
376377 }
377378
378- notification := mcp.JSONRPCNotification {
379- JSONRPC : mcp .JSONRPC_VERSION ,
380- Notification : mcp.Notification {
381- Method : msg .Method ,
382- Params : mcp.NotificationParams {
383- AdditionalFields : map [string ]any {
384- "level" : msg .Params .Level ,
385- "data" : msg .Params .Data ,
386- "logger" : msg .Params .Logger ,
387- },
388- },
389- },
390- }
391-
392- select {
393- case logSession .NotificationChannel () <- notification :
394- return nil
395- default :
396- // Channel is blocked, if there's an error hook, use it
397- if s .hooks != nil && len (s .hooks .OnError ) > 0 {
398- err := ErrNotificationChannelBlocked
399- // Copy hooks pointer to local variable to avoid race condition
400- hooks := s .hooks
401- go func (sessionID string , hooks * Hooks ) {
402- // Use the error hook to report the blocked channel
403- hooks .onError (ctx , nil , "notification" , map [string ]any {
404- "method" : msg .Method ,
405- "sessionID" : sessionID ,
406- }, fmt .Errorf ("failed to send a log message, notification channel blocked for session %s: %w" , sessionID , err ))
407- }(logSession .SessionID (), hooks )
408- }
409- return ErrNotificationChannelBlocked
379+ params := map [string ]any {
380+ "level" : msg .Params .Level ,
381+ "data" : msg .Params .Data ,
382+ "logger" : msg .Params .Logger ,
410383 }
384+ return s .SendNotificationToClient (ctx , msg .Method , params )
411385}
0 commit comments