(t *testing.T, options ...clientOption)
| 144 | } |
| 145 | |
| 146 | func setupMCPClient(t *testing.T, options ...clientOption) *mcp.ClientSession { |
| 147 | // Check rate limit before setting up the client |
| 148 | waitForRateLimit(t) |
| 149 | |
| 150 | // Get token and ensure Docker image is built |
| 151 | token := getE2EToken(t) |
| 152 | |
| 153 | // Create and configure options with default to all toolsets |
| 154 | opts := &clientOpts{ |
| 155 | enabledToolsets: []string{"all"}, |
| 156 | } |
| 157 | |
| 158 | // Apply all options to configure the opts struct |
| 159 | for _, option := range options { |
| 160 | option(opts) |
| 161 | } |
| 162 | |
| 163 | ctx := context.Background() |
| 164 | |
| 165 | // By default, we run the tests including the Docker image, but with DEBUG |
| 166 | // enabled, we run the server in-process, allowing for easier debugging. |
| 167 | var session *mcp.ClientSession |
| 168 | if os.Getenv("GITHUB_MCP_SERVER_E2E_DEBUG") == "" { |
| 169 | ensureDockerImageBuilt(t) |
| 170 | |
| 171 | // Prepare Docker arguments |
| 172 | args := []string{ |
| 173 | "run", |
| 174 | "-i", |
| 175 | "--rm", |
| 176 | "-e", |
| 177 | "GITHUB_PERSONAL_ACCESS_TOKEN", // Personal access token is all required |
| 178 | } |
| 179 | |
| 180 | host := getE2EHost() |
| 181 | if host != "" { |
| 182 | args = append(args, "-e", "GITHUB_HOST") |
| 183 | } |
| 184 | |
| 185 | // Add toolsets environment variable to the Docker arguments |
| 186 | if len(opts.enabledToolsets) > 0 { |
| 187 | args = append(args, "-e", "GITHUB_TOOLSETS") |
| 188 | } |
| 189 | |
| 190 | // Add the image name |
| 191 | args = append(args, "github/e2e-github-mcp-server") |
| 192 | |
| 193 | // Construct the env vars for the MCP Client to execute docker with |
| 194 | // We need to include os.Environ() so docker can find its socket and config |
| 195 | dockerEnvVars := append(os.Environ(), |
| 196 | fmt.Sprintf("GITHUB_PERSONAL_ACCESS_TOKEN=%s", token), |
| 197 | fmt.Sprintf("GITHUB_TOOLSETS=%s", strings.Join(opts.enabledToolsets, ",")), |
| 198 | ) |
| 199 | |
| 200 | if host != "" { |
| 201 | dockerEnvVars = append(dockerEnvVars, fmt.Sprintf("GITHUB_HOST=%s", host)) |
| 202 | } |
| 203 |
no test coverage detected