@downatthebottomofthemolehole/terraform-best-practices-mcp-server

中文文档
5.2.56发布于 2026/11/01MITTypeScriptES Module构建来源已验证

MCP server for Terraform cost, lint, security, and cloud best-practice guidance.

原始使用文档
文档目录52 节
  1. Overview
  2. Platform Compatibility
  3. Tool Matrix
  4. Tools
  5. run_tflint
  6. run_checkov
  7. run_trivy
  8. run_kics
  9. run_infracost
  10. fetch_terraform_best_practices
  11. fetch_provider_best_practices
  12. fetch_terraform_registry_guidance
  13. analyze_terraform_code
  14. analyze_terraform_performance
  15. analyze_state_management
  16. generate_cost_report
  17. generate_terraform_module_docs
  18. recommend_terraform_modules
  19. suggest_terraform_architecture
  20. suggest_terraform_testing_strategy
  21. suggest_security_hardening
  22. generate_compliance_summary
  23. Prompt Cookbook
  24. Quick Start (Zero-Argument Prompts)
  25. CLI Analysis
  26. Best Practices and Guidance
  27. Code Analysis
  28. Reporting and Recommendations
  29. Dependencies
  30. System Dependencies
  31. npm Dependencies
  32. Environment Variables
  33. Installation
  34. Configuration
  35. Usage with VS Code Copilot Chat
  36. Usage with Other MCP Clients
  37. Running
  38. Debugging
  39. Testing
  40. Interactive VS Code Workflows
  41. 1. Security Triage
  42. 2. Cost Impact Review
  43. 3. Architecture Review
  44. Best Practices
  45. Additional Use Cases
  46. Related Projects
  47. Terraform Resources
  48. Model Context Protocol
  49. Community and Contributing
  50. Attribution and License
  51. Development
  52. License

Terraform Best Practices MCP Server

Down At The Bottom Of The Mole Hole banner

CI/Publish Coverage npm License: MIT Node Version

Note: This is a community-maintained MCP server. It is not an official Model Context Protocol server from HashiCorp or any cloud provider.

A Model Context Protocol (MCP) server for producing better Terraform through CLI analysis (tflint, checkov, trivy, kics, infracost), best-practice guidance from terraform-best-practices.com, cloud provider recommendations (Azure, AWS, GCP), and Terraform Registry resource and module guidance.

Overview

This server provides eighteen MCP tools across CLI analysis, best-practice retrieval, and interactive reporting workflows:

  • run_tflint to lint Terraform code.
  • run_checkov to run security and compliance scanning.
  • run_trivy to scan Terraform configuration for vulnerabilities.
  • run_kics to run IaC security and compliance scanning.
  • run_infracost to estimate cloud costs.
  • fetch_terraform_best_practices to retrieve curated Terraform best practices.
  • fetch_provider_best_practices to retrieve cloud provider Terraform guidance.
  • fetch_terraform_registry_guidance to retrieve Terraform Registry resource and module guidance.
  • analyze_terraform_code to analyze code structure, modularity, and best practices.
  • analyze_terraform_performance to identify runtime and performance bottlenecks.
  • analyze_state_management to assess backend state strategy and collaboration safety.
  • generate_cost_report to generate cost analysis with optimization suggestions.
  • generate_terraform_module_docs to produce module documentation from Terraform code.
  • recommend_terraform_modules to recommend reusable modules from detected patterns.
  • suggest_terraform_architecture to suggest multi-environment and multi-region patterns.
  • suggest_terraform_testing_strategy to recommend CI-driven testing by risk profile.
  • suggest_security_hardening to provide security hardening recommendations.
  • generate_compliance_summary to create compliance reports from scan outputs.

Platform Compatibility

This MCP server is platform-agnostic and works in local and CI environments:

  • Local development
  • GitHub Actions
  • GitLab CI/CD
  • Azure DevOps
  • CircleCI, Jenkins, and Bitbucket Pipelines
  • AI Agents and Copilot workflows

The primary requirements are Node.js and optionally the CLI tools on PATH. If a CLI is missing, the server returns installation guidance instead of failing silently.

Tool Matrix

ToolCategoryTypical outcome
run_tflintCLI AnalysisLint findings for Terraform code
run_checkovCLI AnalysisSecurity and compliance scan results
run_trivyCLI AnalysisVulnerability scan results for IaC
run_kicsCLI AnalysisIaC security findings
run_infracostCLI AnalysisMonthly cost baseline for current IaC
fetch_terraform_best_practicesGuidanceCurated best-practice checklist from terraform-best-practices.com
fetch_provider_best_practicesGuidanceCloud provider (Azure/AWS/GCP) Terraform recommendations
fetch_terraform_registry_guidanceGuidanceRegistry guidance for providers, resources, and modules
analyze_terraform_codeAnalysisCode structure and modularity assessment
analyze_terraform_performanceAnalysisPerformance bottleneck and optimization report
analyze_state_managementAnalysisState backend strategy and collaboration safety review
generate_cost_reportReportingCost analysis with optimization suggestions
generate_terraform_module_docsReportingGenerated module documentation markdown
recommend_terraform_modulesReportingReusable module recommendations from code patterns
suggest_terraform_architectureArchitectureMulti-environment and multi-region architecture patterns
suggest_terraform_testing_strategyTestingCI-driven testing strategy by risk profile
suggest_security_hardeningSecuritySecurity hardening recommendations from scan output
generate_compliance_summaryComplianceCompliance report from scan outputs

Tools

run_tflint

Run tflint against a Terraform project directory.

Inputs:

  • path (string, optional): Terraform project path to scan. Default: ..
  • extraArgs (string[], optional): Extra CLI arguments.
  • timeoutMs (integer, optional): Command timeout in milliseconds.

run_checkov

Run checkov over a Terraform directory.

Inputs:

  • path (string, optional): Terraform project path to scan. Default: ..
  • extraArgs (string[], optional): Extra CLI arguments.
  • timeoutMs (integer, optional): Command timeout in milliseconds.

run_trivy

Run trivy config scanning against Terraform code.

Inputs:

  • path (string, optional): Terraform project path to scan. Default: ..
  • extraArgs (string[], optional): Extra CLI arguments.
  • timeoutMs (integer, optional): Command timeout in milliseconds.

run_kics

Run kics IaC scanning against Terraform code.

Inputs:

  • path (string, optional): Terraform project path to scan. Default: ..
  • extraArgs (string[], optional): Extra CLI arguments.
  • timeoutMs (integer, optional): Command timeout in milliseconds.

run_infracost

Run infracost breakdown for a Terraform directory.

Inputs:

  • path (string, optional): Terraform project path to scan. Default: ..
  • extraArgs (string[], optional): Extra CLI arguments.
  • timeoutMs (integer, optional): Command timeout in milliseconds.

fetch_terraform_best_practices

Fetch Terraform best-practice guidance from curated checks and optional live summaries from terraform-best-practices.com.

Inputs:

  • topic (string, optional): Topic filter such as state, modules, security, or naming.
  • liveFetch (boolean, optional): When true, fetches and summarises live content. Default: true.

fetch_provider_best_practices

Fetch Terraform best-practice guidance for Azure, AWS, or GCP from curated checks and optional live provider docs summaries.

Inputs:

  • provider (string, required): Cloud provider (azure, aws, or gcp).
  • topic (string, optional): Focus area such as state, IAM, modules, networking, or cost.
  • liveFetch (boolean, optional): When true, fetches and summarises the linked provider guidance page. Default: true.

fetch_terraform_registry_guidance

Fetch Terraform Registry guidance for providers, resources, and modules.

Inputs:

  • provider (string, optional): Provider name (e.g. aws, azurerm, google).
  • resource (string, optional): Resource type used with provider (e.g. s3_bucket, resource_group).
  • module (string, optional): Module path in the form namespace/name/provider.
  • topic (string, optional): Topic filter for the summary output.
  • liveFetch (boolean, optional): When true, fetches and summarises selected Registry pages. Default: true.

analyze_terraform_code

