{"record":{"id":"c34a2022843f691a","repo":"googleapis/mcp-toolbox","slug":"unable-to-parse-connection-uri-w-c34a20","errorCode":null,"errorMessage":"unable to parse connection uri: %w","messagePattern":"unable to parse connection uri: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/cloudsqlpg/cloud_sql_pg.go","lineNumber":200,"sourceCode":"\t}\n\n\treturn dsn, useIAM, nil\n}\n\nfunc initCloudSQLPgConnectionPool(ctx context.Context, tracer trace.Tracer, name, project, region, instance, ipType, user, pass, dbname string, readOnly bool) (*pgxpool.Pool, error) {\n\t//nolint:all // Reassigned ctx\n\tctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)\n\tdefer span.End()\n\n\t// Configure the driver to connect to the database\n\tdsn, useIAM, err := getConnectionConfig(ctx, user, pass, dbname, readOnly)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to get Cloud SQL connection config: %w\", err)\n\t}\n\n\tconfig, err := pgxpool.ParseConfig(dsn)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to parse connection uri: %w\", err)\n\t}\n\n\t// Create a new dialer with options\n\tuserAgent, err := util.UserAgentFromContext(ctx)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\topts, err := sources.GetCloudSQLOpts(ipType, userAgent, useIAM)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\td, err := cloudsqlconn.NewDialer(ctx, opts...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to parse connection uri: %w\", err)\n\t}\n\n\t// Tell the driver to use the Cloud SQL Go Connector to create connections\n\ti := fmt.Sprintf(\"%s:%s:%s\", project, region, instance)","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/cloudsqlpg/cloud_sql_pg.go#L182-L218","documentation":"After building the DSN, the pool config is parsed with pgxpool.ParseConfig. If the DSN string is malformed (bad key=value pairs, unescaped characters in user/dbname, or a broken options clause), parsing fails and the source cannot be created. Notably, a password containing spaces or special characters without escaping will break this parser.","triggerScenarios":"Initialize where the generated DSN is invalid — typically a password or user containing spaces, quotes, or '=' characters interpolated verbatim into the key=value DSN, or a corrupted readOnly options clause.","commonSituations":"Passwords with special characters pasted from a secrets manager; usernames with spaces (IAM emails are usually fine); older config with a password containing single quotes.","solutions":["Escape or avoid special characters (spaces, quotes, '=') in the user and password; prefer URL-encoded or simple credentials.","Regenerate a password without characters that break DSN key=value parsing.","If the error persists, enable debug logging of the DSN (with secrets redacted) to find the malformed token."],"exampleFix":"// before: password: p@ss word'123  (breaks DSN parsing)\n// after: password: pAssW0rd123  or URL-escape special characters","handlingStrategy":"validation","validationCode":"if strings.ContainsAny(pass, \" '=\") {\n    return errors.New(\"password contains characters unsafe for DSN; regenerate or escape it\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate passwords without spaces, quotes, or '=' signs","Test the DSN with 'psql <dsn>' before wiring it into configs","Store secrets in a manager that avoids problematic characters","Remember the same message may come from NewDialer (616) — check which line threw"],"tags":["postgres","dsn","configuration","pgx","connection-string"],"backgroundTag":"invalid-connection-string","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"}