-
Notifications
You must be signed in to change notification settings - Fork 327
feat: deprecated logger in client & add Logger in ClientOption #738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,15 +18,17 @@ import ( | |
| "time" | ||
|
|
||
| "github.com/google/jsonschema-go/jsonschema" | ||
|
|
||
| "github.com/modelcontextprotocol/go-sdk/internal/jsonrpc2" | ||
| "github.com/modelcontextprotocol/go-sdk/jsonrpc" | ||
| ) | ||
|
|
||
| // A Client is an MCP client, which may be connected to an MCP server | ||
| // using the [Client.Connect] method. | ||
| type Client struct { | ||
| impl *Implementation | ||
| opts ClientOptions | ||
| impl *Implementation | ||
| opts ClientOptions | ||
| // Deprecated | ||
| logger *slog.Logger // TODO: file proposal to export this | ||
CocaineCong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| mu sync.Mutex | ||
| roots *featureSet[*Root] | ||
|
|
@@ -42,25 +44,34 @@ type Client struct { | |
| // The first argument must not be nil. | ||
| // | ||
| // If non-nil, the provided options configure the Client. | ||
| func NewClient(impl *Implementation, opts *ClientOptions) *Client { | ||
| func NewClient(impl *Implementation, options *ClientOptions) *Client { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why rename to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| if impl == nil { | ||
| panic("nil Implementation") | ||
| } | ||
| c := &Client{ | ||
| var opts ClientOptions | ||
| if options != nil { | ||
| opts = *options | ||
| } | ||
| options = nil // prevent reuse | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does this prevent reuse?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| if opts.Logger == nil { // ensure we have a logger | ||
| opts.Logger = ensureLogger(nil) | ||
| } | ||
|
|
||
| return &Client{ | ||
| impl: impl, | ||
| opts: opts, | ||
| logger: ensureLogger(nil), // ensure we have a logger | ||
| roots: newFeatureSet(func(r *Root) string { return r.URI }), | ||
| sendingMethodHandler_: defaultSendingMethodHandler, | ||
| receivingMethodHandler_: defaultReceivingMethodHandler[*ClientSession], | ||
| } | ||
| if opts != nil { | ||
| c.opts = *opts | ||
| } | ||
| return c | ||
| } | ||
|
|
||
| // ClientOptions configures the behavior of the client. | ||
| type ClientOptions struct { | ||
| // Logger may be set to a non-nil value to enable logging of client activity. | ||
| Logger *slog.Logger | ||
CocaineCong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // CreateMessageHandler handles incoming requests for sampling/createMessage. | ||
| // | ||
| // 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 | |
| } | ||
| } | ||
| c.mu.Unlock() | ||
| notifySessions(sessions, notification, params, c.logger) | ||
| notifySessions(sessions, notification, params, c.opts.Logger) | ||
| } | ||
|
|
||
| // shouldSendListChangedNotification checks if the client's capabilities allow | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.