googleapis/mcp-toolbox · error
invalid %s %q: must match %s
Error message
invalid %s %q: must match %s
What it means
ValidateGCEResourceName checks a VM name or zone name against the GCE resource-name rule ^[a-z]([-a-z0-9]{0,61}[a-z0-9])?$: lowercase letters, digits, and hyphens; must start with a letter, must not end with a hyphen, max 63 chars. The failing value is echoed in the message along with the kind ('vm', 'zone', etc.) supplied by the caller.
Source
Thrown at internal/util/cloudsqlconnect/inputvalidate.go:64
}
if !projectIDRe.MatchString(project) {
return "", "", "", fmt.Errorf("invalid project ID %q: must match %s", project, projectIDRe)
}
if !gcpRegionRe.MatchString(region) {
return "", "", "", fmt.Errorf("invalid region %q: must match %s", region, gcpRegionRe)
}
if !cloudSQLInstanceRe.MatchString(instance) {
return "", "", "", fmt.Errorf("invalid Cloud SQL instance ID %q: must match %s", instance, cloudSQLInstanceRe)
}
return project, region, instance, nil
}
// ValidateGCEResourceName checks a VM name or zone name against the standard
// GCE resource-name rule (lowercase, digits, hyphen; must start with a letter
// and not end with a hyphen, max 63 chars).
func ValidateGCEResourceName(name, kind string) error {
if !gceResourceRe.MatchString(name) {
return fmt.Errorf("invalid %s %q: must match %s", kind, name, gceResourceRe)
}
return nil
}
// ValidateDatabaseName accepts the conservative subset of database identifier
// characters that's safe in DSNs and code-snippet templates across Postgres,
// MySQL and SQL Server. It deliberately rejects quotes, semicolons, and
// whitespace even when the engine itself would accept them.
func ValidateDatabaseName(name string) error {
if !databaseNameRe.MatchString(name) {
return fmt.Errorf("invalid database_name %q: must match %s", name, databaseNameRe)
}
return nil
}
View on GitHub (pinned to 8cc6e09de2)
Solutions
- Convert the name to lowercase and replace underscores with hyphens
- Ensure it starts with a letter and ends with a letter or digit, and is at most 63 characters
- Verify the actual resource name with `gcloud compute instances list` or `gcloud compute zones list`
Example fix
// before
ValidateGCEResourceName("My_VM_01", "vm")
// after
ValidateGCEResourceName("my-vm-01", "vm") Defensive patterns
Strategy: validation
Validate before calling
var gceResourceRe = regexp.MustCompile(`^[a-z]([-a-z0-9]{0,61}[a-z0-9])?$`)
if err := cloudsqlconnect.ValidateGCEResourceName(vmName, "vm"); err != nil {
return err
}
if err := cloudsqlconnect.ValidateGCEResourceName(zone, "zone"); err != nil {
return err
} Type guard
func isValidGCEResource(name string) bool {
return regexp.MustCompile(`^[a-z]([-a-z0-9]{0,61}[a-z0-9])?$`).MatchString(name)
} Try / catch
if err := cloudsqlconnect.ValidateGCEResourceName(name, kind); err != nil {
return fmt.Errorf("%w (GCE names: lowercase letters/digits/hyphens, start with a letter, max 63 chars)", err)
} Prevention
- Normalize names to lowercase and replace underscores before passing them in
- Reject uppercase/underscored names at the config or flag level
- Trim whitespace from copy-pasted names
When it happens
Trigger: Calling FindVM-related tool flows (via Invoke) with a vm_name or vm_zone containing uppercase letters, underscores, spaces, a leading digit, or a trailing hyphen.
Common situations: VM names copied from cloud consoles of other providers; CamelCase names like 'MyVM'; zone typed as 'us_central1_a'; accidental trailing whitespace or hyphen from copy-paste.
Related errors
- invalid connection name %q: project, region, and instance mu
- failed to build token-scoped Compute Engine client: %w
- failed to search for VM: %w
- VM %q not found in project %q
- multiple VMs named %q found in zones: %v - please specify vm
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/0aa4b08f9ee22a36.
Report an issue: GitHub.