github/github-mcp-server · warning

failed to get repositories

Error message

failed to get repositories

What it means

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.

Source

Thrown at pkg/github/repository_resource_completions.go:137

	}
	return values, nil
}

func completeRepo(ctx context.Context, client *github.Client, resolved map[string]string, argValue string) ([]string, error) {
	var values []string
	owner := resolved["owner"]
	if owner == "" {
		return values, errors.New("owner not specified")
	}

	query := fmt.Sprintf("org:%s", owner)

	if argValue != "" {
		query = fmt.Sprintf("%s %s", query, argValue)
	}
	repos, _, err := client.Search.Repositories(ctx, query, &github.SearchOptions{ListOptions: github.ListOptions{PerPage: 100}})
	if err != nil || repos == nil {
		return values, errors.New("failed to get repositories")
	}
	// filter repos based on argValue
	for _, repo := range repos.Repositories {
		name := repo.GetName()
		if argValue == "" || strings.HasPrefix(name, argValue) {
			values = append(values, name)
		}
	}

	return values, nil
}

func completeBranch(ctx context.Context, client *github.Client, resolved map[string]string, argValue string) ([]string, error) {
	var values []string
	owner := resolved["owner"]
	repo := resolved["repo"]
	if owner == "" || repo == "" {
		return values, errors.New("owner or repo not specified")

View on GitHub (pinned to 0ea1f775a7)

Solutions

  1. 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)
  2. Check rate limits, especially Search API limits, and retry after Reset (curl -H ... /rate_limit)
  3. Confirm the resolved owner is an organization the token can see; for a personal account this org: search returns no/failing results
  4. Wait and retry if the response was a 403 secondary rate limit (search abuse mechanism)
  5. Improve the code to wrap the underlying error (return nil, fmt.Errorf("failed to get repositories: %w", err)) so the cause is visible

Example fix

// before
repos, _, err := client.Search.Repositories(ctx, query, &github.SearchOptions{ListOptions: github.ListOptions{PerPage: 100}})
if err != nil || repos == nil {
    return values, errors.New("failed to get repositories")
}

// after
repos, _, err := client.Search.Repositories(ctx, query, &github.SearchOptions{ListOptions: github.ListOptions{PerPage: 100}})
if err != nil {
    return values, fmt.Errorf("failed to get repositories: %w", err)
}
if repos == nil {
    return values, errors.New("failed to get repositories: nil result")
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Verify owner is resolvable and token has org read access before completing
if resolved["owner"] == "" {
    return // nothing to complete against
}
// Optional: cheap auth check before search
_, _, err := client.Users.Get(ctx, "")
if err != nil {
    // token invalid; skip repo completion rather than search
    return
}

Try / catch

// In the completion handler wrapper: degrade to empty suggestions instead of
// failing the whole MCP completion request.
values, err := resolver(ctx, client, resolved, argValue)
if err != nil {
    if strings.Contains(err.Error(), "failed to get repositories") {
        return &mcp.CompleteResult{Completion: mcp.CompletionResultDetails{Values: []string{}}}, nil
    }
    return nil, err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of github/github-mcp-server@0ea1f775a7 (2026-08-15). Data as JSON: /api/errors/acb1e8ca7698d7a3. Report an issue: GitHub.