MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / changeAndNotify

Method changeAndNotify

mcp/server.go:630–649  ·  view source on GitHub ↗

changeAndNotify is called when a feature is added or removed. It calls change, which should do the work and report whether a change actually occurred. If there was a change, it sets a timer to send a notification. This debounces change notifications: a single notification is sent after multiple chan

(notification string, change func() bool)

Source from the content-addressed store, hash-verified

628// This debounces change notifications: a single notification is sent after
629// multiple changes occur in close proximity.
630func (s *Server) changeAndNotify(notification string, change func() bool) {
631 s.mu.Lock()
632 defer s.mu.Unlock()
633 if change() && s.shouldSendListChangedNotification(notification) {
634 if len(s.sessions) == 0 {
635 if t := s.pendingNotifications[notification]; t != nil {
636 t.Stop()
637 s.pendingNotifications[notification] = nil
638 }
639 return
640 }
641
642 // Reset the outstanding delayed call, if any.
643 if t := s.pendingNotifications[notification]; t == nil {
644 s.pendingNotifications[notification] = time.AfterFunc(notificationDelay, func() { s.notifySessions(notification) })
645 } else {
646 t.Reset(notificationDelay)
647 }
648 }
649}
650
651// notifySessions sends the notification n to all existing sessions.
652// It is called asynchronously by changeAndNotify.

Callers 8

AddPromptMethod · 0.95
RemovePromptsMethod · 0.95
AddToolMethod · 0.95
RemoveToolsMethod · 0.95
AddResourceMethod · 0.95
RemoveResourcesMethod · 0.95
AddResourceTemplateMethod · 0.95

Calls 2

notifySessionsMethod · 0.95

Tested by

no test coverage detected