Skip to main content

Overview

Proper environment configuration is critical for maintaining consistency across development, staging, and production environments while keeping sensitive data secure. This guide covers configuration strategies, environment management, and the 12-factor app methodology.
Environment-based configuration enables seamless deployment across multiple environments while maintaining security and flexibility.

Configuration Strategies

12-Factor App Principles

The MCP Server follows the 12-Factor App methodology for configuration:

Environment Variables

  • Store config in environment
  • Never commit secrets to git
  • Strict separation of config and code
  • Different values per environment

Backing Services

  • Attached resources via URLs
  • Swap services without code changes
  • Database URLs, cache URLs, etc.
  • Service discovery via environment

Build, Release, Run

  • Separate build and run stages
  • Config injected at runtime
  • Immutable releases
  • Rollback capability

Port Binding

  • Export services via port binding
  • Completely self-contained
  • No runtime injection of webserver
  • Configurable port via environment

Environment Types

Development Environment

Purpose: Local development and testing Configuration:
Characteristics:
  • Fast feedback loops
  • Verbose logging
  • In-memory services
  • Mock external dependencies
  • Hot reload enabled

Staging Environment

Purpose: Pre-production testing and validation Configuration:
Characteristics:
  • Production-like configuration
  • Real backing services
  • Monitoring enabled
  • Sanitized production data
  • Load testing environment

Production Environment

Purpose: Live user-facing deployment Configuration:
Characteristics:
  • Maximum security
  • High availability
  • Performance optimized
  • Full observability
  • Strict rate limiting

Environment Variable Management

Required Variables

string
required
Environment name: development, staging, or production
string
required
Authentication provider: inmemory or keycloak
string
required
Session storage: memory or redis
string
required
LLM provider: anthropic, openai, google, or ollama

Optional Variables

boolean
default:"false"
Enable debug mode (verbose logging, tracebacks)
string
default:"info"
Logging level: debug, info, warning, error, critical
integer
default:"8000"
HTTP server port
integer
default:"4"
Number of worker processes (production)

Provider-Specific Variables

Keycloak:
Redis:
OpenFGA:
LLM Providers:

Configuration Files

.env File Structure

.env.example Template

Create a template for new developers:

.gitignore

CRITICAL: Never commit secrets to git:

Infisical Integration

Centralized Secret Management

Use Infisical to manage secrets across environments:

Environment-Specific Secrets

Development:
Production:

Docker Configuration

docker-compose.yml

Environment-based configuration with Docker Compose:

Multi-Stage Dockerfile

Build once, configure at runtime:

Kubernetes Configuration

ConfigMaps

Store non-sensitive configuration:

Secrets

Store sensitive data in Kubernetes Secrets:

External Secrets Operator

Sync from Infisical automatically:

Deployment with Environment Config

Configuration Validation

Pydantic Settings

Use Pydantic for type-safe configuration:

Startup Validation

Validate configuration on application startup:

Environment-Specific Features

Feature Flags

Enable features based on environment:

Best Practices

Always use .gitignore:
Use secret scanning:
Keep dev, staging, and production as similar as possible:Same backing services:
  • Development: Docker Compose
  • Staging: Kubernetes (minikube/kind)
  • Production: Kubernetes (GKE/EKS/AKS)
Same configuration structure:
  • All environments use same .env format
  • Same ConfigMap structure
  • Same secret keys
Validate configuration before starting:
Centralize secret management:Benefits:
  • Automatic secret rotation
  • Audit logging
  • Access control
  • Version history
  • Emergency revocation
Setup:

Troubleshooting

Problem: Settings show default values instead of .env valuesSolutions:
Problem: Application exits on startupSolutions:
Problem: Pods use old configurationSolutions:

Next Steps

Infisical Setup

Centralized secret management

Secret Rotation

Automated secret rotation

Kubernetes Deployment

Deploy to Kubernetes

Production Checklist

Pre-deployment security

Environment Configuration Ready: Secure, validated configuration across all environments!