A Model Context Protocol (MCP) server for Azure Terraform operations, providing intelligent assistance for infrastructure as code development with Azure resources.
This MCP server provides support for Azure Terraform development, including:
- Azure provider documentation retrieval of AzureRM, AzAPI and Azure Verified Module(AVM)
- HCL code validation and static analysis with TFLint
- Security scanning and compliance checking
- Best practices guidance
- Resource analysis and recommendations
- Azure Provider Docs: Comprehensive documentation retrieval for AzureRM resources
- AzAPI Schema: Schema lookup for Azure API resources
- Azure Verified Modules (AVM): Discovery and documentation for verified Terraform modules including module listings, versions, variables, and outputs
- Resource Documentation: Detailed arguments, attributes, and examples
- Security Scanning: Built-in security rule validation for Azure resources
- Azure Verified Modules (AVM) Policies: Integration with Conftest and Azure Policy Library AVM for comprehensive policy validation
- Best Practices: Azure-specific best practices and recommendations
- Unified Terraform Commands: Single tool to execute all Terraform commands (init, plan, apply, destroy, validate, fmt) plus full state management (list, show, mv, rm, pull, push)
- State Management: Safe resource renaming and state manipulation using proper Terraform commands
- HCL Validation: Syntax validation and error reporting for Terraform code
- HCL Formatting: Automatic code formatting for Terraform configurations
- TFLint Integration: Static analysis with TFLint including Azure ruleset support for Terraform workspaces
- Azure Export for Terraform (aztfexport): Export existing Azure resources to Terraform configuration and state
- Code Cleanup Workflow: Transform exported code into production-ready infrastructure as code
- Terraform Schema Query: Query fine-grained schema information for any Terraform provider
- Provider Item Discovery: List all available resources, data sources, and functions for providers
- Provider Support Discovery: Find which providers are available for analysis
- Dynamic Schema Loading: Support for all providers in the Terraform Registry
- Golang Namespace Discovery: Find available golang packages for source code analysis
- Version/Tag Support: Query specific versions of provider source code
- Source Code Retrieval: Read golang source code for functions, methods, types, and variables
- Terraform Implementation Analysis: Understand how Terraform resources are implemented in Go
- MCP Protocol: Full Model Context Protocol compliance for AI assistant integration
- FastMCP Framework: Built on FastMCP for high-performance async operations
Create or edit .vscode/mcp.json
in your workspace:
{
"servers": {
"tf-mcp-server": {
"command": "docker",
"args": [
"run",
"--rm",
"-i",
"--name", "tf-mcp-server-instance",
"-v", "${workspaceFolder}:/workspace",
"-e", "ARM_CLIENT_ID=${env:ARM_CLIENT_ID}",
"-e", "ARM_CLIENT_SECRET=${env:ARM_CLIENT_SECRET}",
"-e", "ARM_SUBSCRIPTION_ID=${env:ARM_SUBSCRIPTION_ID}",
"-e", "ARM_TENANT_ID=${env:ARM_TENANT_ID}",
"-e", "LOG_LEVEL=INFO",
"ghcr.io/liuwuliuyun/tf-mcp-server:latest"
],
"env": {
"ARM_CLIENT_ID": "${env:ARM_CLIENT_ID}",
"ARM_CLIENT_SECRET": "${env:ARM_CLIENT_SECRET}",
"ARM_SUBSCRIPTION_ID": "${env:ARM_SUBSCRIPTION_ID}",
"ARM_TENANT_ID": "${env:ARM_TENANT_ID}"
}
}
}
}
For detailed installation instructions including:
- π³ Docker with Azure authentication
- β‘ UV installation for development
- π Traditional Python setup
- π§ Optional tool installation
- βοΈ Configuration options
π See the complete Installation Guide
For detailed configuration options including environment variables, configuration files, and Azure authentication setup, see the Installation Guide.
The server provides comprehensive tools across multiple categories. For complete tool reference with examples, see the API Reference.
get_azurerm_provider_documentation
: Retrieve specific AzureRM resource or data source documentation with optional argument/attribute lookupget_azapi_provider_documentation
: Retrieve AzAPI resource schemas and documentationget_avm_modules
: Retrieve all available Azure Verified Modules with descriptions and source informationget_avm_latest_version
: Get the latest version of a specific Azure Verified Moduleget_avm_versions
: Get all available versions of a specific Azure Verified Moduleget_avm_variables
: Retrieve the input variables schema for a specific AVM module versionget_avm_outputs
: Retrieve the output definitions for a specific AVM module version
run_terraform_command
: Execute Terraform CLI commands (init, plan, apply, destroy, validate, fmt) and state management operations (list, show, mv, rm, pull, push) inside a workspace folder
check_conftest_installation
: Check Conftest installation status and get version informationrun_conftest_workspace_validation
: Validate Terraform files in a workspace folder against Azure security policiesrun_conftest_workspace_plan_validation
: Validate Terraform plan files against Azure security policiescheck_tflint_installation
: Check TFLint installation status and get version informationrun_tflint_workspace_analysis
: Run TFLint static analysis on workspace folders containing Terraform files
check_aztfexport_installation
: Check Azure Export for Terraform (aztfexport) installation status and versionexport_azure_resource
: Export a single Azure resource to Terraform configuration using aztfexportexport_azure_resource_group
: Export an entire Azure resource group and its resources to Terraform configurationexport_azure_resources_by_query
: Export Azure resources using Azure Resource Graph queries to Terraform configurationget_aztfexport_config
: Get aztfexport configuration settingsset_aztfexport_config
: Set aztfexport configuration settings
get_terraform_source_providers
: Get supported providers for source code analysisquery_terraform_source_code
: Read Terraform provider source code implementationsget_golang_namespaces
: Get available golang namespaces for analysisget_golang_namespace_tags
: Get supported version tags for a golang namespacequery_golang_source_code
: Read golang source code for functions, methods, types, and variables
get_azure_best_practices
: Get comprehensive Azure and Terraform best practices for specific resources and actions- Supports AzureRM 4.x and AzAPI 2.x recommendations
- Special "code-cleanup" action for aztfexport workflow
- Clear guidance on variables vs locals
- State management best practices
- Security hardening recommendations
For comprehensive guides and examples:
- π Documentation Index - Complete documentation overview
- π Installation Guide - Setup instructions for all platforms
- π§ Configuration Guide - Environment variables and settings
- π API Reference - Complete tool reference with examples
- β Troubleshooting - Common issues and solutions
- Azure Documentation Tools - AzureRM, AzAPI, and AVM documentation access
- Terraform Commands - Execute Terraform operations and state management
- Terraform State Management - Safe resource renaming and state operations
- Security Policies - Policy-based validation and compliance
- Azure Export Integration - Export existing Azure resources
- Source Code Analysis - Terraform and Golang code analysis
- Azure Best Practices - Get Azure-specific recommendations and code cleanup guidance
For complete examples and workflows, see the API Reference.
tf-mcp-server/
βββ src/ # Main source code
β βββ data/ # Data files and schemas
β β βββ azapi_schemas_v2.6.1.json # AzAPI resource schemas
β βββ tf_mcp_server/ # Core package
β βββ __init__.py
β βββ __main__.py # Package entry point
β βββ launcher.py # Server launcher
β βββ core/ # Core functionality
β β βββ __init__.py
β β βββ azapi_schema_generator.py # AzAPI schema generation
β β βββ config.py # Configuration management
β β βββ models.py # Data models and types
β β βββ server.py # FastMCP server with all MCP tools
β β βββ terraform_executor.py # Terraform execution utilities
β β βββ utils.py # Shared utility functions
β βββ tools/ # Tool implementations
β βββ __init__.py
β βββ avm_docs_provider.py # Azure Verified Modules provider
β βββ azapi_docs_provider.py # AzAPI documentation provider
β βββ azurerm_docs_provider.py # AzureRM documentation provider
β βββ aztfexport_runner.py # Azure Export for Terraform (aztfexport) integration
β βββ conftest_avm_runner.py # Conftest policy validation
β βββ terraform_runner.py # Terraform command execution
β βββ tflint_runner.py # TFLint static analysis
βββ tests/ # Test suite
β βββ __init__.py
β βββ conftest.py # Test configuration
β βββ test_*.py # Unit tests
β βββ integration/ # Integration tests
βββ tfsample/ # Sample Terraform configurations
βββ policy/ # Security and compliance policies
β βββ avmsec/ # Azure security policies
β βββ Azure-Proactive-Resiliency-Library-v2/ # Azure resiliency policies
β βββ common/ # Common policy utilities
βββ docs/ # Documentation
βββ examples/ # Usage examples
βββ pyproject.toml # Project configuration (UV/pip)
βββ uv.lock # UV dependency lockfile
βββ README.md # This file
βββ CONTRIBUTE.md # Development and contribution guide
For comprehensive troubleshooting including:
- Docker and VS Code MCP setup issues
- Azure authentication problems
- Tool installation and configuration
- Performance optimization
- Platform-specific solutions
π See the detailed Troubleshooting Guide
Enable debug logging:
{
"mcpServers": {
"tf-mcp-server": {
"command": "docker",
"args": [
"run", "--rm", "-i",
"-v", "${workspaceFolder}:/workspace",
"-e", "LOG_LEVEL=DEBUG",
"-e", "MCP_DEBUG=true",
"ghcr.io/liuwuliuyun/tf-mcp-server:latest"
]
}
}
}
Check logs for detailed information and error diagnosis.
We welcome contributions! For development setup, coding standards, and detailed contribution guidelines:
π See the complete Contributing Guide
- Fork the repository
- Set up development environment (see CONTRIBUTE.md)
- Create a feature branch:
git checkout -b feature/your-feature
- Make changes with tests
- Run tests and formatting:
pytest && black src/ tests/
- Submit a pull request
This project is licensed under the MIT License. See LICENSE file for details.
For issues and questions:
- Create an issue in the repository
- Check the troubleshooting section above
- Review existing documentation and tests