process.env.* in src/; this page summarizes everything currently read by the code on main.
Core application
Authentication
Better Auth (optional social login)
Better Auth is initialized once at process startup insrc/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:
BETTER_AUTH_*environment variablessystemConfig.auth.betterAuth(frommcp_settings.jsonor the database-backed system config)- Built-in defaults
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
Environment variables win over the dashboard. Every setting above overrides the matching field saved in the dashboard. Resolution order is environment variable → dashboard setting → built-in default, so a stale value left in
.env silently shadows a key you just pasted into the UI — embeddings then fail with an authentication error while the form still shows the new key (issue #642).The dashboard now reports this: affected fields carry a warning naming the environment variable that is actually in use. To switch to the dashboard value, remove the variable from the environment and restart.Smart Routing → Enabled and DB URL follow the same order but are reflected directly by the UI instead of a warning — the toggle mirrors the env var, and the URL field renders a ${DB_URL} placeholder.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:- System environment variables.
.env.local(gitignored)..env.{NODE_ENV}(e.g..env.production)..env.
dotenv-expand is enabled, so ${VAR} interpolation works inside .env* files.
Security best practices
- Never commit secrets —
.env*files are gitignored by default; keep it that way. - Always set
JWT_SECRETexplicitly in production. - Rotate bearer keys (
/api/auth/keys) and OAuth client secrets periodically. - Use Docker / Kubernetes secrets for container deployments instead of plain
-e.