googleapis/mcp-toolbox · error

error listing AlloyDB clusters: %w

Error message

error listing AlloyDB clusters: %w

What it means

This error wraps a failure from the AlloyDB Admin API Clusters.List call, which enumerates all clusters in a given project and location. It fires when the REST list request returns an HTTP error or transport failure. The underlying Google API error is preserved via %w so status codes can be examined.

Source

Thrown at internal/sources/alloydbadmin/alloydbadmin.go:292

	resp, err := service.Projects.Locations.Clusters.Users.Get(urlString).Do()
	if err != nil {
		return nil, fmt.Errorf("error getting AlloyDB user: %w", err)
	}
	return resp, nil
}

func (s *Source) ListCluster(ctx context.Context, project, location, accessToken string) (any, error) {
	service, err := s.getService(ctx, accessToken)
	if err != nil {
		return nil, err
	}

	urlString := fmt.Sprintf("projects/%s/locations/%s", project, location)

	resp, err := service.Projects.Locations.Clusters.List(urlString).Do()
	if err != nil {
		return nil, fmt.Errorf("error listing AlloyDB clusters: %w", err)
	}
	return resp, nil
}

func (s *Source) ListInstance(ctx context.Context, project, location, cluster, accessToken string) (any, error) {
	service, err := s.getService(ctx, accessToken)
	if err != nil {
		return nil, err
	}

	urlString := fmt.Sprintf("projects/%s/locations/%s/clusters/%s", project, location, cluster)

	resp, err := service.Projects.Locations.Clusters.Instances.List(urlString).Do()
	if err != nil {
		return nil, fmt.Errorf("error listing AlloyDB instances: %w", err)
	}
	return resp, nil
}

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Verify the location is a valid AlloyDB region and the project ID is correct
  2. Ensure the AlloyDB Admin API (alloydb.googleapis.com) is enabled on the project
  3. Refresh the access token and check it has cloud-platform or alloydb.admin scope
  4. Retry on 429/5xx with exponential backoff
  5. Inspect the wrapped *googleapi.Error for the exact HTTP status and message

Example fix

// before
resp, err := service.Projects.Locations.Clusters.List(urlString).Do()
if err != nil { return nil, fmt.Errorf("error listing AlloyDB clusters: %w", err) }
// after
resp, err := service.Projects.Locations.Clusters.List(urlString).Do()
if err != nil {
    var gerr *googleapi.Error
    if errors.As(err, &gerr) {
        if gerr.Code == 403 && strings.Contains(gerr.Message, "has not been used") {
            return nil, fmt.Errorf("enable the AlloyDB Admin API on project %s: %w", project, err)
        }
    }
    return nil, fmt.Errorf("error listing AlloyDB clusters: %w", err)
}
Defensive patterns

Strategy: retry

Validate before calling

// Go: validate location/project and token presence before ListCluster
if project == "" || location == "" {
    return fmt.Errorf("project and location must be non-empty")
}
if accessToken == "" {
    return fmt.Errorf("access token missing; obtain one with cloud-platform scope")
}

Type guard

func IsRetryable(err error) bool {
    var gerr *googleapi.Error
    if !errors.As(err, &gerr) {
        return true // transport errors are usually retryable
    }
    return gerr.Code == 429 || gerr.Code >= 500
}

Try / catch

var resp any
err := retry.Do(3, func() error {
    var e error
    resp, e = s.ListCluster(ctx, project, location, accessToken)
    var gerr *googleapi.Error
    if errors.As(e, &gerr) && (gerr.Code == 429 || gerr.Code >= 500) {
        return e // retry
    }
    return retry.Stop(e) // no retry
})

Prevention

When it happens

Trigger: Calling Source.ListCluster with a nonexistent or misspelled location (e.g., wrong region), an expired/under-scoped access token, or network failure during Projects.Locations.Clusters.List(urlString).Do().

Common situations: Configured region not matching where clusters were provisioned, disabled AlloyDB Admin API in the project, quota or rate-limit responses (429), and stale tokens in services without token refresh.

Related errors


AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05). Data as JSON: /api/errors/9ff6e640892ca4db. Report an issue: GitHub.