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

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Verify host, port, user, password, database and connectionParams values in the source's YAML configuration
  2. URL-encode any special characters in the password or query parameter values
  3. 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


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