{"record":{"id":"acb1e8ca7698d7a3","repo":"github/github-mcp-server","slug":"failed-to-get-repositories","errorCode":null,"errorMessage":"failed to get repositories","messagePattern":"failed to get repositories","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/github/repository_resource_completions.go","lineNumber":137,"sourceCode":"\t}\n\treturn values, nil\n}\n\nfunc completeRepo(ctx context.Context, client *github.Client, resolved map[string]string, argValue string) ([]string, error) {\n\tvar values []string\n\towner := resolved[\"owner\"]\n\tif owner == \"\" {\n\t\treturn values, errors.New(\"owner not specified\")\n\t}\n\n\tquery := fmt.Sprintf(\"org:%s\", owner)\n\n\tif argValue != \"\" {\n\t\tquery = fmt.Sprintf(\"%s %s\", query, argValue)\n\t}\n\trepos, _, err := client.Search.Repositories(ctx, query, &github.SearchOptions{ListOptions: github.ListOptions{PerPage: 100}})\n\tif err != nil || repos == nil {\n\t\treturn values, errors.New(\"failed to get repositories\")\n\t}\n\t// filter repos based on argValue\n\tfor _, repo := range repos.Repositories {\n\t\tname := repo.GetName()\n\t\tif argValue == \"\" || strings.HasPrefix(name, argValue) {\n\t\t\tvalues = append(values, name)\n\t\t}\n\t}\n\n\treturn values, nil\n}\n\nfunc completeBranch(ctx context.Context, client *github.Client, resolved map[string]string, argValue string) ([]string, error) {\n\tvar values []string\n\towner := resolved[\"owner\"]\n\trepo := resolved[\"repo\"]\n\tif owner == \"\" || repo == \"\" {\n\t\treturn values, errors.New(\"owner or repo not specified\")","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/github/github-mcp-server/blob/0ea1f775a7c73eff1bd2e25904d01136756bbfe2/pkg/github/repository_resource_completions.go#L119-L155","documentation":"Thrown by the 'repo' argument completion handler (completeRepo) for the repository resource template. It fires when client.Search.Repositories (GitHub Search API, query 'org:<owner> [argValue]') returns a non-nil error or a nil result, and it replaces the underlying cause with a fresh error, so the real reason (auth, rate limit, empty org) is discarded. This is a shell-completion path, not a tool call: it only affects MCP autocomplete of the repo URI segment.","triggerScenarios":"MCP client sends a completion request for argument 'repo' with 'owner' resolved, and the GitHub Search API call fails: 401 bad/missing token, 403 rate limit or search abuse detection, 422 for an owner that is a user (org: qualifier fails for personal accounts), or a network failure. Also triggers when the API succeeds but returns a nil result object.","commonSituations":"Using a fine-grained PAT without access to the target organization; hitting the low Search API rate limit (10-30 req/min) while autocompleting; owner resolved to a personal account instead of an org; GITHUB_TOKEN expired; proxy/firewall blocking api.github.com.","solutions":["Verify the token is valid and has read access to the owner's repositories (curl -H \"Authorization: Bearer $TOKEN\" https://api.github.com/orgs/<owner>/repos)","Check rate limits, especially Search API limits, and retry after Reset (curl -H ... /rate_limit)","Confirm the resolved owner is an organization the token can see; for a personal account this org: search returns no/failing results","Wait and retry if the response was a 403 secondary rate limit (search abuse mechanism)","Improve the code to wrap the underlying error (return nil, fmt.Errorf(\"failed to get repositories: %w\", err)) so the cause is visible"],"exampleFix":"// before\nrepos, _, err := client.Search.Repositories(ctx, query, &github.SearchOptions{ListOptions: github.ListOptions{PerPage: 100}})\nif err != nil || repos == nil {\n    return values, errors.New(\"failed to get repositories\")\n}\n\n// after\nrepos, _, err := client.Search.Repositories(ctx, query, &github.SearchOptions{ListOptions: github.ListOptions{PerPage: 100}})\nif err != nil {\n    return values, fmt.Errorf(\"failed to get repositories: %w\", err)\n}\nif repos == nil {\n    return values, errors.New(\"failed to get repositories: nil result\")\n}","handlingStrategy":"try-catch","validationCode":"// Verify owner is resolvable and token has org read access before completing\nif resolved[\"owner\"] == \"\" {\n    return // nothing to complete against\n}\n// Optional: cheap auth check before search\n_, _, err := client.Users.Get(ctx, \"\")\nif err != nil {\n    // token invalid; skip repo completion rather than search\n    return\n}","typeGuard":null,"tryCatchPattern":"// In the completion handler wrapper: degrade to empty suggestions instead of\n// failing the whole MCP completion request.\nvalues, err := resolver(ctx, client, resolved, argValue)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to get repositories\") {\n        return &mcp.CompleteResult{Completion: mcp.CompletionResultDetails{Values: []string{}}}, nil\n    }\n    return nil, err\n}","preventionTips":["Keep Search API usage sparse during completions; prefer listing /orgs/{owner}/repos for pagination without search rate limits","Ensure the token has read access to the target org before enabling repo completion","When embedding, wrap the underlying error with %w so failures are diagnosable"],"tags":["github-api","search","completions","mcp","rate-limit"],"backgroundTag":null,"analyzedSha":"0ea1f775a7c73eff1bd2e25904d01136756bbfe2","analyzedAt":"2026-08-15T18:10:19.804Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}