@@ -58,8 +58,6 @@ func ensureDockerImageBuilt(t *testing.T) {
58
58
type ClientOpts struct {
59
59
// Environment variables to set before starting the client
60
60
EnvVars map [string ]string
61
- // Whether to initialize the client after creation
62
- ShouldInitialize bool
63
61
}
64
62
65
63
// ClientOption defines a function type for configuring ClientOpts
@@ -72,13 +70,6 @@ func WithEnvVars(envVars map[string]string) ClientOption {
72
70
}
73
71
}
74
72
75
- // WithInitialize returns an option that configures the client to be initialized
76
- func WithInitialize () ClientOption {
77
- return func (opts * ClientOpts ) {
78
- opts .ShouldInitialize = true
79
- }
80
- }
81
-
82
73
// setupMCPClient sets up the test environment and returns an initialized MCP client
83
74
// It handles token retrieval, Docker image building, and applying the provided options
84
75
func setupMCPClient (t * testing.T , options ... ClientOption ) * mcpClient.Client {
@@ -125,60 +116,55 @@ func setupMCPClient(t *testing.T, options ...ClientOption) *mcpClient.Client {
125
116
client , err := mcpClient .NewStdioMCPClient (args [0 ], []string {}, args [1 :]... )
126
117
require .NoError (t , err , "expected to create client successfully" )
127
118
128
- // Initialize the client if configured to do so
129
- if opts .ShouldInitialize {
130
- ctx , cancel := context .WithTimeout (context .Background (), 5 * time .Second )
131
- defer cancel ()
132
-
133
- request := mcp.InitializeRequest {}
134
- request .Params .ProtocolVersion = "2025-03-26"
135
- request .Params .ClientInfo = mcp.Implementation {
136
- Name : "e2e-test-client" ,
137
- Version : "0.0.1" ,
138
- }
119
+ // Initialize the client
120
+ ctx , cancel := context .WithTimeout (context .Background (), 5 * time .Second )
121
+ defer cancel ()
139
122
140
- result , err := client .Initialize (ctx , request )
141
- require .NoError (t , err , "failed to initialize client" )
142
- require .Equal (t , "github-mcp-server" , result .ServerInfo .Name , "unexpected server name" )
123
+ request := mcp.InitializeRequest {}
124
+ request .Params .ProtocolVersion = "2025-03-26"
125
+ request .Params .ClientInfo = mcp.Implementation {
126
+ Name : "e2e-test-client" ,
127
+ Version : "0.0.1" ,
143
128
}
144
129
130
+ result , err := client .Initialize (ctx , request )
131
+ require .NoError (t , err , "failed to initialize client" )
132
+ require .Equal (t , "github-mcp-server" , result .ServerInfo .Name , "unexpected server name" )
133
+
145
134
return client
146
135
}
147
136
148
- func TestE2E (t * testing.T ) {
149
- // Setup the MCP client with initialization
150
- client := setupMCPClient (t , WithInitialize ())
137
+ func TestGetMe (t * testing.T ) {
138
+ mcpClient := setupMCPClient (t )
151
139
152
- t .Run ("CallTool get_me" , func (t * testing.T ) {
153
- ctx , cancel := context .WithTimeout (context .Background (), 5 * time .Second )
154
- defer cancel ()
140
+ ctx , cancel := context .WithTimeout (context .Background (), 5 * time .Second )
141
+ defer cancel ()
155
142
156
- // When we call the "get_me" tool
157
- request := mcp.CallToolRequest {}
158
- request .Params .Name = "get_me"
143
+ // When we call the "get_me" tool
144
+ request := mcp.CallToolRequest {}
145
+ request .Params .Name = "get_me"
159
146
160
- response , err := client .CallTool (ctx , request )
161
- require .NoError (t , err , "expected to call 'get_me' tool successfully" )
147
+ response , err := mcpClient .CallTool (ctx , request )
148
+ require .NoError (t , err , "expected to call 'get_me' tool successfully" )
162
149
163
- require .False (t , response .IsError , "expected result not to be an error" )
164
- require .Len (t , response .Content , 1 , "expected content to have one item" )
150
+ require .False (t , response .IsError , "expected result not to be an error" )
151
+ require .Len (t , response .Content , 1 , "expected content to have one item" )
165
152
166
- textContent , ok := response .Content [0 ].(mcp.TextContent )
167
- require .True (t , ok , "expected content to be of type TextContent" )
153
+ textContent , ok := response .Content [0 ].(mcp.TextContent )
154
+ require .True (t , ok , "expected content to be of type TextContent" )
168
155
169
- var trimmedContent struct {
170
- Login string `json:"login"`
171
- }
172
- err = json .Unmarshal ([]byte (textContent .Text ), & trimmedContent )
173
- require .NoError (t , err , "expected to unmarshal text content successfully" )
174
-
175
- // Then the login in the response should match the login obtained via the same
176
- // token using the GitHub API.
177
- client := github .NewClient (nil ).WithAuthToken (getE2EToken (t ))
178
- user , _ , err := client .Users .Get (context .Background (), "" )
179
- require .NoError (t , err , "expected to get user successfully" )
180
- require .Equal (t , trimmedContent .Login , * user .Login , "expected login to match" )
181
- })
156
+ var trimmedContent struct {
157
+ Login string `json:"login"`
158
+ }
159
+ err = json .Unmarshal ([]byte (textContent .Text ), & trimmedContent )
160
+ require .NoError (t , err , "expected to unmarshal text content successfully" )
161
+
162
+ // Then the login in the response should match the login obtained via the same
163
+ // token using the GitHub API.
164
+ ghClient := github .NewClient (nil ).WithAuthToken (getE2EToken (t ))
165
+ user , _ , err := ghClient .Users .Get (context .Background (), "" )
166
+ require .NoError (t , err , "expected to get user successfully" )
167
+ require .Equal (t , trimmedContent .Login , * user .Login , "expected login to match" )
182
168
183
- require .NoError (t , client .Close (), "expected to close client successfully" )
169
+ require .NoError (t , mcpClient .Close (), "expected to close client successfully" )
184
170
}
0 commit comments