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

Function notifySessions

mcp/shared.go:399–417  ·  view source on GitHub ↗

notifySessions calls Notify on all the sessions. Should be called on a copy of the peer sessions. The logger must be non-nil.

(sessions []S, method string, params P, logger *slog.Logger)

Source from the content-addressed store, hash-verified

397// Should be called on a copy of the peer sessions.
398// The logger must be non-nil.
399func notifySessions[S Session, P Params](sessions []S, method string, params P, logger *slog.Logger) {
400 if sessions == nil {
401 return
402 }
403 // Notify with the background context, so the messages are sent on the
404 // standalone stream.
405 // TODO: make this timeout configurable, or call handleNotify asynchronously.
406 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
407 defer cancel()
408
409 // TODO: there's a potential spec violation here, when the feature list
410 // changes before the session (client or server) is initialized.
411 for _, s := range sessions {
412 req := newRequest(s, params)
413 if err := handleNotify(ctx, method, req); err != nil {
414 logger.Warn(fmt.Sprintf("calling %s: %v", method, err))
415 }
416 }
417}
418
419func newRequest[S Session, P Params](s S, p P) Request {
420 switch s := any(s).(type) {

Callers 3

notifySessionsMethod · 0.85
ResourceUpdatedMethod · 0.85
changeAndNotifyFunction · 0.85

Calls 2

newRequestFunction · 0.85
handleNotifyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…