Skip to main content

Terraform MCP server

The Terraform MCP Server is a Model Context Protocol server for Infrastructure as Code automation. It combines sandboxed Terraform CLI execution (init, validate, plan, apply, destroy) with Neo4j-backed vector similarity search across Terraform provider documentation so AI agents generate valid HCL resources without hallucinating deprecated provider arguments.

Core capabilities​

CapabilityDescription
Sandboxed Terraform ExecutionWhitelisted execution of init, validate, plan, apply, destroy, output, state, and fmt with directory traversal protection and 100+ dangerous pattern checks.
Semantic Provider SearchHNSW vector similarity search (1536-dimensional embeddings in Neo4j) over Terraform provider resources, data sources, and architecture best practices with 10–100ms query latency.
Intelligent Doc IngestionMulti-format ingestion pipeline (Markdown, HTML, PDF) with LLM-assisted schema extraction and semantic chunking.
Multi-Provider EmbeddingsSupports OpenAI, Anthropic, Azure OpenAI, HuggingFace, Cohere, and local Ollama models.

Architecture​

Quickstart​

1
Verify prerequisites

Ensure you have Python 3.12+, the Terraform CLI (v1.x), a running Neo4j 5.x+ instance (for vector search), and an embedding provider API key (such as OPENAI_API_KEY).

2
Install and launch the server

Clone the repository, install dependencies with uv, and start the server:

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 .

uv run terraform_mcp_server
3
Connect your MCP client

Register the SSE endpoint in your MCP client configuration:

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

Tool summary​

ToolPurpose
terraform_executeRun whitelisted Terraform commands (init, validate, plan, apply, destroy) inside a validated working directory with timeout and variable scanning.
terraform_doc_searchQuery the Neo4j vector index for provider resource arguments, nested block schemas, data sources, and module best practices.
ingest_terraform_docsParse, chunk, embed, and store Terraform provider documentation into Neo4j with incremental deduplication.

Security guardrails​

GuardrailEnforcement
Command WhitelistingRejects arbitrary shell binaries; only explicitly allowed Terraform subcommands can run.
Directory Traversal ProtectionResolves and validates working directories to block .. path escapes and system directory access.
Variable & Flag ScanningScans input variables (up to 100 keys) and command arguments against 100+ shell injection and remote execution patterns.
Execution TimeoutsEnforces configurable per-command timeouts (1 to 1800 seconds) and truncates oversized stdout/stderr payloads.

Project structure​

terraform-mcp-server/
├── terraform_mcp_server/ # Main package
│ ├── tools/ # MCP tool implementations
│ │ ├── tf_execution/ # Sandboxed Terraform command runner
│ │ ├── tf_search/ # Semantic provider doc search
│ │ └── tf_ingestion/ # Documentation ingestion pipeline
│ ├── services/ # Core services
│ │ ├── embedding/ # Multi-provider vector embeddings
│ │ ├── llm/ # LLM content extraction
│ │ └── neo4j/ # Neo4j vector & graph storage
│ ├── server/ # FastMCP server setup
│ └── config.py # Pydantic settings management
├── tests/ # Test suite
└── pyproject.toml # Project configuration