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

Function changeAndNotify

mcp/client.go:434–446  ·  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 notifies a snapshot of the sessions.

(c *Client, notification string, params P, change func() bool)

Source from the content-addressed store, hash-verified

432// It calls change, which should do the work and report whether a change actually occurred.
433// If there was a change, it notifies a snapshot of the sessions.
434func changeAndNotify[P Params](c *Client, notification string, params P, change func() bool) {
435 var sessions []*ClientSession
436 // Lock for the change, but not for the notification.
437 c.mu.Lock()
438 if change() {
439 // Check if listChanged is enabled for this notification type.
440 if c.shouldSendListChangedNotification(notification) {
441 sessions = slices.Clone(c.sessions)
442 }
443 }
444 c.mu.Unlock()
445 notifySessions(sessions, notification, params, c.opts.Logger)
446}
447
448// shouldSendListChangedNotification checks if the client's capabilities allow
449// sending the given list-changed notification.

Callers 2

AddRootsMethod · 0.85
RemoveRootsMethod · 0.85

Calls 2

notifySessionsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…