{"record":{"id":"9dd8312e3b710119","repo":"github/github-mcp-server","slug":"failed-to-get-github-client-w-9dd831","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/repositories.go","lineNumber":96,"sourceCode":"\t\t\t\treturn utils.NewToolResultError(err.Error()), nil, nil\n\t\t\t}\n\t\t\tdetail, err := parseCommitDetail(detailRaw)\n\t\t\tif err != nil {\n\t\t\t\treturn utils.NewToolResultError(err.Error()), nil, nil\n\t\t\t}\n\t\t\tpagination, err := OptionalPaginationParams(args)\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\topts := &github.ListOptions{\n\t\t\t\tPage:    pagination.Page,\n\t\t\t\tPerPage: pagination.PerPage,\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\t\t\tcommit, resp, err := client.Repositories.GetCommit(ctx, owner, repo, sha, opts)\n\t\t\tif err != nil {\n\t\t\t\treturn ghErrors.NewGitHubAPIErrorResponse(ctx,\n\t\t\t\t\tfmt.Sprintf(\"failed to get commit: %s\", sha),\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 != 200 {\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 commit\", resp, body), nil, nil\n\t\t\t}","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/github/github-mcp-server/blob/0ea1f775a7c73eff1bd2e25904d01136756bbfe2/pkg/github/repositories.go#L78-L114","documentation":"The get_commit tool handler calls deps.GetClient(ctx) before fetching the commit. RequestDeps.GetClient extracts the token from the request context, resolves REST/upload URLs from the configured API hosts, and constructs a go-github client; failures at any of those steps ('no token info in context', 'failed to get base REST URL', 'failed to get upload URL', 'failed to create REST client') are wrapped as 'failed to get GitHub client'.","triggerScenarios":"No token in the request context (missing GITHUB_PERSONAL_ACCESS_TOKEN for stdio, missing Authorization header for HTTP transports); malformed GITHUB_API_URL/GITHUB_UPLOAD_URL (no scheme, no host, embedded path); go-github WithEnterpriseURLs rejecting non-http(s) or path-bearing URLs.","commonSituations":"Fresh installs that set the env var name wrong (GITHUB_TOKEN vs GITHUB_PERSONAL_ACCESS_TOKEN); GHES base URLs copied with a trailing slash or /api/v3 path doubled; reverse proxies stripping Authorization; GHES loopback-host URL handling regressions (see the repo's own fix for preserving authority on loopback GHES hosts).","solutions":["Check the wrapped cause first — it names token vs URL vs client construction","Set GITHUB_PERSONAL_ACCESS_TOKEN (stdio) or pass the Authorization: Bearer header (HTTP) for every request","Validate GITHUB_API_URL and GITHUB_UPLOAD_URL as absolute https URLs with a bare host (the API version path is appended by the client)","For GHES, confirm the URLs match the documented API endpoints and contain no redundant /api/v3 suffix"],"exampleFix":"# before\nexport GITHUB_API_URL=\"github.mycompany.com/api/v3\"   # no scheme → URL parse fails\n\n# after\nexport GITHUB_API_URL=\"https://github.mycompany.com/api/v3\"\nexport GITHUB_UPLOAD_URL=\"https://uploads.mycompany.com/\"","handlingStrategy":"validation","validationCode":"func validateGitHubConfig() error {\n\tif os.Getenv(\"GITHUB_PERSONAL_ACCESS_TOKEN\") == \"\" && !headerAuthConfigured() {\n\t\treturn errors.New(\"no GitHub token: set GITHUB_PERSONAL_ACCESS_TOKEN or send an Authorization header\")\n\t}\n\tfor _, k := range []string{\"GITHUB_API_URL\", \"GITHUB_UPLOAD_URL\"} {\n\t\tif v := os.Getenv(k); v != \"\" {\n\t\t\tu, err := url.Parse(v)\n\t\t\tif err != nil || (u.Scheme != \"http\" && u.Scheme != \"https\") || u.Host == \"\" {\n\t\t\t\treturn fmt.Errorf(\"%s must be an absolute http(s) URL with host, got %q\", k, v)\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"client, err := deps.GetClient(ctx)\nif err != nil {\n\tswitch {\n\tcase strings.Contains(err.Error(), \"no token info in context\"):\n\t\treturn fixAuthPropagation() // env/header wiring\n\tcase strings.Contains(err.Error(), \"base REST URL\"), strings.Contains(err.Error(), \"upload URL\"):\n\t\treturn fixHostConfig() // GITHUB_*_URL values\n\tdefault:\n\t\treturn err\n\t}\n}","preventionTips":["Run a get_me call at session start to prove client construction and auth work","Add startup config validation for token and all GITHUB_*_URL values","For GHES, copy documented API base URLs exactly — no doubled /api/v3, no missing scheme"],"tags":["go","github-api","mcp","authentication","configuration","ghes"],"backgroundTag":null,"analyzedSha":"0ea1f775a7c73eff1bd2e25904d01136756bbfe2","analyzedAt":"2026-08-15T18:10:19.804Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}