{"record":{"id":"edd9eea9c8fc1299","repo":"github/github-mcp-server","slug":"failed-to-get-github-client-w-edd9ee","errorCode":null,"errorMessage":"failed to get GitHub client: %w","messagePattern":"failed to get GitHub client: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/github/secret_scanning.go","lineNumber":67,"sourceCode":"\t\t},\n\t\t[]scopes.Scope{scopes.SecurityEvents},\n\t\tfunc(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) {\n\t\t\towner, err := RequiredParam[string](args, \"owner\")\n\t\t\tif err != nil {\n\t\t\t\treturn utils.NewToolResultError(err.Error()), nil, nil\n\t\t\t}\n\t\t\trepo, err := RequiredParam[string](args, \"repo\")\n\t\t\tif err != nil {\n\t\t\t\treturn utils.NewToolResultError(err.Error()), nil, nil\n\t\t\t}\n\t\t\talertNumber, err := RequiredInt(args, \"alertNumber\")\n\t\t\tif err != nil {\n\t\t\t\treturn utils.NewToolResultError(err.Error()), nil, nil\n\t\t\t}\n\n\t\t\tclient, err := deps.GetClient(ctx)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, nil, fmt.Errorf(\"failed to get GitHub client: %w\", err)\n\t\t\t}\n\n\t\t\talert, resp, err := client.SecretScanning.GetAlert(ctx, owner, repo, int64(alertNumber))\n\t\t\tif err != nil {\n\t\t\t\treturn ghErrors.NewGitHubAPIErrorResponse(ctx,\n\t\t\t\t\tfmt.Sprintf(\"failed to get alert with number '%d'\", alertNumber),\n\t\t\t\t\tresp,\n\t\t\t\t\terr,\n\t\t\t\t), nil, nil\n\t\t\t}\n\t\t\tdefer func() { _ = resp.Body.Close() }()\n\n\t\t\tif resp.StatusCode != http.StatusOK {\n\t\t\t\tbody, err := io.ReadAll(resp.Body)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, nil, fmt.Errorf(\"failed to read response body: %w\", err)\n\t\t\t\t}\n\t\t\t\treturn ghErrors.NewGitHubAPIStatusErrorResponse(ctx, \"failed to get alert\", resp, body), nil, nil","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/github/github-mcp-server/blob/0ea1f775a7c73eff1bd2e25904d01136756bbfe2/pkg/github/secret_scanning.go#L49-L85","documentation":"The get_secret_scanning_alert tool failed to construct a go-github client before any API call. With BaseDeps (stdio) GetClient cannot fail; with RequestDeps (pkg/github/dependencies.go:308) it fails when the request context carries no token info ('no token info in context') or when the REST/upload URLs cannot be derived from the configured API hosts. Seeing this error means the request-scoped auth/host wiring is broken, not GitHub itself.","triggerScenarios":"Remote/hosted deployments where the MCP request has no token (missing Authorization header, unauthenticated transport); GITHUB_HOST / GITHUB_ENTERPRISE_URL values that make apiHosts.BaseRESTURL() or UploadURL() fail; client construction error from go-github.NewClient.","commonSituations":"Serving HTTP mode while the token was only provided for stdio; env var typos (GH_HOST vs GITHUB_HOST); OAuth flow not completed before tool calls; Docker image started without the token env var.","solutions":["Ensure a token reaches every request: set GITHUB_PERSONAL_ACCESS_TOKEN for stdio, or pass Authorization per request in remote mode","Check GITHUB_HOST / GITHUB_ENTERPRISE_URL / GITHUB_API_URL spellings and formats (scheme + host)","If embedding the server, use BaseDeps with a pre-built client when per-request tokens are not available"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// stdio: fail fast at startup, not per tool call\nif os.Getenv(\"GITHUB_PERSONAL_ACCESS_TOKEN\") == \"\" && os.Getenv(\"GITHUB_TOKEN\") == \"\" {\n    log.Fatal(\"no GitHub token configured; set GITHUB_PERSONAL_ACCESS_TOKEN\")\n}\n// remote: middleware guaranteeing token info before tools run\n_, ok := ghcontext.GetTokenInfo(ctx)\nif !ok {\n    http.Error(w, \"missing GitHub token\", http.StatusUnauthorized)\n    return\n}","typeGuard":"func isMissingTokenErr(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"no token info in context\")\n}","tryCatchPattern":"client, err := deps.GetClient(ctx)\nif err != nil {\n    if isMissingTokenErr(err) {\n        return nil, nil, utils.NewToolResultError(\"authentication required: provide a GitHub token for this request\")\n    }\n    return nil, nil, fmt.Errorf(\"failed to get GitHub client: %w\", err)\n}","preventionTips":["Run a cheap boot-time tool call (get_me) so auth/config errors surface at startup","Keep env var names consistent (GITHUB_PERSONAL_ACCESS_TOKEN, GITHUB_HOST) across deployment layers","In remote mode, reject unauthenticated requests in middleware before they reach tools"],"tags":["go","mcp","auth","configuration","secret-scanning"],"backgroundTag":null,"analyzedSha":"0ea1f775a7c73eff1bd2e25904d01136756bbfe2","analyzedAt":"2026-08-15T18:10:19.804Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}