github/github-mcp-server · critical
no token info in context
Error message
no token info in context
What it means
RequestDeps.GetClient could not find TokenInfo in the request context: ghcontext.GetTokenInfo(ctx) returned false because no auth middleware attached a token via ghcontext.WithTokenInfo before the tool handler ran. This is the root error that surfaces as 'failed to get GitHub client: ...' for every REST tool — the server is dispatching authenticated requests without credentials. It is a wiring/configuration failure, not a GitHub API response.
Source
Thrown at pkg/github/dependencies.go:312
) *RequestDeps {
return &RequestDeps{
apiHosts: apiHosts,
version: version,
lockdownMode: lockdownMode,
RepoAccessOpts: repoAccessOpts,
T: t,
ContentWindowSize: contentWindowSize,
featureChecker: featureChecker,
obsv: obsv,
}
}
// GetClient implements ToolDependencies.
func (d *RequestDeps) GetClient(ctx context.Context) (*gogithub.Client, error) {
// extract the token from the context
tokenInfo, ok := ghcontext.GetTokenInfo(ctx)
if !ok {
return nil, fmt.Errorf("no token info in context")
}
token := tokenInfo.Token
baseRestURL, err := d.apiHosts.BaseRESTURL(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get base REST URL: %w", err)
}
uploadURL, err := d.apiHosts.UploadURL(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get upload URL: %w", err)
}
// Construct REST client
restClient, err := gogithub.NewClient(
gogithub.WithAuthToken(token),
gogithub.WithUserAgent(fmt.Sprintf("github-mcp-server/%s", d.version)),
gogithub.WithEnterpriseURLs(baseRestURL.String(), uploadURL.String()),
)View on GitHub (pinned to 0ea1f775a7)
Solutions
- Configure a valid token source before starting the server: export GITHUB_PERSONAL_ACCESS_TOKEN=ghp_... (or App/OAuth credentials) and restart
- Verify startup logs show successful authentication (no token-exchange errors)
- Embedders: wrap the dispatch context with ghcontext.WithTokenInfo(ctx, &ghcontext.TokenInfo{Token: t, TokenType: tt}) before any tool call
- Test with get_me — if it fails the same way, fix server-level auth before debugging individual tools
Example fix
// before — handler receives a context with no token info
result, _, err := toolHandler(ctx, req) // -> "no token info in context"
// after — attach token info before dispatch
ctx = ghcontext.WithTokenInfo(ctx, &ghcontext.TokenInfo{
Token: os.Getenv("GITHUB_PERSONAL_ACCESS_TOKEN"),
TokenType: utils.PAT,
})
result, _, err := toolHandler(ctx, req) Defensive patterns
Strategy: validation
Validate before calling
// fail fast at startup when no credential source is configured
func validateAuthConfig() error {
hasPAT := os.Getenv("GITHUB_PERSONAL_ACCESS_TOKEN") != ""
hasApp := os.Getenv("GITHUB_APP_ID") != "" && os.Getenv("GITHUB_APP_PRIVATE_KEY") != ""
if !hasPAT && !hasApp {
return errors.New("no GitHub credentials configured: set GITHUB_PERSONAL_ACCESS_TOKEN or GitHub App env vars")
}
return nil
} Type guard
func hasTokenInfo(ctx context.Context) bool {
_, ok := ghcontext.GetTokenInfo(ctx)
return ok
} Try / catch
client, err := deps.GetClient(ctx)
if err != nil {
if strings.Contains(err.Error(), "no token info in context") {
// stop dispatching: every tool will fail identically until auth wiring is fixed
}
return nil, fmt.Errorf("failed to get GitHub client: %w", err)
} Prevention
- Validate credential environment variables at server startup and exit non-zero when absent
- Never call tool handlers with a bare context — always the context produced by the auth transport
- Add a health check tool (get_me) to smoke-test auth after deployment
- After upgrading github-mcp-server, re-verify auth middleware ordering in embedded setups
When it happens
Trigger: Any REST tool invocation when the server was started with no token source (no GITHUB_PERSONAL_ACCESS_TOKEN / GitHub App / OAuth credentials), when GitHub App credential exchange silently failed but requests are still dispatched, or when embedding the server and calling handlers with a context that bypassed the auth transport.
Common situations: Missing or empty token environment variable, expired GitHub App installation, OAuth token exchange failure, custom deployments invoking handlers with context.Background(), version upgrades changing middleware ordering.
Related errors
- GitHub App authentication and OAuth login (--oauth-client-id
- GitHub App installation ID is required (GITHUB_APP_INSTALLAT
- GitHub App REST base URL is required
- owner is required
- owner not specified
AI-assisted analysis of github/github-mcp-server@0ea1f775a7 (2026-08-15).
Data as JSON: /api/errors/69637d5d6b016abd.
Report an issue: GitHub.