googleapis/mcp-toolbox · error

invalid connection name %q: project, region, and instance mu

Error message

invalid connection name %q: project, region, and instance must all be non-empty

What it means

After splitting on ':', ParseConnectionName additionally requires every segment (project, region, instance) to be non-empty. A name like 'project::instance' or ':region:instance' has three parts but an empty component, triggering this error.

Source

Thrown at internal/util/cloudsqlconnect/gce.go:38

	"strings"
	"sync"

	"golang.org/x/oauth2"
	"google.golang.org/api/compute/v1"
	"google.golang.org/api/option"
	sqladmin "google.golang.org/api/sqladmin/v1"
)

// ParseConnectionName splits a Cloud SQL instance connection name
// ("project:region:instance") into its three components, rejecting any input
// that doesn't have exactly three non-empty parts.
func ParseConnectionName(connName string) (project, region, instance string, err error) {
	parts := strings.Split(connName, ":")
	if len(parts) != 3 {
		return "", "", "", fmt.Errorf("invalid connection name format %q: expected project:region:instance", connName)
	}
	if parts[0] == "" || parts[1] == "" || parts[2] == "" {
		return "", "", "", fmt.Errorf("invalid connection name %q: project, region, and instance must all be non-empty", connName)
	}
	return parts[0], parts[1], parts[2], nil
}

// ExtractNetworkName pulls the trailing element off a fully-qualified network
// or subnetwork resource path. Idempotent for inputs that are already a name.
func ExtractNetworkName(path string) string {
	idx := strings.LastIndex(path, "/")
	if idx == -1 {
		return path
	}
	return path[idx+1:]
}

// IsSameVPC reports whether the Cloud SQL VPC and the GCE VM VPC resolve to
// the same network name.
func IsSameVPC(sqlVPC, vmVPC string) bool {
	sqlNet := ExtractNetworkName(sqlVPC)

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Ensure all three segments are non-empty, e.g. my-project:us-central1:my-instance
  2. Trim whitespace and validate the connection string before passing it in
  3. Log/inspect the source of the string (env var, YAML field) to find which component is empty

Example fix

// before
conn := fmt.Sprintf("%s:%s:%s", cfg.Project, cfg.Region, cfg.Instance) // Region empty
// after
if cfg.Project == "" || cfg.Region == "" || cfg.Instance == "" {
    return fmt.Errorf("incomplete Cloud SQL config: need project, region, instance")
}
conn := fmt.Sprintf("%s:%s:%s", cfg.Project, cfg.Region, cfg.Instance)
Defensive patterns

Strategy: validation

Validate before calling

func connNameComplete(conn string) bool {
    parts := strings.Split(conn, ":")
    if len(parts) != 3 { return false }
    for _, p := range parts { if strings.TrimSpace(p) == "" { return false } }
    return true
}

Try / catch

p, r, inst, err := cloudsqlconnect.ParseConnectionName(connName)
if err != nil {
    return fmt.Errorf("connection name %q has empty parts; check project/region/instance config: %w", connName, err)
}

Prevention

When it happens

Trigger: Passing a connection string with empty segments such as 'project::instance', ':us-central1:inst', or 'project:region:' to ParseConnectionName or ValidateInstanceConnectionName, often from untrimmed or partially interpolated config values.

Common situations: Environment variables or config templates with missing placeholders; trailing/leading colons from string concatenation; blank config fields passed straight through.

Related errors


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