googleapis/mcp-toolbox · error

error cloning instance: %w

Error message

error cloning instance: %w

What it means

Thrown in CloneInstance when the sqladmin Instances.Clone call (projects.instances.clone) returns an API error. The clone request reached Cloud SQL (or failed client-side) and the API rejected or failed the operation.

Source

Thrown at internal/sources/cloudsqladmin/cloud_sql_admin.go:176

		cloneContext.PointInTime = pointInTime
	}
	if preferredZone != "" {
		cloneContext.PreferredZone = preferredZone
	}
	if preferredSecondaryZone != "" {
		cloneContext.PreferredSecondaryZone = preferredSecondaryZone
	}

	rb := &sqladmin.InstancesCloneRequest{
		CloneContext: cloneContext,
	}
	service, err := s.GetService(ctx, accessToken)
	if err != nil {
		return nil, err
	}
	resp, err := service.Instances.Clone(project, sourceInstanceName, rb).Do()
	if err != nil {
		return nil, fmt.Errorf("error cloning instance: %w", err)
	}
	return resp, nil
}

func (s *Source) CreateDatabase(ctx context.Context, name, project, instance, accessToken string) (any, error) {
	database := sqladmin.Database{
		Name:     name,
		Project:  project,
		Instance: instance,
	}

	service, err := s.GetService(ctx, accessToken)
	if err != nil {
		return nil, err
	}

	resp, err := service.Databases.Insert(project, instance, &database).Do()
	if err != nil {

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Confirm the source instance name and project are correct and the instance is RUNNABLE.
  2. Grant the caller IAM role roles/cloudsql.admin (or sql.instances.clone) in the target project.
  3. Enable the sqladmin.googleapis.com API in the project.
  4. If using point-in-time recovery, ensure binary logging is enabled on the source and the timestamp is within the recovery window and RFC3339-formatted.
  5. Inspect the wrapped googleapi.Error for its code and message to pinpoint the API rejection reason.

Example fix

// before: PITR timestamp without binary logging
CloneReq{PointInTime: "2024-01-01T00:00:00Z"}
// after: enable binary logging on source first, or omit PointInTime for a current-state clone
CloneReq{} // plain clone
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-check source instance exists and is runnable
resp, err := src.GetInstance(ctx, project, sourceInstanceName, accessToken)
if err != nil {
    return fmt.Errorf("cannot clone: source instance unavailable: %w", err)
}
inst := resp.(*sqladmin.Operation) // preceding get ensures project/instance are valid

Type guard

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

Try / catch

out, err := src.CloneInstance(ctx, project, source, rb, token)
if err != nil {
    var gerr *googleapi.Error
    if errors.As(err, &gerr) {
        switch gerr.Code {
        case 403:
            return fmt.Errorf("missing cloudsql.instances.clone permission: %w", err)
        case 404:
            return fmt.Errorf("source instance not found: %w", err)
        }
    }
    return fmt.Errorf("clone failed: %w", err)
}
// Clone returns an Operation; poll it before assuming success

Prevention

When it happens

Trigger: Calling the clone_instance tool when the source instance does not exist, the target/override settings are invalid (e.g. same-region violation, point-in-time timestamp malformed), the project lacks the sql.instances.clone permission, or quota/billing blocks instance creation.

Common situations: Cloning into a project where the Cloud SQL Admin API is not enabled; cloning a source instance that is currently under maintenance or has PITR disabled while supplying a point-in-time; IAM principal missing roles/cloudsql.admin.

Related errors


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