mcp: fix stray log.Printf in notifySessions

I encountered these logs, and they were distracting and noisy. We
shouldn't log to stderr unless configured by the user. Thread through
the logger.

Also, use ensureLogger in the streamable client to simplify call sites.

Updates #708
Updates #684
This commit is contained in:
Rob Findley 2025-12-10 16:50:39 -05:00 • committed by Robert Findley
commit 6f6e196c27

View file

@ -10,6 +10,7 @@ import (
"errors"
"fmt"
"iter"
"log/slog"
"slices"
"strings"
"sync"
@ -26,6 +27,7 @@ import (
type Client struct {
impl *Implementation
opts ClientOptions
logger *slog.Logger // TODO: file proposal to export this
mu sync.Mutex
roots *featureSet[*Root]
sessions []*ClientSession
@ -46,6 +48,7 @@ func NewClient(impl *Implementation, opts *ClientOptions) *Client {
}
c := &Client{
impl: impl,
logger: ensureLogger(nil), // ensure we have a logger
roots: newFeatureSet(func(r *Root) string { return r.URI }),
sendingMethodHandler_: defaultSendingMethodHandler,
receivingMethodHandler_: defaultReceivingMethodHandler[*ClientSession],
@ -341,7 +344,7 @@ func changeAndNotify[P Params](c *Client, notification string, params P, change
sessions = slices.Clone(c.sessions)
}
c.mu.Unlock()
notifySessions(sessions, notification, params)
notifySessions(sessions, notification, params, c.logger)
}
func (c *Client) listRoots(_ context.Context, req *ListRootsRequest) (*ListRootsResult, error) {