googleapis/mcp-toolbox · error

unable to create db connection: %w

Error message

unable to create db connection: %w

What it means

sqlite Config.Initialize (internal/sources/sqlite/sqlite.go:64) opens the SQLite database via initSQLiteConnection (sql.Open over the sqlite driver). If the driver fails to open the database file (or a prep-hook/pragma fails), the error is wrapped as "unable to create db connection". Note sql.Open usually doesn't touch the file, so this most often indicates a bad DSN/path configuration or driver-level error.

Source

Thrown at internal/sources/sqlite/sqlite.go:64

	}
	return actual, nil
}

type Config struct {
	Name         string `yaml:"name" validate:"required"`
	Type         string `yaml:"type" validate:"required"`
	Database     string `yaml:"database" validate:"required"` // Path to SQLite database file
	SQLCommenter *bool  `yaml:"sqlCommenter"`
}

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

func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
	db, err := initSQLiteConnection(ctx, tracer, r.Name, r.Database)
	if err != nil {
		return nil, fmt.Errorf("unable to create db connection: %w", err)
	}

	err = db.PingContext(context.Background())
	if err != nil {
		db.Close()
		return nil, fmt.Errorf("unable to connect successfully: %w", err)
	}

	s := &Source{
		Config: r,
		Db:     db,
	}
	return s, nil
}

var _ sources.Source = &Source{}

type Source struct {

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Verify the `database` path in the source config points to a writable location and its parent directory exists
  2. Create the directory before starting: mkdir -p $(dirname /path/to/db.sqlite3)
  3. Check filesystem permissions on the db file and directory
  4. If using a URI DSN, validate the `file:...?...` syntax the driver expects

Example fix

// before
name: my-sqlite
database: /nonexistent/dir/data.db
// after
name: my-sqlite
database: /tmp/toolbox/data.db  # mkdir -p /tmp/toolbox first
Defensive patterns

Strategy: validation

Validate before calling

if dbPath == "" { return errors.New("sqlite database path is empty") }
if err := os.MkdirAll(filepath.Dir(dbPath), 0o755); err != nil {
	return fmt.Errorf("cannot create db directory: %w", err)
}

Prevention

When it happens

Trigger: Initialize called with a sqlite source whose name/database path is invalid: empty database path, directory doesn't exist, or the driver's Open hook (e.g. PRAGMA setup) fails.

Common situations: Typo in the database file path; parent directory not created before connecting; read-only filesystem; using `file:...` URI syntax incorrectly; missing CGO or driver not compiled in for some sqlite drivers.

Related errors


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