googleapis/mcp-toolbox · error

sql.Open: %w

Error message

sql.Open: %w

What it means

initSingleStoreConnectionPool wraps sql.Open errors with this message. sql.Open validates the driver name and performs minimal DSN parsing; a failure here means the DSN built from the config (user, password, host, port, database, connection params) is malformed or the mysql driver is not registered.

Source

Thrown at internal/sources/singlestore/singlestore.go:219

		connectionParams.Set("readTimeout", timeout.String())
	}

	// Custom user parameters (e.g. tls, compress) — may override defaults above.
	for k, v := range cfg.ConnectionParams {
		if v == "" {
			continue // skip empty values
		}
		connectionParams.Set(k, v)
	}
	dsn := mysqlCfg.FormatDSN()
	if enc := connectionParams.Encode(); enc != "" {
		dsn += "&" + enc
	}

	// Interact with the driver directly as you normally would
	pool, err := sql.Open("mysql", dsn)
	if err != nil {
		return nil, fmt.Errorf("sql.Open: %w", err)
	}
	return pool, nil
}

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Check the wrapped error for the exact DSN parse failure point.
  2. URL-escape special characters in the password or change it to an alphanumeric value temporarily.
  3. Validate connectionParams keys/values; remove exotic or duplicated params one at a time to isolate the offender.
  4. Confirm host/port formatting (no scheme, no trailing slash) in the source config.
  5. Ensure go-sql-driver/mysql is imported/registered (it is in this build; a custom binary build may lack it).

Example fix

// before (unescaped password with @)
password: p@ss word
// after
password: "p%40ss%20word"  # or change password to avoid special chars
Defensive patterns

Strategy: validation

Validate before calling

// Validate DSN-relevant fields before Initialize
func validateSSConfig(cfg Config) error {
    if cfg.Host == "" { return errors.New("host required") }
    if strings.ContainsAny(cfg.Password, "@/ ") { return errors.New("password contains DSN-unsafe chars; URL-escape it") }
    for k := range cfg.ConnectionParams {
        if strings.ContainsAny(k, "=& ") { return fmt.Errorf("invalid connection param key %q", k) }
    }
    return nil
}

Try / catch

src, err := cfg.Initialize(ctx, tracer)
if err != nil && strings.Contains(err.Error(), "sql.Open:") {
    return fmt.Errorf("DSN invalid — check host/port/password escaping/params: %w", err)
}

Prevention

When it happens

Trigger: Malformed DSN caused by bad config values (unescaped characters in password, invalid connectionParams keys/values, bad host format) or, rarely, the mysql driver failing to register.

Common situations: Passwords containing special characters like @ or / without URL-escaping, invalid characters in connection params that break the encoded query string, empty host, or stray whitespace in config fields.

Related errors


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