Environment Configuration
Both the MCP server and webhook server share common environment variable requirements for Slack integration, queue backends, and basic configuration. This guide covers all shared environment variables used across both server types.
Configuration Priority Orderโ
When running the Slack MCP Server, configuration values are loaded in the following priority order (highest to lowest):
.envfile (HIGHEST PRIORITY) - Values in your.envfile override everything- CLI arguments (
--slack-token) - Used as fallback if not set in.envfile - Environment variables - Already set environment variables (lowest priority)
This means your .env file values will always take precedence over CLI arguments, making it easier to manage different environments without worrying about accidental overrides from command-line options.
Example:
# In your .env file
SLACK_BOT_TOKEN=xoxb-production-token
# Even if you run with --slack-token argument, the .env value wins
slack-mcp-server --slack-token xoxb-dev-token # Still uses xoxb-production-token from .env
# To use CLI argument instead, disable .env file loading
slack-mcp-server --slack-token xoxb-dev-token --no-env-file # Now uses xoxb-dev-token
Required Environment Variablesโ
Slack Authenticationโ
The primary requirement for both servers is Slack bot authentication:
# Slack bot token (required for both MCP and webhook servers)
SLACK_BOT_TOKEN="xoxb-your-bot-token-here"
How to get your bot token:
- Go to Slack API Apps
- Create a new app or select an existing one
- Navigate to "OAuth & Permissions"
- Copy the "Bot User OAuth Token" (starts with
xoxb-)
Optional Environment Variablesโ
Alternative Authentication Variablesโ
# Alternative token variable (fallback, used by some legacy configurations)
SLACK_TOKEN="xoxb-your-bot-token-here"
# Additional Slack credentials (for advanced features)
SLACK_BOT_ID="B1234567890" # Your bot's user ID
SLACK_USER_TOKEN="xoxp-your-user-token" # For user-level operations
SLACK_SIGNING_SECRET="your-signing-secret" # For webhook request verification
Development and Testing Variablesโ
# Test channel configuration (useful for development/testing)
SLACK_TEST_CHANNEL="#dev-testing" # Channel name with #
SLACK_TEST_CHANNEL_ID="C1234567890" # Channel ID (recommended)
Queue Backend Configurationโ
Both servers support multiple queue backend options for handling asynchronous operations:
# Queue backend selection
QUEUE_BACKEND="memory" # Options: memory | redis | kafka | custom_backend_name
# Redis backend settings (when QUEUE_BACKEND=redis)
REDIS_URL="redis://localhost:6379/0"
# Kafka backend settings (when QUEUE_BACKEND=kafka)
KAFKA_BOOTSTRAP="broker1:9092,broker2:9092"
Queue Backend Options:
- memory: In-memory queue (default, good for development)
- redis: Redis-based queue (recommended for production)
- kafka: Apache Kafka (for high-throughput scenarios)
- custom plugins: Any custom queue backend plugin from the abstract-backend library
Queue backend implementations are provided by the abstract-backend library. For information about available backends and developing custom queue backend plugins, refer to the abstract-backend documentation.
Web Server CORS Configurationโ
The webhook server includes configurable CORS (Cross-Origin Resource Sharing) settings to control which origins can access the server:
# Allowed origins for CORS requests
CORS_ALLOW_ORIGINS="*" # Default: allow all origins
# Allow credentials in CORS requests (cookies, authorization headers, etc.)
CORS_ALLOW_CREDENTIALS="true" # Default: true
# Allowed HTTP methods for CORS requests
CORS_ALLOW_METHODS="*" # Default: allow all methods
# Allowed HTTP headers for CORS requests
CORS_ALLOW_HEADERS="*" # Default: allow all headers
CORS Configuration Examples:
- Development
- Production
- Highly Restricted
# Development: Allow local origins
CORS_ALLOW_ORIGINS="http://localhost:3000,http://localhost:8080"
CORS_ALLOW_CREDENTIALS="true"
CORS_ALLOW_METHODS="GET,POST,PUT,DELETE,OPTIONS"
CORS_ALLOW_HEADERS="Content-Type,Authorization,X-Requested-With"
# Production: Restrict to specific domains
CORS_ALLOW_ORIGINS="https://app.yourdomain.com,https://admin.yourdomain.com"
CORS_ALLOW_CREDENTIALS="true"
CORS_ALLOW_METHODS="GET,POST,PUT"
CORS_ALLOW_HEADERS="Content-Type,Authorization"
# High security: Minimal CORS
CORS_ALLOW_ORIGINS="https://app.yourdomain.com"
CORS_ALLOW_CREDENTIALS="false"
CORS_ALLOW_METHODS="GET,POST"
CORS_ALLOW_HEADERS="Content-Type"
CORS Security Considerations:
- Development: Use
"*"or local origins for easier testing - Production: Always specify exact domains for better security
- Credentials: Only enable
CORS_ALLOW_CREDENTIALS="true"when needed - Methods: Limit to only the HTTP methods your application actually uses
- Headers: Restrict to only the headers your application requires
Environment File Structureโ
The Slack MCP Server uses separate environment files for different purposes to maintain clear separation between production and testing configurations:
๐ Production Environment Configurationโ
File: .env.example โ .env (root directory)
- Purpose: Production server configuration
- Usage: MCP server, webhook server, and integrated server
- Contains: All production environment variables with detailed documentation
# Copy the production template
cp .env.example .env
# Edit .env with your actual production values
๐งช Test Environment Configurationโ
File: test/.env.test.example โ test/.env.test (test directory)
- Purpose: Test execution configuration only
- Usage: Unit tests, integration tests, and E2E tests
- Contains: Test-specific variables and test environment controls
# Copy the test template
cp test/.env.test.example test/.env.test
# Edit test/.env.test with your test values
Environment File Loading Optionsโ
Both the MCP server and webhook server support flexible environment file loading:
Default Behaviorโ
By default, the server automatically loads variables from .env in the current directory:
# Automatically loads from .env file
slack-mcp-server
# Automatically loads from .env file
slack-events-server
Custom Environment Fileโ
Specify a custom environment file path:
# MCP server with custom env file
slack-mcp-server --env-file .env.production
# Webhook server with custom env file
slack-events-server --env-file /path/to/.env.staging
Disable Environment File Loadingโ
Disable automatic .env file loading (useful when relying only on system environment variables or CLI arguments):
# MCP server without .env file
slack-mcp-server --no-env-file --slack-token xoxb-your-token
# Webhook server without .env file
slack-events-server --no-env-file --slack-token xoxb-your-token
Test Environment Loadingโ
During test execution, the test framework automatically loads from test/.env.test:
# Tests automatically use test/.env.test
uv run pytest
# Tests can be controlled with MCP_NO_ENV_FILE
MCP_NO_ENV_FILE=true uv run pytest # Skip main .env file loading
Environment File Examplesโ
Development Environment (.env.development)โ
- Basic Setup
- Advanced Setup
# Basic development configuration
SLACK_BOT_TOKEN="xoxb-your-development-token"
SLACK_TEST_CHANNEL="#dev-testing"
QUEUE_BACKEND="memory"
# CORS: Allow local development origins
CORS_ALLOW_ORIGINS="http://localhost:3000,http://localhost:8080"
CORS_ALLOW_CREDENTIALS="true"
CORS_ALLOW_METHODS="GET,POST,PUT,DELETE,OPTIONS"
CORS_ALLOW_HEADERS="Content-Type,Authorization,X-Requested-With"
# Advanced development configuration
SLACK_BOT_TOKEN="xoxb-your-development-token"
SLACK_USER_TOKEN="xoxp-your-user-token"
SLACK_SIGNING_SECRET="your-development-signing-secret"
SLACK_TEST_CHANNEL="#dev-testing"
SLACK_TEST_CHANNEL_ID="C1234567890"
QUEUE_BACKEND="redis"
REDIS_URL="redis://localhost:6379/1"
# CORS: Allow local development origins with full access
CORS_ALLOW_ORIGINS="http://localhost:3000,http://localhost:8080,http://localhost:5173"
CORS_ALLOW_CREDENTIALS="true"
CORS_ALLOW_METHODS="GET,POST,PUT,DELETE,PATCH,OPTIONS"
CORS_ALLOW_HEADERS="Content-Type,Authorization,X-Requested-With,X-Custom-Header"
Production Environment (.env.production)โ
- Basic Production
- Advanced Production
# Basic production configuration
SLACK_BOT_TOKEN="xoxb-your-production-token"
QUEUE_BACKEND="redis"
REDIS_URL="redis://prod-redis:6379/0"
# CORS: Restrict to production domains
CORS_ALLOW_ORIGINS="https://app.yourdomain.com"
CORS_ALLOW_CREDENTIALS="true"
CORS_ALLOW_METHODS="GET,POST,PUT"
CORS_ALLOW_HEADERS="Content-Type,Authorization"
# Advanced production configuration
SLACK_BOT_TOKEN="xoxb-your-production-token"
SLACK_USER_TOKEN="xoxp-your-user-token"
SLACK_SIGNING_SECRET="your-production-signing-secret"
QUEUE_BACKEND="kafka"
KAFKA_BOOTSTRAP="kafka-1:9092,kafka-2:9092,kafka-3:9092"
# CORS: Allow multiple production domains with restricted access
CORS_ALLOW_ORIGINS="https://app.yourdomain.com,https://admin.yourdomain.com,https://api.yourdomain.com"
CORS_ALLOW_CREDENTIALS="true"
CORS_ALLOW_METHODS="GET,POST,PUT,DELETE"
CORS_ALLOW_HEADERS="Content-Type,Authorization,X-API-Key"
Testing Environment (test/.env.test)โ
The test environment uses a separate configuration file to avoid conflicts with production settings:
# Test-specific configuration (test/.env.test)
E2E_TEST_API_TOKEN="xoxb-your-test-slack-bot-token"
SLACK_TEST_CHANNEL="#automated-testing"
SLACK_TEST_CHANNEL_ID="C9876543210"
MCP_NO_ENV_FILE=true
QUEUE_BACKEND="memory"
Key Test Environment Variables:
E2E_TEST_API_TOKEN: Bot token for end-to-end testsSLACK_TEST_CHANNEL: Test channel name (with # prefix)SLACK_TEST_CHANNEL_ID: Test channel ID (recommended over name)MCP_NO_ENV_FILE=true: Prevents loading main .env file during testsQUEUE_BACKEND="memory": Uses in-memory queue for test isolation
Test Environment Setup:
# Copy test environment template
cp test/.env.test.example test/.env.test
# Edit with your test values
nano test/.env.test
# Run tests (automatically uses test/.env.test)
uv run pytest
The test environment is designed to be completely isolated from production:
- Uses
test/.env.testinstead of.env MCP_NO_ENV_FILE=trueprevents loading production settingsQUEUE_BACKEND="memory"ensures test isolation- Separate test channels avoid production data contamination
Docker Environment Configurationโ
When running servers in Docker containers, you can pass environment variables in several ways:
Using Environment Filesโ
# Run with environment file
docker run --env-file .env.production your-server-image
# Docker Compose
version: '3.8'
services:
slack-server:
image: your-server-image
env_file:
- .env.production
Using Environment Variables Directlyโ
# Pass individual environment variables
docker run \
-e SLACK_BOT_TOKEN="xoxb-your-token" \
-e QUEUE_BACKEND="redis" \
-e REDIS_URL="redis://redis:6379/0" \
your-server-image
Environment Variable Validationโ
Both servers perform automatic validation of environment variables on startup:
Required Variable Validationโ
- Checks for presence of
SLACK_BOT_TOKEN - Validates token format (must start with
xoxb-) - Warns about missing optional variables
Queue Backend Validationโ
- Validates
QUEUE_BACKENDvalue against allowed options - Checks backend-specific connection variables
- Tests connectivity to external services (Redis/Kafka)
Common Validation Errorsโ
# Missing required token
โ Error: SLACK_BOT_TOKEN environment variable is required
# Invalid token format
โ Error: SLACK_BOT_TOKEN must start with 'xoxb-'
# Invalid queue backend
โ Error: QUEUE_BACKEND must be one of: memory, redis, kafka
# Redis connection failed
โ Error: Cannot connect to Redis at redis://localhost:6379/0
Security Best Practicesโ
Token Securityโ
- Never commit tokens to version control
- Use
.envfiles and add them to.gitignore - Rotate tokens regularly in production
- Use different tokens for different environments
Environment File Securityโ
- Set appropriate file permissions:
chmod 600 .env - Store production
.envfiles securely - Use secrets management systems in production (e.g., Kubernetes secrets, AWS Secrets Manager)
Example .gitignoreโ
# Production environment files
.env
.env.local
.env.development
.env.production
# Test environment files
test/.env.test
test/.env.test.local
# Backup env files
*.env.backup
Both production (.env) and test (test/.env.test) environment files contain sensitive credentials and should never be committed to version control. Always add both to your .gitignore file.
Troubleshooting Environment Issuesโ
Token Issuesโ
# Test token validity
curl -H "Authorization: Bearer $SLACK_BOT_TOKEN" \
https://slack.com/api/auth.test
Redis Connection Issuesโ
# Test Redis connection
redis-cli -u $REDIS_URL ping
Environment Variable Debugโ
# Check if variables are loaded
env | grep SLACK_
env | grep QUEUE_
env | grep REDIS_
For server-specific configuration options, see: