googleapis/mcp-toolbox · error

sql.Open: %w

Error message

sql.Open: %w

What it means

Wraps the error returned by database/sql's sql.Open when registering/opening the 'clickhouse' driver with the constructed DSN fails. sql.Open mostly validates driver name and DSN format; it fails here if the clickhouse driver is not registered or the DSN is malformed.

Source

Thrown at internal/sources/clickhouse/clickhouse.go:208

		return nil, err
	}

	encodedUser := url.QueryEscape(user)
	encodedPass := url.QueryEscape(pass)

	var dsn string
	scheme := protocol
	if protocol == "http" && secure {
		scheme = "https"
	}
	dsn = fmt.Sprintf("%s://%s:%s@%s:%s/%s", scheme, encodedUser, encodedPass, host, port, dbname)
	if scheme == "https" {
		dsn += "?secure=true&skip_verify=false"
	}

	pool, err := sql.Open("clickhouse", dsn)
	if err != nil {
		return nil, fmt.Errorf("sql.Open: %w", err)
	}

	pool.SetMaxOpenConns(25)
	pool.SetMaxIdleConns(5)
	pool.SetConnMaxLifetime(5 * time.Minute)

	return pool, nil
}

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Check that host, port, user, pass, and dbname fields are all non-empty and correctly quoted in the YAML
  2. URL-encode special characters in the password or use a password without reserved characters
  3. Inspect the underlying wrapped error for the specific DSN parse message

Example fix

// before
user: "admin"
pass: "p@ss:word"  # breaks DSN parsing
// after
user: "admin"
pass: "p%40ss%3Aword"  # URL-encoded
Defensive patterns

Strategy: validation

Validate before calling

// validate fields before initializing the source
func checkCH(host, port, user, pass, dbname string) error {
    for name, v := range map[string]string{"host":host,"port":port,"user":user,"pass":pass,"dbname":dbname} {
        if v == "" { return fmt.Errorf("%s must not be empty", name) }
        if strings.ContainsAny(v, " &#@") { return fmt.Errorf("%s has characters that break the DSN; URL-encode them", name) }
    }
    return nil
}

Try / catch

// Go: unwrap the sql.Open error
if _, err := initPool(...); err != nil {
    log.Fatalf("clickhouse pool init failed: %v", err) // wrapped error contains DSN parse detail
}

Prevention

When it happens

Trigger: Initialize calls initClickHouseConnectionPool, which builds the DSN from host/port/user/pass/dbname/protocol and calls sql.Open('clickhouse', dsn); failure occurs on a malformed DSN (bad characters in credentials or database name) or the clickhouse driver failing to parse the options.

Common situations: Passwords containing special characters (&, @, spaces) that break DSN parsing, empty required fields (host, user, dbname) producing an unparseable DSN, or protocol https with a bad query-string combination.

Related errors


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