{"record":{"id":"1344fb134a732ed2","repo":"googleapis/mcp-toolbox","slug":"invalid-cloud-sql-instance-id-q-must-match-s","errorCode":null,"errorMessage":"invalid Cloud SQL instance ID %q: must match %s","messagePattern":"invalid Cloud SQL instance ID %q: must match (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/util/cloudsqlconnect/inputvalidate.go","lineNumber":54,"sourceCode":"\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\n}\n\n// ValidateDatabaseName accepts the conservative subset of database identifier\n// characters that's safe in DSNs and code-snippet templates across Postgres,\n// MySQL and SQL Server. It deliberately rejects quotes, semicolons, and\n// whitespace even when the engine itself would accept them.","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/util/cloudsqlconnect/inputvalidate.go#L36-L72","documentation":"ValidateInstanceConnectionName checks the instance-ID segment of a connection name against ^[a-z][a-z0-9-]{0,97}[a-z0-9]$ (lowercase, start with a letter, end with letter/digit, up to 99 chars). Cloud SQL instance IDs follow these upstream naming rules, and this validation prevents unsafe characters from reaching generated code or DSN templates.","triggerScenarios":"Passing a connection name whose final segment contains uppercase, underscores, spaces, starts with a digit or hyphen, ends with a hyphen, or is empty.","commonSituations":"Developer used the instance's display name or connection alias instead of the instance ID; used a Postgres database name instead of the Cloud SQL instance ID; pasted a full connection name with a trailing character.","solutions":["Use the Cloud SQL instance ID from `gcloud sql instances list --format='value(name)'`","Convert the ID to lowercase and remove underscores/invalid characters","Confirm the connection name has exactly three colon-separated parts: project:region:instance"],"exampleFix":"// before\nValidateInstanceConnectionName(\"my-project:us-central1:My_Instance\")\n// after\nValidateInstanceConnectionName(\"my-project:us-central1:my-instance\")","handlingStrategy":"validation","validationCode":"var cloudSQLInstanceRe = regexp.MustCompile(`^[a-z][a-z0-9-]{0,97}[a-z0-9]$`)\ninstance := parts[2]\nif !cloudSQLInstanceRe.MatchString(instance) {\n    return fmt.Errorf(\"instance segment %q is not a valid Cloud SQL instance ID\", instance)\n}","typeGuard":"func isValidCloudSQLInstanceID(id string) bool {\n    return regexp.MustCompile(`^[a-z][a-z0-9-]{0,97}[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; instance ID must be lowercase, start with a letter\", connName, err)\n}","preventionTips":["Use the Cloud SQL instance ID, not the display name or database name","Lowercase instance IDs when generating them (e.g. in CI pipelines)","Validate the whole 'project:region:instance' string before storing it in config"],"tags":["gcp","validation","cloudsql"],"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"}