Analyze Terraform code structure, modularity, and best practices.

Inputs:

  • code (string, required): Terraform code snippet to analyze (max 50,000 chars).
  • focusArea (string, optional): Analysis focus area (modularity, variables, outputs, locals, general). Default: general.

analyze_terraform_performance

Analyze Terraform runtime and performance bottlenecks and optimization opportunities.

Inputs:

  • terraformCode (string, required): Terraform code for performance-focused heuristics.
  • stateSizeMb (number, optional): State size in MB for scale-aware recommendations.
  • workspaceCount (integer, optional): Number of workspaces sharing the same root stack.
  • providerRateLimitSensitive (boolean, optional): When true, emphasise provider API throttling protections. Default: true.

analyze_state_management

Assess backend state strategy and collaboration safety.

Inputs:

  • terraformCode (string, required): Terraform code including backend and state-related configuration.
  • teamSize (integer, optional): Number of engineers applying Terraform changes. Default: 6.
  • environmentCount (integer, optional): Number of environments managed by the estate. Default: 2.
  • currentBackend (string, optional): State backend in use (auto, s3, azurerm, gcs, remote, local, unknown). Default: auto.
  • useWorkspaces (boolean, optional): Whether multiple environments are managed through workspaces. Default: false.

generate_cost_report

Generate cost analysis with optimization suggestions from Infracost output.

Inputs:

  • infracostJson (string, required): JSON output from infracost breakdown or diff command.
  • includeOptimizations (boolean, optional): When true, generates cost optimization suggestions. Default: true.

generate_terraform_module_docs

Generate module documentation markdown from Terraform code.

Inputs:

  • terraformCode (string, required): Terraform module code to document.
  • moduleName (string, optional): Friendly name used in generated markdown docs. Default: terraform-module.
  • includeUsageExample (boolean, optional): Include a usage example section. Default: true.
  • includeInputsOutputsTables (boolean, optional): Render inputs and outputs as markdown tables. Default: true.

recommend_terraform_modules

Recommend reusable Terraform modules from detected code patterns.

Inputs:

  • terraformCode (string, required): Terraform code used to infer module recommendations.
  • provider (string, optional): Preferred cloud provider (aws, azure, gcp, any). Default: any.
  • deploymentIntent (string, optional): Primary deployment goal (networking, kubernetes, serverless, storage, database, observability, security, general). Default: general.
  • maxRecommendations (integer, optional): Maximum recommendations to return (1--10). Default: 5.

suggest_terraform_architecture

Suggest architecture patterns for multi-environment and multi-region estates.

Inputs:

  • workloadType (string, optional): Primary workload profile (web-api, data-platform, event-driven, platform-foundation, general). Default: general.
  • environments (string[], optional): Target environments (dev, test, stage, prod, sandbox, dr). Default: ["dev", "prod"].
  • multiRegion (boolean, optional): Whether workloads run across multiple regions. Default: false.
  • complianceProfile (string, optional): Compliance profile (none, cis, pci-dss, hipaa, sox). Default: none.
  • teamSize (integer, optional): Number of engineers operating Terraform code. Default: 6.
  • currentPainPoints (string, optional): Pain points or constraints in the current architecture.
  • includeReferenceLayout (boolean, optional): Include a suggested repository and folder layout. Default: true.

suggest_terraform_testing_strategy

Recommend CI-driven Terraform testing strategy by risk profile.

Inputs:

  • terraformCode (string, optional): Terraform code for complexity-aware recommendations.
  • deploymentCriticality (string, optional): Business impact level (low, medium, high, mission-critical). Default: medium.
  • changeFrequency (string, optional): How often infrastructure changes are introduced (low, medium, high). Default: medium.
  • ciSystem (string, optional): Target CI system (github-actions, azure-devops, gitlab, circleci, jenkins, other). Default: github-actions.
  • includeExamplePipeline (boolean, optional): Include an example pipeline sequence. Default: true.

suggest_security_hardening

Provide security hardening recommendations from scan output.

