{"record":{"id":"6acc358eb6199b66","repo":"googleapis/mcp-toolbox","slug":"unable-to-parse-connection-uri-w","errorCode":null,"errorMessage":"unable to parse connection uri: %w","messagePattern":"unable to parse connection uri: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/alloydbpg/alloydb_pg.go","lineNumber":223,"sourceCode":"\t\tdsn += \" options='-c alloydb_session_read_only=locked'\"\n\t}\n\n\treturn dsn, useIAM, nil\n}\n\nfunc initAlloyDBPgConnectionPool(ctx context.Context, tracer trace.Tracer, name, project, region, cluster, 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\tdsn, useIAM, err := getConnectionConfig(ctx, user, pass, dbname, readOnly)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to get AlloyDB 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\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 := getOpts(ipType, userAgent, useIAM)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\td, err := alloydbconn.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 AlloyDB Go Connector to create connections\n\ti := fmt.Sprintf(\"projects/%s/locations/%s/clusters/%s/instances/%s\", project, region, cluster, instance)\n\tconfig.ConnConfig.DialFunc = func(ctx context.Context, _ string, instance string) (net.Conn, error) {","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/alloydbpg/alloydb_pg.go#L205-L241","documentation":"After building the DSN, initAlloyDBPgConnectionPool calls pgxpool.ParseConfig to validate the connection string. This error indicates the constructed DSN is not a parseable pgx connection string/URI, so no pool can be created. Because the DSN is built by the source from project/region/cluster/instance plus user fields, this usually means one of those inputs is malformed (e.g. contains characters illegal in a DSN).","triggerScenarios":"Calling Initialize with a dbname, user, or other DSN component containing characters pgx cannot parse (spaces, unescaped quotes, invalid keyword=value syntax) or an instance name with unexpected separators.","commonSituations":"Database or username values pasted with surrounding whitespace or quotes into YAML; special characters in passwords interpolated into the DSN without escaping; non-ASCII or control characters in config values.","solutions":["Inspect the wrapped pgx error text — it names the offending DSN keyword or syntax problem.","Check the user/dbname/password values in your config for stray quotes, spaces, or unescaped special characters.","If the password contains special characters, use IAM auth (leave user/pass empty) or URL-encode the password component.","Verify the project/region/cluster/instance fields are plain identifiers without extra characters."],"exampleFix":"// before: dbname with quotes/whitespace in config\ndbname: \"\" \"my db\"\"\"  // invalid DSN keyword value\n// after\ndbname: mydb","handlingStrategy":"validation","validationCode":"if strings.ContainsAny(dbname, \" '\\\"\") || strings.ContainsAny(user, \" '\\\"\") {\n    return errors.New(\"dbname/user contain DSN-illegal characters\")\n}\nif _, err := pgxpool.ParseConfig(testDSN); err != nil {\n    return fmt.Errorf(\"invalid DSN: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if _, err := pgxpool.ParseConfig(dsn); err != nil {\n    return fmt.Errorf(\"check dbname/user values for illegal characters: %w\", err)\n}","preventionTips":["Avoid quotes, spaces, and control characters in dbname/user config values.","Trim whitespace on all config string fields before writing them to YAML.","URL-encode special characters in passwords if embedding them in a DSN.","Test the DSN locally with psql or pgx ParseConfig before deploying."],"tags":["alloydb","postgres","configuration","pgx"],"backgroundTag":"connection-string-parse-error","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"}