googleapis/mcp-toolbox · error
unable to parse connection uri: %w
Error message
unable to parse connection uri: %w
What it means
pgxpool.ParseConfig rejected the connection URI assembled by BuildPostgresURL from the configured host, port, user, password, database and queryParams — at least one of these fields produces a malformed DSN (bad port, unescaped credentials, or invalid query parameter).
Source
Thrown at internal/sources/postgres/postgres.go:163
func initPostgresConnectionPool(ctx context.Context, tracer trace.Tracer, name, host, port, user, pass, dbname string, queryParams map[string]string, queryExecMode string, connectTimeout *int) (*pgxpool.Pool, error) {
//nolint:all // Reassigned ctx
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
defer span.End()
userAgent, err := util.UserAgentFromContext(ctx)
if err != nil {
userAgent = "genai-toolbox"
}
if queryParams == nil {
// Initialize the map before using it
queryParams = make(map[string]string)
}
if _, ok := queryParams["application_name"]; !ok {
queryParams["application_name"] = userAgent
}
config, err := pgxpool.ParseConfig(BuildPostgresURL(host, port, user, pass, dbname, queryParams))
if err != nil {
return nil, fmt.Errorf("unable to parse connection uri: %w", err)
}
execMode, err := ParseQueryExecMode(queryExecMode)
if err != nil {
return nil, err
}
config.ConnConfig.DefaultQueryExecMode = execMode
if connectTimeout != nil {
config.ConnConfig.ConnectTimeout = time.Duration(*connectTimeout) * time.Second
}
pool, err := pgxpool.NewWithConfig(ctx, config)
if err != nil {
return nil, fmt.Errorf("unable to create connection pool: %w", err)
}
return pool, nilView on GitHub (pinned to 8cc6e09de2)
Solutions
- Verify host, port, user, password, database and connectionParams values in the source's YAML configuration
- URL-encode any special characters in the password or query parameter values
- Test the assembled URI locally with psql or pgxpool.ParseConfig to reproduce the parse failure
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/sources/postgres/postgres.go:163 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/04240a49a6566d32.
Report an issue: GitHub.