@@ -18,15 +18,17 @@ import (
1818 "time"
1919
2020 "github.com/google/jsonschema-go/jsonschema"
21+
2122 "github.com/modelcontextprotocol/go-sdk/internal/jsonrpc2"
2223 "github.com/modelcontextprotocol/go-sdk/jsonrpc"
2324)
2425
2526// A Client is an MCP client, which may be connected to an MCP server
2627// using the [Client.Connect] method.
2728type Client struct {
28- impl * Implementation
29- opts ClientOptions
29+ impl * Implementation
30+ opts ClientOptions
31+ // Deprecated
3032 logger * slog.Logger // TODO: file proposal to export this
3133 mu sync.Mutex
3234 roots * featureSet [* Root ]
@@ -42,25 +44,34 @@ type Client struct {
4244// The first argument must not be nil.
4345//
4446// If non-nil, the provided options configure the Client.
45- func NewClient (impl * Implementation , opts * ClientOptions ) * Client {
47+ func NewClient (impl * Implementation , options * ClientOptions ) * Client {
4648 if impl == nil {
4749 panic ("nil Implementation" )
4850 }
49- c := & Client {
51+ var opts ClientOptions
52+ if options != nil {
53+ opts = * options
54+ }
55+ options = nil // prevent reuse
56+
57+ if opts .Logger == nil { // ensure we have a logger
58+ opts .Logger = ensureLogger (nil )
59+ }
60+
61+ return & Client {
5062 impl : impl ,
63+ opts : opts ,
5164 logger : ensureLogger (nil ), // ensure we have a logger
5265 roots : newFeatureSet (func (r * Root ) string { return r .URI }),
5366 sendingMethodHandler_ : defaultSendingMethodHandler ,
5467 receivingMethodHandler_ : defaultReceivingMethodHandler [* ClientSession ],
5568 }
56- if opts != nil {
57- c .opts = * opts
58- }
59- return c
6069}
6170
6271// ClientOptions configures the behavior of the client.
6372type ClientOptions struct {
73+ // Logger may be set to a non-nil value to enable logging of client activity.
74+ Logger * slog.Logger
6475 // CreateMessageHandler handles incoming requests for sampling/createMessage.
6576 //
6677 // Setting CreateMessageHandler to a non-nil value automatically causes the
@@ -407,7 +418,7 @@ func changeAndNotify[P Params](c *Client, notification string, params P, change
407418 }
408419 }
409420 c .mu .Unlock ()
410- notifySessions (sessions , notification , params , c .logger )
421+ notifySessions (sessions , notification , params , c .opts . Logger )
411422}
412423
413424// shouldSendListChangedNotification checks if the client's capabilities allow
0 commit comments