Token导航 LogoToken导航TokenDH.com
Terraform Best Practices MCP logo
安全风控未说明官方级别未说明来源级核验

Terraform Best Practices MCP

MCP Server

一个用于通过CLI分析(tflint、checkov、trivy、kics、infracost)、最佳实践指导和云提供商建议来提升Terraform代码质量的MCP服务器。

工具数

18

提示词数

0

GitHub Stars

1

资源数

0
基础设施即代码安全TypeScriptVS CodeVS Code

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

DownAtTheBottomOfTheMoleHole

提供方

DownAtTheBottomOfTheMoleHole

最后核验

2026/5/17 20:22

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

详细介绍

Terraform最佳实践MCP服务器

Down At The Bottom Of The Mole Hole banner

![CI/Publish](https://github.com/DownAtTheBottomOfTheMoleHole/terraform-best-practices-mcp/actions/workflows/publish-mcp.yml) ![Coverage](https://codecov.io/github/DownAtTheBottomOfTheMoleHole/terraform-best-practices-mcp) ](https://registry.npmjs.org/@downatthebottomofthemolehole/terraform-best-practices-mcp-server) ![License: MIT](./LICENSE) ](https://nodejs.org/)

注: 这是一个由社区维护的MCP服务器。它不是HashiCorp或任何云提供商的官方模型上下文协议服务器。

通过CLI分析生成更好地形的模型上下文协议(MCP)服务器(tflint, checkov, trivy, kics, infracost),最佳实践指导来自 terraform-best-practices.com云提供商建议(Azure、AWS、GCP)以及Terraform注册表资源和模块指南。

概述

此服务器在CLI分析、最佳实践检索和交互式报告工作流中提供了18个MCP工具:

  • run_tflint 到lint Terraform代码。
  • run_checkov 运行安全性和合规性扫描。
  • run_trivy 扫描Terraform配置以查找漏洞。
  • run_kics 运行IaC安全和合规扫描。
  • run_infracost 以估算云成本。
  • fetch_terraform_best_practices 检索精心策划的Terraform最佳实践。
  • fetch_provider_best_practices 检索云提供商Terraform指南。
  • fetch_terraform_registry_guidance 检索Terraform注册表资源和模块指南。
  • analyze_terraform_code 分析代码结构、模块化和最佳实践。
  • analyze_terraform_performance 以识别运行时和性能瓶颈。
  • analyze_state_management 评估后端状态策略和协作安全。
  • generate_cost_report 生成具有优化建议的成本分析。
  • generate_terraform_module_docs 从Terraform代码生成模块文档。
  • recommend_terraform_modules 从检测到的模式中推荐可重用的模块。
  • suggest_terraform_architecture 提出多环境、多区域格局。
  • suggest_terraform_testing_strategy 建议根据风险状况进行CI驱动测试。
  • suggest_security_hardening 提供安全强化建议。
  • generate_compliance_summary 根据扫描输出创建合规性报告。

平台兼容性

此MCP服务器与平台无关,可在本地和CI环境中工作:

  • 本地开发
  • GitHub操作
  • GitLab CI/CD
  • Azure DevOps
  • CircleCI、Jenkins和Bitbucket管道
  • AI代理和Copilot工作流程

主要要求是Node.js和可选的CLI工具 PATH。如果缺少CLI,服务器将返回安装指南,而不是自动失败。

工具矩阵

工具类别典型结果
run_tflintCLI分析Terraform代码的Lint发现
run_checkovCLI分析安全性和合规性扫描结果
run_trivyCLI分析IaC漏洞扫描结果
run_kicsCLI分析IaC安全发现
run_infracostCLI分析当前IaC的月度成本基线
fetch_terraform_best_practices指导来自terraform-best-practices.com的精选最佳实践清单
fetch_provider_best_practices指导云提供商(Azure/AWS/GCP)平台建议
fetch_terraform_registry_guidance指南针对提供者、资源和模块的注册表指南
analyze_terraform_code分析代码结构和模块化评估
analyze_terraform_performance分析性能瓶颈和优化报告
analyze_state_management分析状态后端策略和协作安全审查
generate_cost_report报告成本分析及优化建议
generate_terraform_module_docs报告生成的模块文档标记
recommend_terraform_modules报告来自代码模式的可重用模块建议
suggest_terraform_architecture架构多环境、多区域架构模式
suggest_terraform_testing_strategy测试基于风险状况的CI驱动测试策略
suggest_security_hardening安全性扫描输出的安全强化建议
generate_compliance_summary合规性扫描输出的合规性报告

工具

run_tflint

对Terraform项目目录运行tflint。

输入:

  • path (字符串,可选):要扫描的地形项目路径。违约: ..
  • extraArgs (string\[\],可选):额外的CLI参数。
  • timeoutMs (整数,可选):命令超时时间(毫秒)。

run_checkov

在Terraform目录上运行checkov。

输入:

  • path (字符串,可选):要扫描的地形项目路径。违约: ..
  • extraArgs (string\[\],可选):额外的CLI参数。
  • timeoutMs (整数,可选):命令超时时间(毫秒)。

run_trivy

对Terraform代码运行trivy配置扫描。

输入:

  • path (字符串,可选):要扫描的地形项目路径。违约: ..
  • extraArgs (string\[\],可选):额外的CLI参数。
  • timeoutMs (整数,可选):命令超时时间(毫秒)。

run_kics

对Terraform代码运行kics-IaC扫描。

输入:

  • path (字符串,可选):要扫描的地形项目路径。违约: ..
  • extraArgs (string\[\],可选):额外的CLI参数。
  • timeoutMs (整数,可选):命令超时时间(毫秒)。

run_infracost

运行Terraform目录的基础设施成本明细。

输入:

  • path (字符串,可选):要扫描的地形项目路径。违约: ..
  • extraArgs (string\[\],可选):额外的CLI参数。
  • timeoutMs (整数,可选):命令超时时间(毫秒)。

fetch_terraform_best_practices

从精心策划的检查中获取Terraform最佳实践指南,并从Terraform-best-practices.com获取可选的实时摘要。

输入:

  • topic (字符串,可选):主题过滤器,如状态、模块、安全性或命名。
  • liveFetch (布尔值,可选):当为true时,获取并总结实时内容。违约: true.

fetch_provider_best_practices

从精心策划的检查和可选的实时提供商文档摘要中获取Azure、AWS或GCP的Terraform最佳实践指南。

输入:

  • provider (string,必填):云提供商(azure, aws,或 gcp).
  • topic (字符串,可选):关注领域,如状态、IAM、模块、网络或成本。
  • liveFetch (布尔值,可选):当为true时,获取并总结链接的提供者指南页面。违约: true.

fetch_terraform_registry_guidance

获取提供程序、资源和模块的Terraform注册表指南。

输入:

  • provider (字符串,可选):提供者名称(例如。 aws, azurerm, google).
  • resource (字符串,可选):与提供者一起使用的资源类型(例如。 s3_bucket, resource_group).
  • module (字符串,可选):表单中的模块路径 namespace/name/provider.
  • topic (字符串,可选):摘要输出的主题过滤器。
  • liveFetch (布尔值,可选):当为true时,获取并汇总选定的注册表页面。违约: true.

analyze_terraform_code

分析Terraform代码结构、模块化和最佳实践。

输入:

  • code (字符串,必填):要分析的地形代码片段(最多50000个字符)。
  • focusArea (字符串,可选):分析重点区域(modularity, variables, outputs, locals, general).违约: general.

analyze_terraform_performance

分析Terraform运行时和性能瓶颈以及优化机会。

输入:

  • terraformCode (字符串,必填):用于以性能为中心的启发式算法的Terraform代码。
  • stateSizeMb (数字,可选):说明规模感知建议的大小(MB)。
  • workspaceCount (整数,可选):共享同一根堆栈的工作区数量。
  • providerRateLimitSensitive (布尔值,可选):如果为true,则强调提供程序API节流保护。违约: true.

analyze_state_management

评估后端状态策略和协作安全。

输入:

  • terraformCode (字符串,必填):地形代码,包括后端和状态相关配置。
  • teamSize (整数,可选):应用Terraform更改的工程师数量。违约: 6.
  • environmentCount (整数,可选):房地产管理的环境数量。违约: 2.
  • currentBackend (字符串,可选):表示后端正在使用中(auto, s3, azurerm, gcs, remote, local, unknown).违约: auto.
  • useWorkspaces (布尔值,可选):是否通过工作区管理多个环境。违约: false.

generate_cost_report

根据基础设施成本输出的优化建议生成成本分析。

输入:

  • infracostJson (字符串,必填):来自infrascost分解或diff命令的JSON输出。
  • includeOptimizations (布尔值,可选):为真时,生成成本优化建议。违约: true.

generate_terraform_module_docs

从Terraform代码生成模块文档标记。

输入:

  • terraformCode (字符串,必填):要记录的Terraform模块代码。
  • moduleName (字符串,可选):在生成的markdown文档中使用的友好名称。违约: terraform-module.
  • includeUsageExample (布尔值,可选):包含用法示例部分。违约: true.
  • includeInputsOutputsTables (布尔值,可选):将输入和输出渲染为markdown表。违约: true.

recommend_terraform_modules

根据检测到的代码模式推荐可重用的Terraform模块。

输入:

  • terraformCode (字符串,必填):用于推断模块建议的地形代码。
  • provider (字符串,可选):首选云提供商(aws, azure, gcp, any).违约: any.
  • deploymentIntent (字符串,可选):主要部署目标(networking, kubernetes, serverless, storage, database, observability, security, general).违约: general.
  • maxRecommendations (整数,可选):要返回的最大建议值(1--10)。违约: 5.

suggest_terraform_architecture

为多环境、多区域的庄园提出建筑模式建议。

输入:

  • workloadType (字符串,可选):主要工作负载配置文件(web-api, data-platform, event-driven, platform-foundation, general).违约: general.
  • environments (string\[\],可选):目标环境(dev, test, stage, prod, sandbox, dr).违约: ["dev", "prod"].
  • multiRegion (布尔值,可选):工作负载是否跨多个区域运行。违约: false.
  • complianceProfile (字符串,可选):合规性配置文件(none, cis, pci-dss, hipaa, sox).违约: none.
  • teamSize (整数,可选):操作Terraform代码的工程师人数。违约: 6.
  • currentPainPoints (字符串,可选):当前架构中的痛点或约束。
  • includeReferenceLayout (布尔值,可选):包括建议的存储库和文件夹布局。违约: true.

suggest_terraform_testing_strategy

根据风险状况推荐CI驱动的Terraform测试策略。

输入:

  • terraformCode (字符串,可选):用于复杂性感知建议的Terraform代码。
  • deploymentCriticality (字符串,可选):业务影响级别(low, medium, high, mission-critical).违约: medium.
  • changeFrequency (字符串,可选):引入基础设施更改的频率(low, medium, high).违约: medium.
  • ciSystem (字符串,可选):目标CI系统(github-actions, azure-devops, gitlab, circleci, jenkins, other).违约: github-actions.
  • includeExamplePipeline (布尔值,可选):包含一个示例管道序列。违约: true.

suggest_security_hardening

从扫描输出中提供安全强化建议。

输入:

  • scanOutput (string,必填):安全扫描工具(checkov、trivy或kics)的输出。
  • scanTool (字符串,可选):扫描工具的名称(checkov, trivy, kics).违约: checkov.

generate_compliance_summary

根据扫描输出创建合规性报告。

输入:

  • checkovOutput (字符串,可选):checkov扫描的输出。
  • trivyOutput (字符串,可选):trivy扫描的输出。
  • kicsOutput (字符串,可选):kics扫描的输出。
  • complianceFramework (字符串,可选):用于评估的合规框架(cis, pci-dss, hipaa, sox, general).违约: general.

提示食谱

在Copilot Chat中使用这些最小提示 @tf-best-practices.CLI工具在没有时默认为当前工作区根目录 path 提供。添加 #file#folder 上下文可以提高聊天理解, path).

快速入门(零参数提示)

@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分析

@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 .

最佳实践和指导

@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

代码分析

@tf-best-practices run analyze_terraform_code with code 
 and focusArea modularity
@tf-best-practices run analyze_terraform_performance with terraformCode 

@tf-best-practices run analyze_state_management with terraformCode 

报告和建议

@tf-best-practices run generate_cost_report with infracostJson 

@tf-best-practices run generate_terraform_module_docs with terraformCode 

@tf-best-practices run recommend_terraform_modules with terraformCode 
 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 
 and scanTool checkov
@tf-best-practices run generate_compliance_summary with complianceFramework cis

依赖项

系统依赖

  • Node.js >=24.14.0
  • npm(与Node.js捆绑在一起)
  • 可选CLIs可在 PATH 对于命令工具:

- tflint - checkov - trivy - kics - infracost

如果缺少CLI,服务器将返回安装指南,而不是自动失败。

npm依赖关系

运行时间:

  • @modelcontextprotocol/sdk (MCP服务器SDK)
  • zod (输入模式验证)

发展:

  • typescript (构建/编译)
  • tsx (开发负责人)
  • vitest (机组试验转轮)
  • @types/node (Node.js类型)

环境变量

  • INFRACOST_API_KEY:用于云支持成本估计的Infracost API密钥。

安装

npm install
npm run build

配置

使用VS Code Copilot聊天

此工作区已在中预配置 .vscode/mcp.json:

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

重新加载VS代码(Cmd+Shift+P -> Developer: Reload Window)在更改MCP配置后。

然后通过Copilot Chat查询服务器 @tf-best-practices例如:

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

与其他MCP客户端一起使用

使用内置入口点的stdio传输:

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

先构建 npm run build,然后启动MCP客户端。

跑步

npm start

开发模式:

npm run dev

调试

使用 .vscode/launch.json:

  • Debug MCP Server (跑步 npm run dev)
  • Debug MCP Server (Built) (跑步 dist/index.js 建成后)

在中设置断点 src/index.ts,然后按 F5.

测试

docs/TEST.md 用于Copilot聊天场景、手动JSON-RPC检查和故障排除指导。

Copilot聊天中的快速验证提示:

@tf-best-practices run run_tflint

交互式VS代码工作流

1.安全分类

  1. 运行扫描:
@tf-best-practices run run_checkov
  1. 请求强化建议:
@tf-best-practices run suggest_security_hardening with scanOutput 
 and scanTool checkov
  1. 生成合规性摘要:
@tf-best-practices run generate_compliance_summary with checkovOutput 
 and complianceFramework cis

2.成本影响审查

  1. 生成成本基线:
@tf-best-practices run run_infracost
  1. 制作成本报告:
@tf-best-practices run generate_cost_report with infracostJson 

3.架构审查

  1. 分析代码质量:
@tf-best-practices run analyze_terraform_code with code 
 and focusArea modularity
  1. 审查状态管理:
@tf-best-practices run analyze_state_management with terraformCode 
  1. 获取架构建议:
@tf-best-practices run suggest_terraform_architecture with workloadType web-api and multiRegion true

最佳实践

  • 在使用指导工具之前,先从CLI分析工具开始建立基线。
  • 使用 fetch_terraform_best_practices 与社区惯例保持一致。
  • 使用 fetch_provider_best_practices 针对特定于提供商的模式。
  • 保持 timeoutMs 足够用于大型Terraform项目。
  • suggest_terraform_testing_strategy 在引入新的CI/CD管道时。
  • 使用 generate_compliance_summary 定期检查审计准备情况。

其他用例

  • 在pull请求中预合并安全和合规门。
  • 自动化基础设施变更的成本影响审查。
  • 绿地项目的建筑模式建议。
  • 为共享的Terraform模块生成模块文档。
  • 根据部署风险状况定义CI驱动的测试策略。
  • 为审计跟踪生成合规性证据。

相关项目

地形资源

模型上下文协议

社区与贡献

归属和许可

由卡尔·道森维护 在鼹鼠洞的底部 组织。

发展

npm run lint
npm test
npm run build

许可证

根据MIT许可证获得许可。

目录标签

目录标签

基础设施即代码安全TypeScriptVS Code本地部署Terraform代码分析安全扫描成本估算

支持客户端

VS Code

接入字段

传输方式(transport,传输协议)

未说明

鉴权方式(authType,认证方式)

none

工具数量(toolCount,工具数)

18

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

未说明none部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

仍需确认:installCommand

来源信息

继续浏览同类 MCP