Configuration
Complete configuration guide for the Terraform MCP Server including Neo4j database setup, environment variables, and security settings.
📋 Prerequisites
| Requirement | Description |
|---|---|
| Python 3.12+ | Required for installation |
| Neo4j 4.4+ | With vector search support |
| Terraform CLI | For command execution |
| AI Provider API Key | OpenAI, Anthropic, Azure OpenAI, Cohere, or Ollama |
🗄️ Neo4j Database Setup
Option 1: Docker (Recommended)
# Pull the latest Neo4j Docker image
docker pull neo4j
# Start Neo4j database
docker run \
--publish=7474:7474 --publish=7687:7687 \
--volume=/path/to/your/neo4j_data:/data \
--env NEO4J_AUTH=neo4j/your-password \
--env NEO4J_PLUGINS='["apoc"]' \
--env "NEO4J_dbms_security_procedures_unrestricted=apoc.*,apoc.meta.data" \
--env "NEO4J_dbms_security_procedures_allowlist=apoc.*,apoc.meta.data" \
neo4j
Important Notes:
- Replace
/path/to/your/neo4j_datawith your data directory - Replace
your-passwordwith a secure password - Port 7474: Neo4j Browser (web interface)
- Port 7687: Bolt protocol (used by MCP server)
Option 2: Direct Installation
Download and install Neo4j from neo4j.com following their official installation guide.
📦 Installation Options
Option 1: Using uv (Recommended)
# Install uv if not already installed
curl -LsSf https://astral.sh/uv/install.sh | sh
# Clone the repository
git clone git@github.com:talkops-ai/talkops-mcp.git
cd talkops-mcp/src/terraform-mcp-server
# Create virtual environment and install
uv venv --python=3.12
source .venv/bin/activate # Unix/macOS
# .venv\Scripts\activate # Windows
uv pip install -e .
Option 2: Using pip
git clone git@github.com:talkops-ai/talkops-mcp.git
cd talkops-mcp/src/terraform-mcp-server
python -m venv .venv
source .venv/bin/activate
pip install -e .
⚙️ Environment Variables
Create a .env file in the project root:
touch .env
Required Configuration
# Neo4j Configuration
NEO4J_URI=bolt://localhost:7687
NEO4J_USERNAME=neo4j
NEO4J_PASSWORD=your-password
# AI Provider Configuration (choose one)
OPENAI_API_KEY=sk-... # OpenAI
ANTHROPIC_API_KEY=sk-ant-... # Anthropic
AZURE_OPENAI_API_KEY=your-key # Azure OpenAI
AZURE_OPENAI_ENDPOINT=https://... # Azure OpenAI
Optional Configuration
# Additional AI Providers
COHERE_API_KEY=your-key # Cohere
OLLAMA_BASE_URL=http://localhost:11434 # Ollama
# Server Configuration
HOST=0.0.0.0
PORT=8000
LOG_LEVEL=INFO
📊 Configuration Reference
Server Configuration
| Variable | Default | Description |
|---|---|---|
HOST | 0.0.0.0 | Server host address |
PORT | 8000 | Server port |
DEBUG | false | Debug mode |
LOG_LEVEL | INFO | Logging level |
Neo4j Configuration
| Variable | Default | Description |
|---|---|---|
NEO4J_URI | bolt://localhost:7687 | Neo4j connection URI |
NEO4J_USERNAME | neo4j | Database username |
NEO4J_PASSWORD | (required) | Database password |
AI Configuration
| Variable | Default | Description |
|---|---|---|
LLM_PROVIDER | openai | LLM provider |
LLM_MODEL | gpt-4o | LLM model name |
EMBEDDING_PROVIDER | openai | Embedding provider |
EMBEDDING_MODEL | text-embedding-ada-002 | Embedding model |
EMBEDDING_DIMENSIONS | 1536 | Embedding dimensions |
Terraform Execution Security
| Variable | Default | Description |
|---|---|---|
TERRAFORM_SECURITY_ENABLED | true | Enable security features |
TERRAFORM_ALLOWED_COMMANDS | ["init", "plan", "validate", "apply", "destroy"] | Allowed commands |
TERRAFORM_ALLOWED_WORKING_DIRECTORIES | ["/tmp", "/var/tmp"] | Allowed directories |
TERRAFORM_MAX_TIMEOUT | 1800 | Max timeout (30 min) |
TERRAFORM_DEFAULT_TIMEOUT | 300 | Default timeout (5 min) |
TERRAFORM_MAX_VARIABLES | 100 | Max variables per execution |
TERRAFORM_MAX_OUTPUT_LENGTH | 10000 | Max output characters |
🔐 Security Configuration
Terraform Execution Security
| Setting | Default | Description |
|---|---|---|
TERRAFORM_DANGEROUS_PATTERNS_ENABLED | true | Enable pattern detection |
TERRAFORM_WORKING_DIRECTORY_VALIDATION | true | Enable directory validation |
TERRAFORM_MAX_WORKING_DIRECTORY_DEPTH | 10 | Maximum directory depth |
TERRAFORM_BLOCKED_WORKING_DIRECTORIES | /etc, /usr, /bin, /sbin, /boot, /dev, /proc, /sys | Blocked directories |
Dangerous Patterns Detected
The server scans for 100+ dangerous patterns including:
Command Injection:
|,;,&,&&,||,>,>>,<,`,$(
System Commands:
sudo,chmod,chown,bash,sh,curl,wget,ssh,eval,exec
Windows Commands:
cmd,powershell,net,reg,runas,del,rmdir,.bat,.ps1
🚀 Starting the Server
Basic Start
uv run terraform_mcp_server
Custom Configuration
uv run terraform_mcp_server --host 0.0.0.0 --port 9000 --transport stdio
Available Options:
| Option | Default | Description |
|---|---|---|
--host | localhost | Server host |
--port | 8000 | Server port |
--transport | sse | Transport protocol (sse or stdio) |
🔌 MCP Client Configuration
SSE Transport (Default)
{
"mcpServers": {
"terraform-mcp-server": {
"transport": "sse",
"url": "http://localhost:8000/sse",
"description": "Terraform MCP Server for IaC operations",
"disabled": false,
"autoApprove": []
}
}
}
Configuration Parameters
| Parameter | Description |
|---|---|
url | SSE endpoint URL |
transport | Transport protocol (sse) |
disabled | Set to true to disable |
autoApprove | Tools to auto-approve (use with caution) |
🔧 Troubleshooting
Neo4j Connection Failed
Error: Failed to connect to Neo4j database
Solutions:
- Verify Neo4j is running:
docker ps - Check
NEO4J_URIis correct - Verify credentials in
NEO4J_PASSWORD - Ensure ports 7474 and 7687 are accessible
Embedding Generation Failed
Error: Failed to generate embeddings
Solutions:
- Verify API key is set correctly
- Check API key has required permissions
- Ensure network access to AI provider
Terraform Command Not Found
Error: terraform: command not found
Solutions:
- Install Terraform: https://www.terraform.io/downloads
- Ensure Terraform is in PATH
- Check
TERRAFORM_BINARY_PATHif custom location
Security Violation Error
Error: Security violation: dangerous pattern detected
Solutions:
- Review variables for dangerous patterns
- Use safe variable names and values
- Check working directory is in allowed list