googleapis/mcp-toolbox · error

error getting AlloyDB cluster: %w

Error message

error getting AlloyDB cluster: %w

What it means

This error wraps a failure from the AlloyDB Admin API Clusters.Get call, which fetches a single cluster by its fully qualified resource name. It is thrown when the REST GET request fails with an HTTP error or transport failure. The wrapped error preserves the underlying Google API error for programmatic handling.

Source

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

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

	return resp, nil
}

func (s *Source) GetCluster(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.Get(urlString).Do()
	if err != nil {
		return nil, fmt.Errorf("error getting AlloyDB cluster: %w", err)
	}

	return resp, nil
}

func (s *Source) GetInstance(ctx context.Context, project, location, cluster, instance, 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/instances/%s", project, location, cluster, instance)

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

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Verify the cluster name, project, and location are correct with gcloud alloydb clusters list
  2. Check the access token is valid and has cloud-platform/alloydb scope; refresh if expired
  3. Handle 404 distinctly — the cluster may have been deleted or never created
  4. Retry transient failures (5xx, network errors) with backoff
  5. Unwrap with errors.As(*googleapi.Error) to branch on the HTTP status code

Example fix

// before
resp, err := service.Projects.Locations.Clusters.Get(urlString).Do()
if err != nil { return nil, fmt.Errorf("error getting AlloyDB cluster: %w", err) }
// after
resp, err := service.Projects.Locations.Clusters.Get(urlString).Do()
if err != nil {
    var gerr *googleapi.Error
    if errors.As(err, &gerr) && gerr.Code == 404 {
        return nil, fmt.Errorf("cluster %s not found in %s/%s: %w", cluster, project, location, err)
    }
    return nil, fmt.Errorf("error getting AlloyDB cluster: %w", err)
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Go: validate resource identifiers before the call
if project == "" || location == "" || cluster == "" {
    return fmt.Errorf("project, location and cluster must be non-empty")
}
if !isValidRegion(location) {
    return fmt.Errorf("location %q is not a valid AlloyDB region", location)
}

Type guard

func IsNotFound(err error) bool {
    var gerr *googleapi.Error
    return errors.As(err, &gerr) && gerr.Code == 404
}

Try / catch

cluster, err := s.GetCluster(ctx, project, location, clusterName, accessToken)
if err != nil {
    var gerr *googleapi.Error
    if errors.As(err, &gerr) && gerr.Code == 404 {
        return nil, fmt.Errorf("cluster %q does not exist in %s/%s", clusterName, project, location)
    }
    if errors.As(err, &gerr) && gerr.Code >= 500 {
        return retryWithBackoff(...)
    }
    return err
}

Prevention

When it happens

Trigger: Calling Source.GetCluster when the cluster does not exist (404), the location is wrong, the access token is expired or lacks scope, or the network request to the AlloyDB Admin endpoint fails.

Common situations: Querying a cluster in the wrong region, deleted clusters, misconfigured project/location strings in tool config, revoked or short-lived access tokens, and transient network failures.

Related errors


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