googleapis/mcp-toolbox · error

unable to create pool: %w

Error message

unable to create pool: %w

What it means

The YugabyteDB source's Config.Initialize calls initYugabyteDBConnectionPool to build a pgx connection pool (with Yugabyte load-balancing options). Any error constructing the pool — bad DSN parameters, driver issues, invalid load-balance/topology settings — is wrapped as 'unable to create pool: %w'. The wrapped cause carries the precise reason.

Source

Thrown at internal/sources/yugabytedb/yugabytedb.go:68

	Port                            string `yaml:"port" validate:"required"`
	User                            string `yaml:"user" validate:"required"`
	Password                        string `yaml:"password" validate:"required"`
	Database                        string `yaml:"database" validate:"required"`
	LoadBalance                     string `yaml:"loadBalance"`
	TopologyKeys                    string `yaml:"topologyKeys"`
	YBServersRefreshInterval        string `yaml:"ybServersRefreshInterval"`
	FallBackToTopologyKeysOnly      string `yaml:"fallbackToTopologyKeysOnly"`
	FailedHostReconnectDelaySeconds string `yaml:"failedHostReconnectDelaySecs"`
}

func (r Config) SourceConfigType() string {
	return SourceType
}

func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
	pool, err := initYugabyteDBConnectionPool(ctx, tracer, r.Name, r.Host, r.Port, r.User, r.Password, r.Database, r.LoadBalance, r.TopologyKeys, r.YBServersRefreshInterval, r.FallBackToTopologyKeysOnly, r.FailedHostReconnectDelaySeconds)
	if err != nil {
		return nil, fmt.Errorf("unable to create pool: %w", err)
	}

	err = pool.Ping(ctx)
	if err != nil {
		pool.Close()
		return nil, fmt.Errorf("unable to connect successfully: %w", err)
	}

	s := &Source{
		Config: r,
		Pool:   pool,
	}
	return s, nil
}

var _ sources.Source = &Source{}

type Source struct {

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Verify host, port, user, password, and database values in the source config
  2. Validate load_balance and topology_keys formatting against Yugabyte docs (e.g. 'preload-topology-keys' or 'topology-key=region.zone')
  3. Check numeric fields (yb_servers_refresh_interval, failed_host_reconnect_delay_seconds) are valid integers
  4. Inspect the wrapped '%w' cause in the error message for the exact parse/config failure

Example fix

// before
host: yb-server
loadBalance: topology=wrong-format
// after
host: yb-server
loadBalance: true
topologyKeys: cloud1.datacenter1.rack1
Defensive patterns

Strategy: validation

Validate before calling

const required = ["host", "port", "user", "password", "database"];
for (const f of required) {
  if (cfg[f] === undefined || cfg[f] === "") throw new Error(`yugabytedb config missing field: ${f}`);
}
if (!Number.isInteger(cfg.port) || cfg.port <= 0) throw new Error("port must be a positive integer");

Type guard

function isCompleteYbConfig(c: Partial<YbConfig>): c is YbConfig {
  return typeof c.host === "string" && typeof c.port === "number" &&
    typeof c.user === "string" && typeof c.password === "string" &&
    typeof c.database === "string";
}

Try / catch

try {
  await startToolbox();
} catch (err) {
  if (String(err).includes("unable to create pool")) {
    console.error("Yugabyte pool config invalid; check cause:", err.cause ?? err.message);
    process.exit(1);
  }
  throw err;
}

Prevention

When it happens

Trigger: Initialize with invalid connection parameters (host/port/user/password/database), malformed topology_keys or load_balance settings, or an unparseable combination passed to pgxpool config before any connection is attempted.

Common situations: Wrong port or hostname in tools.yaml; invalid YAML types (e.g. string where int expected for port/refresh interval); unsupported topology keys syntax; unreachable Yugabyte servers only surfacing later at Ping (error 1028 instead).

Related errors


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