EBS初始化MCP服务器
用于自动化AWS EBS卷初始化的模型上下文协议(MCP)服务器。此服务器提供使用AWS Systems Manager初始化连接到EC2实例的EBS卷的工具。
特性
- 🔍 卷发现:自动发现连接到EC2实例的所有EBS卷
- 🚀 自动初始化:使用初始化卷
fio(推荐)或dd - 🏢 多实例支持:使用单个SSM命令并行初始化多个实例中的卷
- ⏱️ 智能时间估算:通过并行处理模拟,根据卷大小和吞吐量预测完成时间
- 📊 实时进度跟踪:带有准确百分比和每个实例剩余时间的可视化进度条
- ❌ 取消支持:取消正在进行的初始化,并完成进程清理
- 🤖 AI代理优化:基于文本的响应针对AI代理兼容性进行了优化
- 🌐 多区域支持:适用于所有AWS区域
- 🔒 安全执行:使用AWS Systems Manager进行安全的远程执行
- 🏗️ 模块化架构:干净、可维护的代码库,关注点分开
安装
使用uvx(推荐)
# Run directly without installation (latest version)
uvx ebs-initializer-mcp@latest
# Or run specific version
uvx ebs-initializer-mcp==0.7.10
# Install globally
uv tool install ebs-initializer-mcp
# Upgrade to latest version
uvx --upgrade ebs-initializer-mcp来自GitHub
uvx --from git+https://github.com/username/ebs-init-mcp.git ebs-mcp-server用法
作为MCP服务器
添加到MCP配置(mcp_config.json):
{
"mcpServers": {
"ebs-initializer": {
"command": "uvx",
"args": ["ebs-initializer-mcp@latest"],
"env": {
"AWS_REGION": "us-west-2"
}
}
}
}可用工具
- get_instance_volumes:获取附加到实例的所有EBS卷
- 初始化_所有卷:初始化一个或多个实例上的所有卷(支持执行单个SSM命令时使用逗号分隔的实例ID)
- 初始化_体积_by_id:通过卷ID初始化特定卷
- check_initialize_status:监控初始化进度,查看包含每个实例估计数据的详细日志
- cancel_初始化:取消正在进行的初始化,并完成进程清理
使用Claude代码的示例用法
# Single instance
"Initialize all EBS volumes for instance i-1234567890abcdef0 using fio"
# Multiple instances (comma-separated)
"Initialize all EBS volumes for instances i-1234567890abcdef0,i-0987654321fedcba0 using fio"
# Specific volume
"Initialize volume vol-1234567890abcdef0 using fio"
# Check status
"Check the status of the initialization command 12345678-1234-1234-1234-123456789012"
# Cancel operation
"Cancel the initialization command 12345678-1234-1234-1234-123456789012"MCP服务器将:
- 发现所有连接的EBS卷并计算每个实例的估计完成时间
- 在目标实例上安装fio
- 使用基于IMDS的卷过滤跨多个实例执行单个SSM命令
- 与实时吞吐量优化并行运行初始化命令
- 提供 实时进度跟踪 带有可视化进度条和每个实例的估计
- 返回 AI代理优化的扁平JSON结构 具有实例特定数据
- 如果需要,允许取消并完成流程清理
进度跟踪
针对具有多实例支持的AI代理优化的增强进度跟踪:
可视化进度显示
- 实时进度条:
[██████████░░░░░░░░░░] 50.0% - 每实例跟踪:每个实例的个人进度
- 准确百分比:基于初始时间估计和经过的时间
- 剩余时间计算:精确估计完成时间
多实例支持
- 实例特定估计:每个实例都有自己的时间预测
- 并行执行时间:显示所有实例的最大时间(不是总和)
- IMDS音量过滤:每个实例只处理自己的卷
- 参数存储集成:存储多实例命令的估计数据
AI代理优化
- 扁平JSON结构:顶级字段中的进度信息便于访问
- 优先级字段排序:最重要的进展数据放在首位
- 实例分解:每个实例的详细估算数据
单实例响应结构
{
"command_id": "...",
"status": "InProgress",
"execution_start_time": "2025-09-10 01:18:21.418000+00:00",
"progress_percentage": 50.0,
"progress_bar": "[██████████░░░░░░░░░░] 50.0%",
"estimated_remaining_minutes": 5.2,
"message": "🔄 50.0% Complete..."
}多实例响应结构
{
"status": "initialization_started",
"command_id": "4044d07e-c10c-4caf-b5b7-eee8435ac1c7",
"target_instances": ["i-0fe60964746c77041", "i-0a824284f8c887f4a"],
"total_instances": 2,
"instance_estimations": {
"i-0fe60964746c77041": {
"estimated_minutes": 1.09,
"volume_count": 1,
"total_gb": 8,
"instance_type": "t3.xlarge"
},
"i-0a824284f8c887f4a": {
"estimated_minutes": 6.89,
"volume_count": 3,
"total_gb": 208,
"instance_type": "m5.4xlarge"
}
},
"total_estimated_minutes": 6.89
}先决条件
- 配置了适当权限的AWS CLI
- EC2实例必须安装Systems Manager代理
- 支持的操作系统:
- 亚马逊Linux 2 - 亚马逊Linux 2023 - 红帽企业Linux(RHEL) - Ubuntu(18.04,20.04,22.04,24.04) - SUSE Linux企业服务器(SLES)
- 所需IAM权限:
- ec2:DescribeVolumes - ec2:DescribeInstances - ssm:SendCommand - ssm:GetCommandInvocation - ssm:PutParameter - ssm:GetParameter - ssm:DeleteParameter
AWS IAM权限
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:DescribeVolumes",
"ec2:DescribeInstances",
"ssm:SendCommand",
"ssm:GetCommandInvocation",
"ssm:PutParameter",
"ssm:GetParameter",
"ssm:DeleteParameter"
],
"Resource": "*"
}
]
}配置
环境变量
服务器会自动从环境变量中检测AWS区域:
# Option 1: AWS_DEFAULT_REGION (preferred)
export AWS_DEFAULT_REGION=ap-northeast-2
# Option 2: AWS_REGION (also supported)
export AWS_REGION=ap-northeast-2优先级顺序:
AWS_DEFAULT_REGION环境变量AWS_REGION环境变量- 回退到
us-east-1
MCP配置
{
"mcpServers": {
"ebs-initializer": {
"command": "uvx",
"args": ["ebs-initializer-mcp@latest"],
"env": {
"AWS_DEFAULT_REGION": "ap-northeast-2"
}
}
}
}建筑
模块化设计
为了可维护性和可重用性,代码库被组织成重点模块:
src/ebs_init_mcp/
├── server.py # MCP server and tool definitions (430 lines)
├── aws_clients.py # AWS client caching and management
├── throughput.py # EBS throughput calculation
├── estimation.py # Time estimation algorithms
├── initialization.py # Command generation for volume initialization
├── status.py # Status checking and progress calculation
└── utils.py # Utility functions and device mapping scripts时间估计逻辑
1. initialize_all_volumes (并行初始化)
算法:通过吞吐量共享模拟并行处理
# Step 1: Get instance EBS throughput
instance_throughput = get_instance_ebs_throughput(instance_type)
# Step 2: Collect volume data
volumes = [{'size_gb': size, 'max_throughput_mbps': vol_throughput}...]
# Step 3: AWS EBS throughput allocation algorithm
while volumes_remaining:
total_demand = sum(vol_throughput for each volume)
if total_demand fair_share
throughput_per_large = remaining_throughput / len(remaining_large_volumes)
for volume in remaining_large_volumes:
volume.allocated = throughput_per_large
# Calculate completion times and process next step
completion_times = [(size * 1024) / allocated_throughput / 60 for each volume]示例:t3.large(500MB/s),有3个卷:
- 卷1:100GB/125MB/s,卷2:100GB/1000MB/s,第三卷:100GB/1000MB/s
- 总需求:2125MB/s>500MB/s(超过实例限制)
- 分配:第1卷=125MB/s,第2卷=187.5MB/s,第3卷=187.5MB/s
- 结果:第2和第3卷在9.1分钟结束,第1卷单独继续→ 13.7最小总计
2. initialize_volume_by_id (单卷)
算法:简单的吞吐量限制计算
# Step 1: Get throughput constraints
instance_throughput = get_instance_ebs_throughput(instance_type)
volume_throughput = volume.get('Throughput', 1000)
# Step 2: Calculate effective throughput (bottleneck)
effective_throughput = min(volume_throughput, instance_throughput)
# Step 3: Linear time calculation
estimated_minutes = (size_gb * 1024 MB) / effective_throughput / 60示例:100GB容量,t3大(500MB/s),gp3(1000MB/s)
- 有效:最小(1000500)=500MB/s
- 时间:(100×1024)/500/60= 3.4分钟
发展
git clone
cd ebs-init-mcp
# Install dependencies
uv sync
# Run development server
AWS_REGION=ap-northeast-2 uv run mcp dev src/ebs_init_mcp/server.py
# Run tests
uv run pytest
# Format code
uv run ruff format src/
uv run ruff check src/许可证
MIT许可证
