1//lint:file-ignore SA1019 roots are deprecated, and followed for the hosts that still share them23package mcp45import (6 "path/filepath"7 "strings"8 "testing"910 sdk "github.com/modelcontextprotocol/go-sdk/mcp"11)1213// TestClientRoots checks the client's roots win over the server's, and14// follow the client's changes.15func TestClientRoots(t *testing.T) {16 dir, outsideBook := folder(t)17 c := sdk.NewClient(&sdk.Implementation{Name: "test", Version: "1"}, nil)18 c.AddRoots(&sdk.Root{URI: "file://" + filepath.ToSlash(filepath.Dir(outsideBook))})19 // Servers ask for roots only of clients of protocols up to 2025-11-25.20 cs := connectClient(t, Options{Roots: rootsFor(t, dir)}, c, &sdk.ClientSessionOptions{ProtocolVersion: "2025-11-25"})21 if res := call(t, cs, "describe", map[string]any{"path": filepath.Join(dir, "book.012")}, nil); !strings.Contains(errorText(res), "outside") {22 t.Errorf("the server's root with the client's given: %q", errorText(res))23 }24 var d describeOut25 call(t, cs, "describe", map[string]any{"path": "other.012"}, &d)26 if d.Path != "other.012" {27 t.Errorf("the client's root: %+v", d)28 }29 c.RemoveRoots("file://" + filepath.ToSlash(filepath.Dir(outsideBook)))30 c.AddRoots(&sdk.Root{URI: "file://" + filepath.ToSlash(dir)})31 for range 100 {32 if res := call(t, cs, "describe", map[string]any{"path": "book.012"}, &d); !res.IsError {33 return34 }35 }36 t.Error("the client's new roots weren't followed")37}