googleapis/mcp-toolbox · error
unable to parse connection uri: %w
Error message
unable to parse connection uri: %w
What it means
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.
Source
Thrown at internal/sources/cloudsqlpg/cloud_sql_pg.go:200
}
return dsn, useIAM, nil
}
func initCloudSQLPgConnectionPool(ctx context.Context, tracer trace.Tracer, name, project, region, instance, ipType, user, pass, dbname string, readOnly bool) (*pgxpool.Pool, error) {
//nolint:all // Reassigned ctx
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
defer span.End()
// Configure the driver to connect to the database
dsn, useIAM, err := getConnectionConfig(ctx, user, pass, dbname, readOnly)
if err != nil {
return nil, fmt.Errorf("unable to get Cloud SQL connection config: %w", err)
}
config, err := pgxpool.ParseConfig(dsn)
if err != nil {
return nil, fmt.Errorf("unable to parse connection uri: %w", err)
}
// Create a new dialer with options
userAgent, err := util.UserAgentFromContext(ctx)
if err != nil {
return nil, err
}
opts, err := sources.GetCloudSQLOpts(ipType, userAgent, useIAM)
if err != nil {
return nil, err
}
d, err := cloudsqlconn.NewDialer(ctx, opts...)
if err != nil {
return nil, fmt.Errorf("unable to parse connection uri: %w", err)
}
// Tell the driver to use the Cloud SQL Go Connector to create connections
i := fmt.Sprintf("%s:%s:%s", project, region, instance)View on GitHub (pinned to 8cc6e09de2)
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.
Example fix
// before: password: p@ss word'123 (breaks DSN parsing) // after: password: pAssW0rd123 or URL-escape special characters
Defensive patterns
Strategy: validation
Validate before calling
if strings.ContainsAny(pass, " '=") {
return errors.New("password contains characters unsafe for DSN; regenerate or escape it")
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- unable to parse connection uri: %w
- unable to parse row: %w
- unable to parse row: %w
- password is provided without a username. Please provide both
- unable to get Cloud SQL connection config: %w
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/c34a2022843f691a.
Report an issue: GitHub.