MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / TestClientRootCapabilities

Function TestClientRootCapabilities

mcp/server_test.go:662–779  ·  view source on GitHub ↗

TestClientRootCapabilities verifies that the server correctly observes RootsV2 for various client capability configurations. This tests the fix for #607.

(t *testing.T)

Source from the content-addressed store, hash-verified

660// RootsV2 for various client capability configurations. This tests the fix
661// for #607.
662func TestClientRootCapabilities(t *testing.T) {
663 testCases := []struct {
664 name string
665 capabilities *string // JSON for the capabilities field; nil means omit the field
666 wantRootsV2 *RootCapabilities
667 }{
668 {
669 name: "capabilities field omitted",
670 capabilities: nil,
671 wantRootsV2: nil,
672 },
673 {
674 name: "empty capabilities",
675 capabilities: ptr(`{}`),
676 wantRootsV2: nil,
677 },
678 {
679 name: "capabilities with no roots",
680 capabilities: ptr(`{"sampling": {}}`),
681 wantRootsV2: nil,
682 },
683 {
684 name: "capabilities with empty roots",
685 capabilities: ptr(`{"roots": {}}`),
686 wantRootsV2: &RootCapabilities{ListChanged: false},
687 },
688 {
689 name: "capabilities with roots without listChanged",
690 capabilities: ptr(`{"roots": {"listChanged": false}}`),
691 wantRootsV2: &RootCapabilities{ListChanged: false},
692 },
693 {
694 name: "capabilities with roots with listChanged",
695 capabilities: ptr(`{"roots": {"listChanged": true}}`),
696 wantRootsV2: &RootCapabilities{ListChanged: true},
697 },
698 }
699
700 for _, tc := range testCases {
701 t.Run(tc.name, func(t *testing.T) {
702 ctx := context.Background()
703
704 // Create a minimal server.
705 impl := &Implementation{Name: "testServer", Version: "v1.0.0"}
706 s := NewServer(impl, nil)
707
708 // Connect the server.
709 cTransport, sTransport := NewInMemoryTransports()
710 ss, err := s.Connect(ctx, sTransport, nil)
711 if err != nil {
712 t.Fatal(err)
713 }
714
715 // Connect the client JSON-RPC connection (raw, no client).
716 cConn, err := cTransport.Connect(ctx)
717 if err != nil {
718 t.Fatal(err)
719 }

Callers

nothing calls this directly

Calls 13

ConnectMethod · 0.95
NewCallFunction · 0.92
Int64IDFunction · 0.92
NewServerFunction · 0.85
NewInMemoryTransportsFunction · 0.85
RunMethod · 0.80
InitializeParamsMethod · 0.80
ptrFunction · 0.70
ConnectMethod · 0.65
WriteMethod · 0.65
ReadMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…