Skip to main content

Configuration

Configure the Terraform MCP Server using environment variables to connect to your Neo4j vector database, select your embedding and LLM providers, and enforce directory and command whitelisting on Terraform CLI executions.

Prerequisites​

RequirementDescription
Python 3.12+Runtime environment for the FastMCP server
Terraform CLI (v1.x)Required on PATH (or via TERRAFORM_BINARY_PATH) for command execution
Neo4j 5.x+Graph and vector index backend with the apoc plugin enabled
AI Provider API KeyOpenAI, Anthropic, Azure OpenAI, Cohere, or local Ollama endpoint

Neo4j vector database setup​

Start a local Neo4j instance with APOC procedures enabled using Docker:

docker run -d \
--name terraform-neo4j \
--publish=7474:7474 \
--publish=7687:7687 \
--volume=$HOME/neo4j_data:/data \
--env NEO4J_AUTH=neo4j/your-secure-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:5
  • Port 7474: Neo4j Browser UI (http://localhost:7474)
  • Port 7687: Bolt protocol endpoint (bolt://localhost:7687)

Installation and startup​

git clone https://github.com/talkops-ai/talkops-mcp.git
cd talkops-mcp/src/terraform-mcp-server

uv venv --python=3.12
source .venv/bin/activate
uv pip install -e .

# Start the server (default: SSE on port 8000)
uv run terraform_mcp_server

To customize the bind address or run over stdio:

uv run terraform_mcp_server --host 0.0.0.0 --port 9000 --transport stdio

Environment variables​

Create a .env file in the server root directory:

.env
# Neo4j connection
NEO4J_URI=bolt://localhost:7687
NEO4J_USERNAME=neo4j
NEO4J_PASSWORD=your-secure-password

# Embedding & LLM provider (choose one)
OPENAI_API_KEY=sk-...
# ANTHROPIC_API_KEY=sk-ant-...
# OLLAMA_BASE_URL=http://localhost:11434

# Server transport
HOST=0.0.0.0
PORT=8000
LOG_LEVEL=INFO

Server and database settings​

VariableDefaultDescription
HOST0.0.0.0Server bind address
PORT8000Server bind port
LOG_LEVELINFOLogging verbosity (DEBUG, INFO, WARNING, ERROR)
NEO4J_URIbolt://localhost:7687Neo4j Bolt URI
NEO4J_USERNAMEneo4jNeo4j username
NEO4J_PASSWORD(Required)Neo4j password

AI and embedding settings​

VariableDefaultDescription
LLM_PROVIDERopenaiLLM provider for documentation extraction (openai, anthropic, azure, ollama)
LLM_MODELgpt-4oModel identifier used during documentation ingestion
EMBEDDING_PROVIDERopenaiVector embedding provider (openai, cohere, huggingface, ollama)
EMBEDDING_MODELtext-embedding-ada-002Embedding model identifier
EMBEDDING_DIMENSIONS1536Vector index dimensionality

Terraform execution security settings​

VariableDefaultDescription
TERRAFORM_SECURITY_ENABLEDtrueEnforce command whitelisting, path validation, and variable scanning
TERRAFORM_ALLOWED_COMMANDS["init", "plan", "validate", "apply", "destroy"]Permitted Terraform subcommands
TERRAFORM_ALLOWED_WORKING_DIRECTORIES["/tmp", "/var/tmp"]Allowed root directories for Terraform execution
TERRAFORM_BLOCKED_WORKING_DIRECTORIES/etc, /usr, /bin, /sbin, /boot, /dev, /proc, /sysExplicitly forbidden system directories
TERRAFORM_MAX_WORKING_DIRECTORY_DEPTH10Maximum directory nesting depth
TERRAFORM_DEFAULT_TIMEOUT300Default per-command execution timeout (5 minutes)
TERRAFORM_MAX_TIMEOUT1800Maximum configurable timeout (30 minutes)
TERRAFORM_MAX_VARIABLES100Maximum number of -var entries per execution
TERRAFORM_MAX_OUTPUT_LENGTH10000Maximum stdout/stderr character length returned to the agent

Dangerous pattern detection​

When TERRAFORM_DANGEROUS_PATTERNS_ENABLED=true (default), all variable keys, values, and paths are scanned against 100+ injection signatures before invoking the Terraform binary:

  • Shell metacharacters: |, ;, &, &&, ||, >, >>, <, backticks, and $(...) subshells.
  • Privilege & network binaries: sudo, chmod, chown, bash, sh, curl, wget, ssh, eval, exec.
  • Path traversal sequences: ../ or symlink escapes outside TERRAFORM_ALLOWED_WORKING_DIRECTORIES.

MCP client configuration​

mcp.json
{
"mcpServers": {
"terraform-mcp-server": {
"transport": "sse",
"url": "http://localhost:8000/sse",
"description": "Terraform MCP Server for IaC operations",
"disabled": false
}
}
}

Troubleshooting​

ErrorCauseResolution
Failed to connect to Neo4j databaseNeo4j container stopped or wrong NEO4J_URI / NEO4J_PASSWORDVerify container health (docker ps) and ensure Bolt port 7687 is reachable.
terraform: command not foundTerraform CLI binary missing from system PATHInstall Terraform (v1.x) or set TERRAFORM_BINARY_PATH to the full binary path.
Security violation: dangerous pattern detectedVariable value contains shell expansion characters or working directory is outside allowed rootsAdd your workspace root to TERRAFORM_ALLOWED_WORKING_DIRECTORIES and remove shell metacharacters from variable values.