{"record":{"id":"69637d5d6b016abd","repo":"github/github-mcp-server","slug":"no-token-info-in-context","errorCode":null,"errorMessage":"no token info in context","messagePattern":"no token info in context","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/github/dependencies.go","lineNumber":312,"sourceCode":") *RequestDeps {\n\treturn &RequestDeps{\n\t\tapiHosts:          apiHosts,\n\t\tversion:           version,\n\t\tlockdownMode:      lockdownMode,\n\t\tRepoAccessOpts:    repoAccessOpts,\n\t\tT:                 t,\n\t\tContentWindowSize: contentWindowSize,\n\t\tfeatureChecker:    featureChecker,\n\t\tobsv:              obsv,\n\t}\n}\n\n// GetClient implements ToolDependencies.\nfunc (d *RequestDeps) GetClient(ctx context.Context) (*gogithub.Client, error) {\n\t// extract the token from the context\n\ttokenInfo, ok := ghcontext.GetTokenInfo(ctx)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"no token info in context\")\n\t}\n\ttoken := tokenInfo.Token\n\n\tbaseRestURL, err := d.apiHosts.BaseRESTURL(ctx)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get base REST URL: %w\", err)\n\t}\n\tuploadURL, err := d.apiHosts.UploadURL(ctx)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get upload URL: %w\", err)\n\t}\n\n\t// Construct REST client\n\trestClient, err := gogithub.NewClient(\n\t\tgogithub.WithAuthToken(token),\n\t\tgogithub.WithUserAgent(fmt.Sprintf(\"github-mcp-server/%s\", d.version)),\n\t\tgogithub.WithEnterpriseURLs(baseRestURL.String(), uploadURL.String()),\n\t)","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/github/github-mcp-server/blob/0ea1f775a7c73eff1bd2e25904d01136756bbfe2/pkg/github/dependencies.go#L294-L330","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before — handler receives a context with no token info\nresult, _, err := toolHandler(ctx, req)  // -> \"no token info in context\"\n\n// after — attach token info before dispatch\nctx = ghcontext.WithTokenInfo(ctx, &ghcontext.TokenInfo{\n\tToken:     os.Getenv(\"GITHUB_PERSONAL_ACCESS_TOKEN\"),\n\tTokenType: utils.PAT,\n})\nresult, _, err := toolHandler(ctx, req)","handlingStrategy":"validation","validationCode":"// fail fast at startup when no credential source is configured\nfunc validateAuthConfig() error {\n\thasPAT := os.Getenv(\"GITHUB_PERSONAL_ACCESS_TOKEN\") != \"\"\n\thasApp := os.Getenv(\"GITHUB_APP_ID\") != \"\" && os.Getenv(\"GITHUB_APP_PRIVATE_KEY\") != \"\"\n\tif !hasPAT && !hasApp {\n\t\treturn errors.New(\"no GitHub credentials configured: set GITHUB_PERSONAL_ACCESS_TOKEN or GitHub App env vars\")\n\t}\n\treturn nil\n}","typeGuard":"func hasTokenInfo(ctx context.Context) bool {\n\t_, ok := ghcontext.GetTokenInfo(ctx)\n\treturn ok\n}","tryCatchPattern":"client, err := deps.GetClient(ctx)\nif err != nil {\n\tif strings.Contains(err.Error(), \"no token info in context\") {\n\t\t// stop dispatching: every tool will fail identically until auth wiring is fixed\n\t}\n\treturn nil, fmt.Errorf(\"failed to get GitHub client: %w\", err)\n}","preventionTips":["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"],"tags":["go","authentication","context","configuration","server-setup"],"backgroundTag":null,"analyzedSha":"0ea1f775a7c73eff1bd2e25904d01136756bbfe2","analyzedAt":"2026-08-15T18:10:19.804Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}