MCP Infrastructure as Code Assistant
An MCP server for managing infrastructure as code with Terraform.
Features
- Initialize Terraform working directories
- Generate and show execution plans
- Apply changes to infrastructure
- Destroy infrastructure
- Validate Terraform configurations
- Show current state or saved plans
- Manage Terraform workspaces
Prerequisites
- Python 3.8 or higher
- Terraform 1.5.7 or higher
- Docker and Docker Compose (optional)
Installation
Local Installation
-
Clone the repository:
git clone https://github.com/yourusername/mcp-iac.git cd mcp-iac -
Install dependencies using uv:
curl -LsSf https://astral.sh/uv/install.sh | sh uv pip install -e .
Docker Installation
-
Clone the repository:
git clone https://github.com/yourusername/mcp-iac.git cd mcp-iac -
Build and run the Docker container:
docker-compose up -d
Usage
Local Usage
-
Start the MCP server:
python main.py -
Use the MCP CLI to interact with the server:
mcp terraform_init --working-dir ./terraform mcp terraform_plan --working-dir ./terraform mcp terraform_apply --working-dir ./terraform --auto-approve
Docker Usage
-
Start the MCP server:
docker-compose up -d -
Use the MCP CLI to interact with the server:
mcp terraform_init --working-dir ./terraform mcp terraform_plan --working-dir ./terraform mcp terraform_apply --working-dir ./terraform --auto-approve
Example Terraform Configuration
The repository includes an example Terraform configuration that creates an EC2 instance in AWS:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
provider "aws" {
region = var.region
}
resource "aws_instance" "example" {
ami = var.ami_id
instance_type = var.instance_type
tags = {
Name = var.instance_name
}
}
Contributing
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Available Tools
terraform_init: Initialize a Terraform working directoryterraform_plan: Generate and show an execution plan for Terraformterraform_apply: Apply the changes required to reach the desired stateterraform_destroy: Destroy the infrastructure managed by Terraformterraform_validate: Validate the syntax and internal consistency of Terraform filesterraform_show: Show the current state or a saved planterraform_workspace_list: List Terraform workspacesterraform_workspace_select: Select a Terraform workspace
Example Usage
Here's an example of how to use the MCP server with an AI agent:
-
Start the MCP server:
python main.py -
Connect to the server using an MCP client:
mcp connect http://localhost:8000 -
The AI agent can now help you with Terraform operations. For example:
- Initialize a Terraform working directory
- Generate and review execution plans
- Apply changes to infrastructure
- Destroy infrastructure resources
- Validate Terraform configurations
Examples
Check out the examples directory for sample Terraform configurations that demonstrate how to use the MCP server:
examples/aws-s3: A simple AWS S3 bucket example
Recommend MCP Servers 💡
@hiveflow/mcp-server
Official Model Context Protocol (MCP) server for HiveFlow, enabling AI assistants like Claude and Cursor to directly connect and interact with the HiveFlow automation platform for managing and executing workflows.
@steipete/peekaboo-mcp
A macOS MCP server that enables AI agents to capture screenshots, analyze visual content, and automate GUI interactions through natural language commands.
cronlytic-mcp-server
MCP server to let LLMs (AI Agents) communicate and interact with Cronlytic to perform CRUD operations for serverless cron jobs
touchdesigner-mcp-server
An MCP server implementation that enables AI agents to control and operate TouchDesigner projects
screenMonitorMCP
A REVOLUTIONARY Model Context Protocol (MCP) server! Gives AI real-time vision capabilities and enhanced UI intelligence power. This isn't just screen capture - it gives AI the power to truly "see" and understand your digital world!
GH05TCREW/winsecMCP
A Python-based MCP server for automating Windows security configuration tasks including firewall, RDP, UAC, and account policy management