feat: deprecated logger in client & add Logger in ClientOption (#738)

Fix #708

1. deprecated logger in client
2. add Logger in ClientOption
3. add unit test for Logger
This commit is contained in:
FanOne 2026-01-05 23:41:31 +08:00 • committed by GitHub
commit 61be548803
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,6 +7,7 @@ package mcp
import (
"context"
"fmt"
"log/slog"
"testing"
"github.com/google/go-cmp/cmp"
@ -165,6 +166,23 @@ func TestClientPaginateBasic(t *testing.T) {
}
}
func TestClientLogger(t *testing.T) {
// Case 1: No logger provided
c1 := NewClient(&Implementation{Name: "test", Version: "1.0"}, nil)
if c1.opts.Logger == nil {
t.Error("expected default logger, got nil")
}
// Case 2: Logger provided
logger := slog.Default()
c2 := NewClient(&Implementation{Name: "test", Version: "1.0"}, &ClientOptions{
Logger: logger,
})
if c2.opts.Logger != logger {
t.Error("expected provided logger, got different one")
}
}
func TestClientPaginateVariousPageSizes(t *testing.T) {
ctx := context.Background()
for i := 1; i < len(allItems)+1; i++ {