github/github-mcp-server · error
failed to get GitHub client: %w
Error message
failed to get GitHub client: %w
What it means
The get_label tool could not construct a GraphQL client via deps.GetGQLClient before querying the label. Underlying causes are 'no token info in context' (the request context carries no auth token) or 'failed to get GraphQL URL' (the configured API host could not be resolved). The wrapped error text identifies which.
Source
Thrown at pkg/github/labels.go:91
Repository struct {
Label struct {
ID githubv4.ID
Name githubv4.String
Color githubv4.String
Description githubv4.String
} `graphql:"label(name: $name)"`
} `graphql:"repository(owner: $owner, name: $repo)"`
}
vars := map[string]any{
"owner": githubv4.String(owner),
"repo": githubv4.String(repo),
"name": githubv4.String(name),
}
client, err := deps.GetGQLClient(ctx)
if err != nil {
return nil, nil, fmt.Errorf("failed to get GitHub client: %w", err)
}
if err := client.Query(ctx, &query, vars); err != nil {
return ghErrors.NewGitHubGraphQLErrorResponse(ctx, "Failed to find label", err), nil, nil
}
if query.Repository.Label.Name == "" {
return utils.NewToolResultError(fmt.Sprintf("label '%s' not found in %s/%s", name, owner, repo)), nil, nil
}
label := map[string]any{
"id": fmt.Sprintf("%v", query.Repository.Label.ID),
"name": string(query.Repository.Label.Name),
"color": string(query.Repository.Label.Color),
"description": string(query.Repository.Label.Description),
}
out, err := json.Marshal(label)View on GitHub (pinned to 0ea1f775a7)
Solutions
- Check the wrapped message: 'no token info in context' means supply a token (GITHUB_TOKEN env or Authorization header for remote mode)
- 'failed to get GraphQL URL' means fixing the host config — verify GITHUB_API_URL/GH_HOST points at a valid GitHub or GHES host
- Restart the server with a valid token and retry the get_label call
Example fix
# before docker run ghcr.io/github/github-mcp-server # after docker run -e GITHUB_TOKEN=ghp_xxx ghcr.io/github/github-mcp-server
Defensive patterns
Strategy: validation
Validate before calling
func preflightAuth() error {
if os.Getenv("GITHUB_TOKEN") == "" {
return fmt.Errorf("GITHUB_TOKEN not set; get_label will fail to build a client")
}
if host := os.Getenv("GITHUB_API_URL"); host != "" {
u, err := url.Parse(host)
if err != nil || u.Host == "" {
return fmt.Errorf("GITHUB_API_URL is not a valid host")
}
}
return nil
} Try / catch
if err != nil && strings.Contains(err.Error(), "failed to get GitHub client") {
// Auth/host config problem, not transient. Fix token or API host; do not retry unchanged.
} Prevention
- Set GITHUB_TOKEN (or forward Authorization headers in remote mode) before startup
- Health-check auth with a cheap call (get_label on a known repo) after deployment
When it happens
Trigger: Invoking get_label when the server has no GitHub token configured, the token was not propagated into the request context (per-request auth missing), or the GH_HOST/GITHUB_API_URL host configuration is invalid.
Common situations: Forgetting to set GITHUB_TOKEN (or --read-only-token) when starting the server; remote/streamable HTTP deployments where the Authorization header is absent; a misconfigured enterprise API host (GITHUB_API_URL) that cannot yield a GraphQL endpoint.
Related errors
- failed to get GitHub client: %w
- failed to get repo access cache: %w
- failed to get GitHub client: %w
- failed to get GitHub client: %w
- authentication required: set GITHUB_PERSONAL_ACCESS_TOKEN, c
AI-assisted analysis of github/github-mcp-server@0ea1f775a7 (2026-08-15).
Data as JSON: /api/errors/d9d04f0f2894ad33.
Report an issue: GitHub.