Inputs:

  • scanOutput (string, required): Output from a security scanning tool (checkov, trivy, or kics).
  • scanTool (string, optional): Name of the scanning tool (checkov, trivy, kics). Default: checkov.

generate_compliance_summary

Create compliance reports from scan outputs.

Inputs:

  • checkovOutput (string, optional): Output from checkov scan.
  • trivyOutput (string, optional): Output from trivy scan.
  • kicsOutput (string, optional): Output from kics scan.
  • complianceFramework (string, optional): Compliance framework to assess against (cis, pci-dss, hipaa, sox, general). Default: general.

Prompt Cookbook

Use these minimal prompts in Copilot Chat with @tf-best-practices. CLI tools default to the current workspace root when no path is provided. Adding #file or #folder context can improve chat understanding, but tool execution path is controlled by explicit tool inputs (for example, path).

Quick Start (Zero-Argument Prompts)

@tf-best-practices run run_tflint
@tf-best-practices run run_checkov
@tf-best-practices run run_trivy
@tf-best-practices run run_kics
@tf-best-practices run run_infracost
@tf-best-practices run fetch_terraform_best_practices

CLI Analysis

@tf-best-practices run run_tflint with path ./modules/network
@tf-best-practices run run_checkov with path ./environments/prod
@tf-best-practices run run_trivy with path .
@tf-best-practices run run_kics with path .
@tf-best-practices run run_infracost with path .

Best Practices and Guidance

@tf-best-practices run fetch_terraform_best_practices with topic modules
@tf-best-practices run fetch_provider_best_practices with provider azure
@tf-best-practices run fetch_terraform_registry_guidance with provider azurerm and resource resource_group

Code Analysis

@tf-best-practices run analyze_terraform_code with code <paste code> and focusArea modularity
@tf-best-practices run analyze_terraform_performance with terraformCode <paste code>
@tf-best-practices run analyze_state_management with terraformCode <paste code>

Reporting and Recommendations

@tf-best-practices run generate_cost_report with infracostJson <paste json>
@tf-best-practices run generate_terraform_module_docs with terraformCode <paste code>
@tf-best-practices run recommend_terraform_modules with terraformCode <paste code> and provider azure
@tf-best-practices run suggest_terraform_architecture with workloadType web-api and environments ["dev","stage","prod"]
@tf-best-practices run suggest_terraform_testing_strategy with ciSystem github-actions
@tf-best-practices run suggest_security_hardening with scanOutput <paste output> and scanTool checkov
@tf-best-practices run generate_compliance_summary with complianceFramework cis

Dependencies

System Dependencies

  • Node.js >=24.14.0
  • npm (bundled with Node.js)
  • Optional CLIs available on PATH for command tools:
    • tflint
    • checkov
    • trivy
    • kics
    • infracost

If a CLI is missing, the server returns installation guidance instead of failing silently.

npm Dependencies

Runtime:

  • @modelcontextprotocol/sdk (MCP server SDK)
  • zod (input schema validation)

Development:

  • typescript (build/compile)
  • tsx (development runner)
  • vitest (unit test runner)
  • @types/node (Node.js typings)

Environment Variables

  • INFRACOST_API_KEY: Infracost API key for cloud-backed cost estimates.

Installation

npm install
npm run build

Configuration

Usage with VS Code Copilot Chat

This workspace is preconfigured in .vscode/mcp.json:

{
  "servers": {
    "tf-best-practices": {
      "type": "stdio",
      "command": "npm",
      "args": ["run", "dev"]
    }
  }
}

Reload VS Code (Cmd+Shift+P -> Developer: Reload Window) after changing MCP configuration.

Then query the server from Copilot Chat with @tf-best-practices, for example:

@tf-best-practices run run_tflint
@tf-best-practices run fetch_terraform_best_practices with topic modules

Usage with Other MCP Clients

Use stdio transport with the built entrypoint:

{
  "name": "terraform-best-practices-mcp-server",
  "type": "stdio",
  "command": "node",
  "args": ["/absolute/path/to/terraform-best-practices-mcp/dist/index.js"]
}

Build first with npm run build, then start your MCP client.

Running

npm start

Development mode:

npm run dev

