Using Environment Variables to Specify Options
The server supports environment variables for all configuration options. All
environment variables use the PGEDGE_ prefix to avoid collisions with
other software.
Database Configuration
The following environment variables configure a single database connection:
PGEDGE_DB_HOST: PostgreSQL server hostnamePGEDGE_DB_PORT: PostgreSQL server port (default: 5432)PGEDGE_DB_NAME: Database namePGEDGE_DB_USER: Database usernamePGEDGE_DB_PASSWORD: Database passwordPGEDGE_DB_SSLMODE: SSL mode (disable, prefer, require)
Multiple Database Configuration
For Docker deployments, you can configure multiple databases using numbered environment variables. The init script automatically generates a YAML config file when these variables are detected.
Use the pattern PGEDGE_DB_N_* where N is a number from 1 to 99:
PGEDGE_DB_N_NAME: Display name for the database (required)PGEDGE_DB_N_HOST: PostgreSQL server hostnamePGEDGE_DB_N_PORT: PostgreSQL server port (default: 5432)PGEDGE_DB_N_DATABASE: Database name (defaults to NAME)PGEDGE_DB_N_USER: Database username (default: postgres)PGEDGE_DB_N_PASSWORD: Database passwordPGEDGE_DB_N_SSLMODE: SSL mode (default: prefer)PGEDGE_DB_N_ALLOW_WRITES: Allow write operations (default: false)
Numbers do not need to be sequential; gaps are skipped automatically. For example, you can define PGEDGE_DB_1_, PGEDGE_DB_5_, and PGEDGE_DB_10_*.
Example - Two databases in Docker:
# Production database (read-only)
PGEDGE_DB_1_NAME=production
PGEDGE_DB_1_HOST=prod-db.example.com
PGEDGE_DB_1_DATABASE=prod_db
PGEDGE_DB_1_USER=readonly_user
PGEDGE_DB_1_PASSWORD=secret123
PGEDGE_DB_1_SSLMODE=require
PGEDGE_DB_1_ALLOW_WRITES=false
# Development database (with writes)
PGEDGE_DB_2_NAME=development
PGEDGE_DB_2_HOST=localhost
PGEDGE_DB_2_DATABASE=dev_db
PGEDGE_DB_2_USER=postgres
PGEDGE_DB_2_PASSWORD=devpass
PGEDGE_DB_2_ALLOW_WRITES=true
For more information on multiple database configuration, see Multiple Database Configuration.
LLM Database Switching
When multiple databases are configured, the following environment variable controls whether the LLM can switch between databases:
PGEDGE_LLM_DB_SWITCHING: Enable LLM database switching tools ("true", "1", "yes" to enable; default: disabled)
When enabled, the LLM has access to list_database_connections and
select_database_connection tools. When disabled, users can still switch
databases manually via CLI commands or Web UI.
HTTP/HTTPS Server Configuration
The following environment variables specify HTTP/HTTPS Server preferences:
PGEDGE_HTTP_ENABLED: Enable HTTP transport mode ("true", "1", "yes" to enable)PGEDGE_HTTP_ADDRESS: HTTP server address (default: ":8080")
The following environment variables specify TLS/HTTPS preferences:
PGEDGE_TLS_ENABLED: Enable TLS/HTTPS ("true", "1", "yes" to enable)PGEDGE_TLS_CERT_FILE: Path to TLS certificate filePGEDGE_TLS_KEY_FILE: Path to TLS key filePGEDGE_TLS_CHAIN_FILE: Path to TLS certificate chain file (optional)
The following environment variables specify authentication preferences:
PGEDGE_AUTH_ENABLED: Enable API token authentication ("true", "1", "yes" to enable)PGEDGE_AUTH_TOKEN_FILE: Path to API token filePGEDGE_AUTH_USER_FILE: Path to user authentication file
The following environment variables specify LLM provider configuration:
PGEDGE_LLM_ENABLED: Enable LLM proxy for web clientsPGEDGE_LLM_PROVIDER: LLM provider ("anthropic", "openai", or "ollama")PGEDGE_LLM_MODEL: Default model to usePGEDGE_ANTHROPIC_API_KEY: Anthropic API key (orANTHROPIC_API_KEY)PGEDGE_ANTHROPIC_BASE_URL: Custom Anthropic API base URL (for proxies)PGEDGE_OPENAI_API_KEY: OpenAI API key (orOPENAI_API_KEY)PGEDGE_OPENAI_BASE_URL: Custom OpenAI API base URL (for proxies)PGEDGE_OLLAMA_URL: Ollama server URL
The following environment variables specify embedding provider configuration:
PGEDGE_VOYAGE_API_KEY: Voyage AI API key (orVOYAGE_API_KEY)PGEDGE_VOYAGE_BASE_URL: Custom Voyage API base URL (for proxies)PGEDGE_OPENAI_EMBEDDING_BASE_URL: Custom OpenAI embeddings base URL
The following environment variables specify knowledgebase embedding configuration:
PGEDGE_KB_VOYAGE_API_KEY: Voyage API key for knowledgebasePGEDGE_KB_VOYAGE_BASE_URL: Custom Voyage base URL for knowledgebasePGEDGE_KB_OPENAI_API_KEY: OpenAI API key for knowledgebasePGEDGE_KB_OPENAI_BASE_URL: Custom OpenAI base URL for knowledgebasePGEDGE_KB_OLLAMA_URL: Ollama URL for knowledgebase
If you run into issues with your environment variable settings, check:
# Verify environment variables are set
env | grep PGEDGE
# Export the variables if you are running in a new shell
export PGEDGE_HTTP_ENABLED="true"
export PGEDGE_HTTP_ADDRESS=":8080"
Examples - Deploying the MCP Server with Environment Variables
Configuring an HTTP server with authentication:
export PGEDGE_HTTP_ENABLED="true"
export PGEDGE_HTTP_ADDRESS=":8080"
export PGEDGE_AUTH_ENABLED="true"
export PGEDGE_AUTH_TOKEN_FILE="./postgres-mcp-tokens.yaml"
./bin/pgedge-postgres-mcp
Configuring a HTTPS server:
export PGEDGE_HTTP_ENABLED="true"
export PGEDGE_TLS_ENABLED="true"
export PGEDGE_TLS_CERT_FILE="./server.crt"
export PGEDGE_TLS_KEY_FILE="./server.key"
./bin/pgedge-postgres-mcp
Using Environment Variables for Tests:
Tests use a separate environment variable to avoid confusion with runtime configuration:
export TEST_PGEDGE_POSTGRES_CONNECTION_STRING="postgres://localhost/postgres?sslmode=disable"
go test ./...