Skip to content

Commit 5a1bb65

Browse files
authored
chore(mcp): remove unused error declaration and refactor test case (#3186)
1 parent 640a72a commit 5a1bb65

File tree

2 files changed

+13
-47
lines changed

2 files changed

+13
-47
lines changed

pkg/mcp/mcp.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package mcp
22

33
import (
44
"context"
5-
"errors"
65
"os/exec"
76
"strings"
87

@@ -161,5 +160,3 @@ func (e defaultExecutor) Execute(ctx context.Context, subcommand string, args ..
161160
// cmd.Dir not set - inherits process working directory which is the current working directory
162161
return cmd.CombinedOutput()
163162
}
164-
165-
var ErrWriteDisabled = errors.New("server is not write enabled")

pkg/mcp/mcp_test.go

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)