Skip to main content
MCPHub reads the following environment variables at startup. The authoritative list is whatever appears under process.env.* in src/; this page summarizes everything currently read by the code on main.

Core application

Authentication

JWT_SECRET must be set to a persistent, high-entropy value (≥ 32 random bytes) in staging and production. If it is left unset, MCPHub generates a new random secret on every process start, which means: every restart invalidates all outstanding sessions and bearer tokens; horizontally-scaled instances cannot share sessions because each replica signs with its own secret; and CI / container restarts silently log everyone out. Generate one with openssl rand -hex 32 and store it in your secret manager. Treat it like any other long-lived cryptographic key — rotation requires invalidating outstanding JWTs.

Better Auth (optional social login)

Better Auth is initialized once at process startup in src/betterAuth.ts. Because of that, changing any Better Auth setting still requires a restart. For non-secret Better Auth settings, MCPHub resolves values in this order:
  1. BETTER_AUTH_* environment variables
  2. systemConfig.auth.betterAuth (from mcp_settings.json or the database-backed system config)
  3. Built-in defaults
Provider client credentials remain environment-variable only.
Better Auth currently requires PostgreSQL-backed storage in MCPHub. In practice that means DB_URL must be configured; file-only mode does not support Better Auth sessions.
You can still store the non-secret Better Auth settings in systemConfig.auth.betterAuth, but BETTER_AUTH_* variables now override those values at startup. A full env-only local OIDC example looks like this:

Storage

MCPHub picks file or database storage at boot:
See Database Configuration for end-to-end setup.

Smart Routing & embeddings

Smart Routing performs vector search over upstream tools to surface only the few most relevant tools for a given query. It requires Postgres + pgvector and an embedding endpoint.

OpenAI

Azure OpenAI

MCPRouter (optional upstream catalog)

Configuration examples

Development

Production with database + Smart Routing

Loading order

MCPHub loads variables in this order; later sources override earlier ones:
  1. System environment variables.
  2. .env.local (gitignored).
  3. .env.{NODE_ENV} (e.g. .env.production).
  4. .env.
dotenv-expand is enabled, so ${VAR} interpolation works inside .env* files.

Security best practices

  1. Never commit secrets — .env* files are gitignored by default; keep it that way.
  2. Always set JWT_SECRET explicitly in production.
  3. Rotate bearer keys (/api/auth/keys) and OAuth client secrets periodically.
  4. Use Docker / Kubernetes secrets for container deployments instead of plain -e.