mcp tfstate阅读器
](https://pypi.org/project/mcp-tfstate-reader/) ](https://pypi.org/project/mcp-tfstate-reader/)  
本地人 模型上下文协议(MCP)服务器 解析Terraform .tfstate 文件,让人工智能代理审计企业基础设施的安全配置错误,而不需要直接的云凭据。
______________________________________________________________________
为什么?
Terraform状态文件是云中实际部署内容的唯一真实来源。安全团队需要定期审核它们,但传统的工作流程是手动的:运行CLI工具,解析终端输出,重复。
mcp tfstate阅读器 为AI代理(如Claude)提供对您的Terraform状态的结构化、只读访问。你问一个问题,代理会自动调用正确的工具,而不是将JSON复制到聊天窗口中。
______________________________________________________________________
特性
| 工具 | 说明 |
|---|---|
list_resources | 解析a .tfstate 归档并列出每个托管资源及其地址和类型 |
audit_security | 扫描常见的配置错误(见下文) |
get_resource_detail | 按地址转储特定资源的完整属性 |
summarize_state | 高级概述:按类型/模块、提供商、标签、地区列出的资源计数 |
compare_states | 基础设施漂移检测——区分添加/删除/修改的两个状态文件 |
安全检查 audit_security
- 第3页 --没有服务器端加密的bucket;未启用版本控制的bucket
- S3 ACL --bucket ACL设置为
public-read或public-read-write - 安全组 --入口规则开放
0.0.0.0/0敏感端口:22(SSH)、3389(RDP)、5432(PostgreSQL) - IAM --带通配符的策略
*操作(完全管理员权限) - 关系型数据库服务 --实例没有
storage_encrypted = true;可公开访问的实例 - 电子制动系统 --未加密的卷
- EC2 --实例与
associate_public_ip_address = true - 拉姆达 --未部署在VPC中的功能
- 公里 --未启用自动按键旋转的按键
- ElastiCache --没有传输加密的复制组
- 社交网络服务 --没有KMS加密的主题
- 简单队列服务 --没有KMS加密的队列
- ALB/NLB --未启用访问日志的负载平衡器
- 云监控 --没有保留策略的日志组
______________________________________________________________________
快速开始
1.安装
pip install mcp-tfstate-reader2.配置克劳德桌面
将此添加到您的Claude Desktop MCP配置文件中:
| 操作系统 | 路径 |
|---|---|
| macOS | ~/Library/Application Support/Claude/claude_desktop_config.json |
| 窗户 | %APPDATA%\Claude\claude_desktop_config.json |
推荐-与 uvx (无需安装):
{
"mcpServers": {
"tfstate-reader": {
"command": "uvx",
"args": ["mcp-tfstate-reader"]
}
}
}注: Claude Desktop可能无法继承您的终端$PATH。如果服务器无法连接,请使用绝对路径uvx(找到它which uvx在您的终端中): ``json { "mcpServers": { "tfstate-reader": { "command": "/full/path/to/uvx", "args": ["mcp-tfstate-reader"] } } }``
替代方案——通过pip安装:
{
"mcpServers": {
"tfstate-reader": {
"command": "mcp-tfstate-reader"
}
}
}备选方案——来源(virtualenv):
{
"mcpServers": {
"tfstate-reader": {
"command": "/absolute/path/to/mcp-tfstate-reader/.venv/bin/python",
"args": ["-m", "mcp_tfstate_reader.server"]
}
}
}3.重新启动克劳德桌面
完全退出(Cmd+Q 在macOS上)并重新打开。查找工具图标以确认服务器已连接。
4.问一个问题
“审核Terraform状态文件 /path/to/terraform.tfstate 为了安全问题。"______________________________________________________________________
交互示例
Claude自主地将工具链接起来——首先列出资源,运行审计,然后钻取关键发现:
Found 17 finding(s):
[CRITICAL] aws_iam_policy.admin: IAM policy contains a wildcard (*) action — grants unrestricted permissions.
[HIGH] aws_s3_bucket.assets: S3 bucket has no server-side encryption configuration.
[HIGH] aws_s3_bucket_acl.assets: S3 bucket ACL is set to 'public-read' — allows public access.
[HIGH] aws_security_group.bastion: Security group allows 0.0.0.0/0 ingress on port 22.
[HIGH] aws_security_group.rdp_open: Security group allows 0.0.0.0/0 ingress on port 3389.
[HIGH] aws_db_instance.prod: RDS instance storage is not encrypted.
[HIGH] aws_db_instance.prod: RDS instance is publicly accessible.
[HIGH] aws_ebs_volume.data: EBS volume is not encrypted.
[HIGH] aws_elasticache_replication_group.sessions: ElastiCache replication group does not have transit encryption enabled.
[MEDIUM] aws_s3_bucket.assets: S3 bucket does not have versioning enabled.
[MEDIUM] aws_instance.web: EC2 instance has a public IP address assigned.
[MEDIUM] aws_lambda_function.processor: Lambda function is not deployed in a VPC.
[MEDIUM] aws_kms_key.app: KMS key does not have automatic key rotation enabled.
[MEDIUM] aws_sns_topic.alerts: SNS topic is not encrypted with a KMS key.
[MEDIUM] aws_sqs_queue.jobs: SQS queue is not encrypted with a KMS key.
[MEDIUM] aws_lb.frontend: Load balancer does not have access logs enabled.
[MEDIUM] aws_cloudwatch_log_group.app: CloudWatch log group has no retention policy (logs kept indefinitely).______________________________________________________________________
故障排除
服务器未出现在Claude Desktop中
- 确保Claude Desktop已完全重新启动(使用退出
Cmd+Q,而不仅仅是关上窗户)。 - 检查你的配置JSON是否有效——尾随的逗号或拼写错误会悄无声息地打断它。
- 如果满足以下条件,请使用绝对路径
uvx或mcp-tfstate-reader未找到。
“找不到文件”错误
该工具从本地文件系统读取文件。使用完整的绝对路径(例如。 /Users/you/infra/terraform.tfstate),而不是相对路径。
这只是克劳德桌面
MCP服务器使用Claude Desktop应用程序,而不是浏览器中的Claude.ai。web界面无法访问本地MCP服务器或您的文件系统。
______________________________________________________________________
发展
# Clone and set up
git clone https://github.com/berkayildi/mcp-tfstate-reader.git
cd mcp-tfstate-reader
make setup
# Run tests
make test
# Build distribution
make build
# Run the server locally (stdio)
make start
# Clean everything
make clean______________________________________________________________________
许可证
麻省理工学院©Berkay Yildirim
