googleapis/mcp-toolbox · error

unable to create connection pool: %w

Error message

unable to create connection pool: %w

What it means

pgxpool.NewWithConfig failed while establishing the Postgres connection pool during source Initialize; the config parsed fine but the server was unreachable, credentials were rejected, or TLS settings mismatched.

Source

Thrown at internal/sources/postgres/postgres.go:178

	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, nil
}

// BuildPostgresURL assembles a postgres connection URL from its components.
// It uses net.JoinHostPort so IPv6 host literals are wrapped in brackets as
// required by RFC 3986 (e.g. "[::1]:5432"); IPv4 addresses and hostnames are
// left unchanged. Query parameters are encoded with url.Values so special
// characters are escaped correctly and the output is deterministic.
func BuildPostgresURL(host, port, user, pass, dbname string, queryParams map[string]string) string {
	u := &url.URL{
		Scheme: "postgres",
		User:   url.UserPassword(user, pass),
		Host:   net.JoinHostPort(host, port),
		Path:   dbname,
	}
	if len(queryParams) > 0 {

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Confirm the Postgres server is running and reachable from the Toolbox host (network, firewall, VPC)
  2. Check username/password and pg_hba.conf rules
  3. Verify TLS/SSL requirements match between client config and server
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at internal/sources/postgres/postgres.go:178 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05). Data as JSON: /api/errors/1891f0ef742d1eb2. Report an issue: GitHub.