Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions mcp/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,18 +346,23 @@ func notifySessions[S Session, P Params](sessions []S, method string, params P)
if sessions == nil {
return
}
// TODO: make this timeout configurable, or call handleNotify asynchronously.
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

// TODO: there's a potential spec violation here, when the feature list
// changes before the session (client or server) is initialized.
for _, s := range sessions {
req := newRequest(s, params)
if err := handleNotify(ctx, method, req); err != nil {
// TODO(jba): surface this error better
log.Printf("calling %s: %v", method, err)
}
// Call handleNotify asynchronously to avoid blocking
go func(r Request) {
// Use a reasonable timeout to prevent goroutine leaks
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

if err := handleNotify(ctx, method, r); err != nil {
// TODO(jba): surface this error better
log.Printf("notify session, calling %s fails, err: %v", method, err)
}
}(req)

}
}

Expand Down