{"record":{"id":"05880d44aabcc99c","repo":"googleapis/mcp-toolbox","slug":"invalid-project-id-q-must-match-s","errorCode":null,"errorMessage":"invalid project ID %q: must match %s","messagePattern":"invalid project ID %q: must match (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/util/cloudsqlconnect/inputvalidate.go","lineNumber":48,"sourceCode":"//   - Cloud SQL instance IDs:     https://cloud.google.com/sql/docs/postgres/instance-settings\nvar (\n\tprojectIDRe        = regexp.MustCompile(`^[a-z][-a-z0-9]{4,28}[a-z0-9]$`)\n\tgcpRegionRe        = regexp.MustCompile(`^[a-z]+-[a-z0-9-]+$`)\n\tcloudSQLInstanceRe = regexp.MustCompile(`^[a-z][a-z0-9-]{0,97}[a-z0-9]$`)\n\tgceResourceRe      = regexp.MustCompile(`^[a-z]([-a-z0-9]{0,61}[a-z0-9])?$`)\n\tdatabaseNameRe     = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_-]{0,62}$`)\n)\n\n// ValidateInstanceConnectionName splits and validates project, region, and\n// instance ID per the GCP naming rules. Use this in place of plain\n// ParseConnectionName when the parts will flow into generated code or shell.\nfunc ValidateInstanceConnectionName(connName string) (project, region, instance string, err error) {\n\tproject, region, instance, err = ParseConnectionName(connName)\n\tif err != nil {\n\t\treturn \"\", \"\", \"\", err\n\t}\n\tif !projectIDRe.MatchString(project) {\n\t\treturn \"\", \"\", \"\", fmt.Errorf(\"invalid project ID %q: must match %s\", project, projectIDRe)\n\t}\n\tif !gcpRegionRe.MatchString(region) {\n\t\treturn \"\", \"\", \"\", fmt.Errorf(\"invalid region %q: must match %s\", region, gcpRegionRe)\n\t}\n\tif !cloudSQLInstanceRe.MatchString(instance) {\n\t\treturn \"\", \"\", \"\", fmt.Errorf(\"invalid Cloud SQL instance ID %q: must match %s\", instance, cloudSQLInstanceRe)\n\t}\n\treturn project, region, instance, nil\n}\n\n// ValidateGCEResourceName checks a VM name or zone name against the standard\n// GCE resource-name rule (lowercase, digits, hyphen; must start with a letter\n// and not end with a hyphen, max 63 chars).\nfunc ValidateGCEResourceName(name, kind string) error {\n\tif !gceResourceRe.MatchString(name) {\n\t\treturn fmt.Errorf(\"invalid %s %q: must match %s\", kind, name, gceResourceRe)\n\t}\n\treturn nil","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/util/cloudsqlconnect/inputvalidate.go#L30-L66","documentation":"ValidateInstanceConnectionName splits a Cloud SQL connection name (project:region:instance) and checks each part against upstream GCP naming rules. The project segment must match ^[a-z][-a-z0-9]{4,28}[a-z0-9]$ (6-30 chars, lowercase, start with letter). This validation exists because these parts get interpolated into shell commands, JDBC URLs, and generated code, so metacharacters must be rejected.","triggerScenarios":"Passing a connection name whose project segment is invalid: contains uppercase, underscores, is fewer than 6 characters, starts with a digit or hyphen, or exceeds 30 characters.","commonSituations":"Developer used the project NUMBER (e.g. \"123456789012\") instead of the project ID; used the display name (which may contain uppercase/spaces); typo'd or truncated the project ID.","solutions":["Get the canonical project ID via `gcloud projects describe <name> --format='value(projectId)'` and use it in the connection name","Fix the connection name string to form 'my-project:us-central1:my-instance' with a valid lowercase project ID","Check that you didn't pass the project number or an environment-variable placeholder that didn't expand"],"exampleFix":"// before\nValidateInstanceConnectionName(\"123456789012:us-central1:my-db\")\n// after\nValidateInstanceConnectionName(\"my-project-id:us-central1:my-db\")","handlingStrategy":"validation","validationCode":"var projectIDRe = regexp.MustCompile(`^[a-z][-a-z0-9]{4,28}[a-z0-9]$`)\nparts := strings.SplitN(connName, \":\", 3)\nif len(parts) != 3 || !projectIDRe.MatchString(parts[0]) {\n    return fmt.Errorf(\"project segment %q of connection name is not a valid project ID\", parts[0])\n}","typeGuard":"func isValidProjectID(id string) bool {\n    return regexp.MustCompile(`^[a-z][-a-z0-9]{4,28}[a-z0-9]$`).MatchString(id)\n}","tryCatchPattern":"project, region, instance, err := cloudsqlconnect.ValidateInstanceConnectionName(connName)\nif err != nil {\n    return fmt.Errorf(\"connection name %q rejected: %w (expected form 'project:region:instance')\", connName, err)\n}","preventionTips":["Use project IDs, never project numbers or display names","Resolve the canonical project ID at startup with the Resource Manager API","Validate connection names at config-load time, not at call time"],"tags":["gcp","validation","input-validation"],"backgroundTag":"input-validation-failed","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}