@@ -61,49 +61,8 @@ func TestInstructions(t *testing.T) {
6161 }
6262}
6363
64- // newTestPairWithReadonly returns a ClientSession and Server with the specified readonly mode.
65- func newTestPairWithReadonly (t * testing.T , readonly bool ) (* mcp.ClientSession , * Server , error ) {
66- t .Helper ()
67- var (
68- errCh = make (chan error , 1 )
69- initCh = make (chan struct {})
70- serverTpt , clientTpt = mcp .NewInMemoryTransports ()
71- )
72-
73- // Create a test server with in-memory transport and readonly flag set
74- server := New (WithTransport (serverTpt ), WithReadonly (readonly ))
75- server .OnInit = func (ctx context.Context ) {
76- close (initCh )
77- }
78-
79- // Start the Server (readonly already set via WithReadonly option)
80- go func () {
81- errCh <- server .Start (t .Context (), ! readonly )
82- }()
83-
84- // Connect a client to trigger initialization
85- client := mcp .NewClient (& mcp.Implementation {
86- Name : "test-client" ,
87- Version : "1.0.0" ,
88- }, nil )
89- session , err := client .Connect (t .Context (), clientTpt , nil )
90- if err != nil {
91- return nil , nil , fmt .Errorf ("client connection failed: %v" , err )
92- }
93-
94- // Wait for init
95- select {
96- case err = <- errCh :
97- return nil , nil , fmt .Errorf ("server exited prematurely %v" , err )
98- case <- t .Context ().Done ():
99- return nil , nil , fmt .Errorf ("timeout waiting for server initialization" )
100- case <- initCh : // Successful start; continue.
101- }
102- return session , server , nil
103- }
104-
105- // newTestPair returns a ClientSession and Server connected over an in-memory transport.
106- func newTestPair (t * testing.T , options ... Option ) (session * mcp.ClientSession , server * Server , err error ) {
64+ // newTestPairCore is the core logic for creating a ClientSession and Server connected over an in-memory transport.
65+ func newTestPairCore (t * testing.T , readonly bool , options ... Option ) (session * mcp.ClientSession , server * Server , err error ) {
10766 t .Helper ()
10867 var (
10968 errCh = make (chan error , 1 )
@@ -125,7 +84,7 @@ func newTestPair(t *testing.T, options ...Option) (session *mcp.ClientSession, s
12584
12685 // Start the Server
12786 go func () {
128- errCh <- server .Start (t .Context (), false )
87+ errCh <- server .Start (t .Context (), ! readonly )
12988 }()
13089
13190 // Connect a client to trigger initialization
@@ -149,3 +108,13 @@ func newTestPair(t *testing.T, options ...Option) (session *mcp.ClientSession, s
149108 }
150109 return
151110}
111+
112+ // newTestPairWithReadonly returns a ClientSession and Server with the specified readonly mode.
113+ func newTestPairWithReadonly (t * testing.T , readonly bool ) (* mcp.ClientSession , * Server , error ) {
114+ return newTestPairCore (t , readonly , WithReadonly (readonly ))
115+ }
116+
117+ // newTestPair returns a ClientSession and Server connected over an in-memory transport.
118+ func newTestPair (t * testing.T , options ... Option ) (session * mcp.ClientSession , server * Server , err error ) {
119+ return newTestPairCore (t , false , options ... )
120+ }
0 commit comments