Are you the author? Sign in to claim
tf-dialect is a vibe coded MCP (Model Context Protocol) server that exposes your organization's Terraform style guide to
tf-dialect is an MCP (Model Context Protocol) server that exposes your organization's Terraform style guide to AI coding agents, ensuring they generate context-aware, organization-specific Infrastructure as Code instead of generic HCL.
Configure once, use with any MCP-capable coding agent (Claude Desktop, Cline, etc.).
# Clone the repository
git clone https://github.com/utpaljaynadiger/tf-dialect.git
cd tf-dialect
# Install dependencies
npm install
# Build the project
npm run build
# Create your style configuration
cp terraform-style.example.yaml terraform-style.yaml
# Edit terraform-style.yaml with your organization's standards
# Then configure in your MCP client (see "Running the Server" section)
AI coding assistants generate generic Terraform code that violates your org's standards. Your existing tools (tflint, Sentinel, module registries) are reactive—they catch violations after code is written. Developers waste cycles fixing preventable issues.
tf-dialect exposes your Terraform standards to AI agents via MCP before code generation. AI learns your naming conventions, required tags, approved modules, and security defaults, then generates compliant code on first try.
Without tf-dialect:
# AI generates generic code
resource "aws_s3_bucket" "logs" {
bucket = "my-logs-bucket"
}
# ❌ Wrong naming, missing tags, no encryption, not using approved module
# → 3 commits to fix tflint/Sentinel violations
With tf-dialect:
# AI calls get_style_guide() + list_examples() first
module "logs_bucket" {
source = "../modules/s3-bucket"
name = "acme-prod-logs"
kms_key_id = data.aws_kms_key.standard.arn
tags = {
CostCenter = "engineering"
Team = "platform"
Environment = "prod"
}
}
# ✅ Passes all checks on first commit
| Tool | Phase | Purpose |
|---|---|---|
| tf-dialect | Pre-generation | Teach AI your standards |
| Module Registry | Reference | Provide reusable modules |
| tflint/checkov | Post-generation | Static analysis |
| Sentinel/OPA | Runtime | Policy enforcement |
tf-dialect is complementary—it makes AI agents aware of your module registry and helps generate code that passes your existing validation tools.
npm install
npm run build
cp terraform-style.example.yaml terraform-style.yaml
terraform-style.yaml to match your organization's standards:modules:
pattern: "root + shared-modules"
shared_module_path: "modules/"
prefer_shared_modules: true
naming:
resource_format: "<project>-<env>-<component>-<extra?>"
variable_case: "snake_case"
output_case: "snake_case"
tagging:
required_tags:
- "environment"
- "owner"
- "cost_center"
defaults:
environment: "${var.environment}"
owner: "infra-team"
security_defaults:
s3_bucket:
block_public_acls: true
versioning: true
encryption: "aws:kms"
rds:
storage_encrypted: true
backup_retention_period: 7
examples:
s3_private_bucket: |
module "logs_bucket" {
source = "../modules/s3-bucket"
name = "${local.project}-${var.environment}-logs"
tags = local.default_tags
}
npm run mcp
Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
{
"mcpServers": {
"tf-dialect": {
"command": "node",
"args": ["/absolute/path/to/tf-dialect/dist/index.js"],
"env": {
"TERRAFORM_STYLE_PATH": "/absolute/path/to/your/terraform-style.yaml"
}
}
}
}
Or if terraform-style.yaml is in the same directory as the server:
{
"mcpServers": {
"tf-dialect": {
"command": "node",
"args": ["/absolute/path/to/tf-dialect/dist/index.js"]
}
}
}
Add to your MCP settings:
{
"mcpServers": {
"tf-dialect": {
"command": "node",
"args": ["/absolute/path/to/tf-dialect/dist/index.js"]
}
}
}
The server exposes four tools that AI agents can use:
get_style_guideGet the complete Terraform style guide configuration.
Input: None
Output:
{
"modules": { ... },
"naming": { ... },
"tagging": { ... },
"providers": { ... },
"security_defaults": { ... },
"examples": { ... }
}
Example agent prompt:
"Show me the Terraform style guide for this project"
list_examplesList code examples, optionally filtered by resource type or search term.
Input:
{
"resourceType": "s3_bucket", // optional
"search": "postgres" // optional
}
Output:
{
"examples": [
{
"name": "s3_private_bucket",
"code": "module \"logs_bucket\" { ... }"
}
]
}
Example agent prompts:
"Show me examples of S3 buckets" "List all RDS examples"
validate_snippetValidate Terraform code against the style guide.
Input:
{
"code": "resource \"aws_s3_bucket\" \"example\" { ... }",
"filePath": "main.tf" // optional
}
Output:
{
"valid": false,
"violations": [
{
"ruleId": "required_tag_missing",
"severity": "error",
"message": "Missing required tags: environment, owner",
"line": 5,
"suggestion": "Add the following tags: environment = \"...\", owner = \"...\""
}
]
}
Example agent prompts:
"Validate this Terraform code against our style guide" "Check if this S3 bucket configuration is compliant"
generate_resourceGenerate a Terraform resource following organization standards.
Input:
{
"resourceType": "aws_s3_bucket",
"env": "prod",
"service": "analytics",
"purpose": "logs", // optional
"extraTags": { // optional
"team": "data"
}
}
Output:
{
"code": "resource \"aws_s3_bucket\" \"this\" { ... }"
}
Supported resource types:
aws_s3_bucketaws_db_instanceExample agent prompts:
"Generate an S3 bucket for prod analytics logs" "Create an RDS instance for the staging API database"
tf-dialect enforces the following rules:
Ensures all resources include required tags defined in your config.
Blocks dangerous patterns like:
0.0.0.0/0 in security groupsEnforces security best practices:
S3 Buckets:
RDS Instances:
Validates resource names follow your format:
<project>-<env>-<component>-<extra?># Install dependencies
npm install
# Build
npm run build
# Watch mode
npm run dev
Agent asks about style:
get_style_guideAgent needs an example:
list_examples with resourceType: "rds"Agent generates code:
generate_resource or writes codevalidate_snippet to check complianceAgent fixes violations:
MIT
Contributions welcome! This is an OSS-friendly project designed for IaC power users.
Run Claude Code as an MCP server so any agent can delegate coding tasks to it
Browser automation using accessibility snapshots instead of screenshots
Google's universal MCP server supporting PostgreSQL, MySQL, MongoDB, Redis, and 10+ databases
Official GitHub integration for repos, issues, PRs, and CI/CD workflows