Debugging

Use .vscode/launch.json:

  • Debug MCP Server (runs npm run dev)
  • Debug MCP Server (Built) (runs dist/index.js after build)

Set breakpoints in src/index.ts, then press F5.

Testing

See docs/TESTING.md for Copilot Chat scenarios, manual JSON-RPC checks, and troubleshooting guidance.

Quick validation prompt in Copilot Chat:

@tf-best-practices run run_tflint

Interactive VS Code Workflows

1. Security Triage

  1. Run a scan:
@tf-best-practices run run_checkov
  1. Request hardening suggestions:
@tf-best-practices run suggest_security_hardening with scanOutput <paste checkov output> and scanTool checkov
  1. Generate a compliance summary:
@tf-best-practices run generate_compliance_summary with checkovOutput <paste output> and complianceFramework cis

2. Cost Impact Review

  1. Generate a cost baseline:
@tf-best-practices run run_infracost
  1. Produce a cost report:
@tf-best-practices run generate_cost_report with infracostJson <paste json>

3. Architecture Review

  1. Analyse code quality:
@tf-best-practices run analyze_terraform_code with code <paste code> and focusArea modularity
  1. Review state management:
@tf-best-practices run analyze_state_management with terraformCode <paste code>
  1. Get architecture recommendations:
@tf-best-practices run suggest_terraform_architecture with workloadType web-api and multiRegion true

Best Practices

  • Start with CLI analysis tools to establish a baseline before using guidance tools.
  • Use fetch_terraform_best_practices to align with community conventions.
  • Use fetch_provider_best_practices for provider-specific patterns.
  • Keep timeoutMs high enough for large Terraform projects.
  • Run suggest_terraform_testing_strategy when onboarding new CI/CD pipelines.
  • Use generate_compliance_summary regularly for audit readiness.

Additional Use Cases

  • Pre-merge security and compliance gates in pull requests.
  • Automated cost impact reviews for infrastructure changes.
  • Architecture pattern recommendations for greenfield projects.
  • Module documentation generation for shared Terraform modules.
  • CI-driven testing strategy definition by deployment risk profile.
  • Compliance evidence generation for audit trails.

Terraform Resources

Model Context Protocol

Community and Contributing

Attribution and License

Maintained by Carl Dawson under the Down At The Bottom Of The Mole Hole organization.

Development

npm run lint
npm test
npm run build

License

Licensed under the MIT License.

版本与发布记录

@downatthebottomofthemolehole/terraform-best-practices-mcp-server 共发布 61 个版本,首次发布于 2026/03/07;过去 12 个月发布了 61 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
5.2.56latest2026/11/012 天前
5.2.552026/10/295 天前
5.2.522026/10/2212 天前
5.2.532026/10/2212 天前
5.2.512026/10/1816 天前
5.2.502026/10/1816 天前

关于 @downatthebottomofthemolehole/terraform-best-practices-mcp-server 的常见问题

@downatthebottomofthemolehole/terraform-best-practices-mcp-server 是什么?

用于Terraform成本、lint、安全性和云最佳实践指导的MCP服务器。

如何安装 @downatthebottomofthemolehole/terraform-best-practices-mcp-server?

在项目目录运行 npm install @downatthebottomofthemolehole/terraform-best-practices-mcp-server,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 terraform-best-practices-mcp-server,可以用 npx terraform-best-practices-mcp-server 直接运行。

@downatthebottomofthemolehole/terraform-best-practices-mcp-server 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@downatthebottomofthemolehole/terraform-best-practices-mcp-server 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@downatthebottomofthemolehole/terraform-best-practices-mcp-server 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=26.13.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@downatthebottomofthemolehole/terraform-best-practices-mcp-server 可以商用吗?

@downatthebottomofthemolehole/terraform-best-practices-mcp-server 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@downatthebottomofthemolehole/terraform-best-practices-mcp-server 还在维护吗?

最新版本 5.2.56 发布于 2026/11/01(2 天前);至今共发布 61 个版本,其中过去 12 个月发布了 61 个;首次发布于 2026/03/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。