GPU监控管理服务器

AMD SMI MCP Server是一个用于AMD GPU监控和管理的模型上下文协议服务器,提供70种工具用于系统信息、监控、电源管理等,支持沙盒执行和安全确认机制。

  • by AMD-melliott
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 AMD-melliott/mcp-amdsmi

使用说明

AMD SMI MCP服务器

用于AMD GPU监控和管理的模型上下文协议(MCP)服务器。通过FastMCP 3.x CodeMode分阶段发现,将70个AMD SMI功能作为工具公开,并内置变异操作的安全确认功能。

特性

  • 70工具 7个类别:系统信息、监控、电源、pcie拓扑、流程、ras、配置
  • CodeMode分阶段发现:按标签搜索或浏览,检查模式,然后执行——没有工具列表膨胀
  • 确认令牌安全:所有配置和重置操作在执行前都需要两步确认
  • 4个MCP提示:针对特定领域的健康评估、性能调优、多GPU诊断和安全配置指南
  • 沙盒执行:MontySandbox强制执行每次调用的内存和时间限制

快速开始

先决条件

  • Python 3.11+
  • ROCm 已安装(提供 libamd_smi.so 和那个 amdsmi Python包)
  • Git

安装

这个 amdsmi Python包必须从ROCm提供的源代码安装——PyPI上的版本可能与您的系统不匹配 libamd_smi.so。从ROCm共享目录安装它,然后安装此项目:

git clone https://github.com/AMD-melliott/mcp-amdsmi.git
cd mcp-amdsmi
pip install /opt/rocm/share/amd_smi
pip install -e .

如果 /opt/rocm/share/amd_smi 不可写,请先复制:

cp -r /opt/rocm/share/amd_smi /tmp/amd_smi_build
pip install /tmp/amd_smi_build
rm -rf /tmp/amd_smi_build

跑

mcp-amdsmi

MCP客户端配置

添加到您的Claude Desktop(或其他MCP客户端)配置中:

{
  "mcpServers": {
    "amd-smi": {
      "command": "mcp-amdsmi"
    }
  }
}

要使用特定的虚拟环境,请执行以下操作:

{
  "mcpServers": {
    "amd-smi": {
      "command": "/path/to/venv/bin/mcp-amdsmi"
    }
  }
}

工具类别

类别 计数 示例工具
system-info 12 get_gpu_asic_info, get_gpu_driver_info, get_fw_info
monitoring 15 get_gpu_activity, get_temp_metric, get_gpu_metrics_info
power 5 get_power_cap_info, get_gpu_perf_level, get_violation_status
pcie-topology 10 get_pcie_info, topo_get_link_weight, is_P2P_accessible
process 5 get_gpu_process_list, get_gpu_compute_process_info
ras 8 get_gpu_total_ecc_count, get_gpu_bad_page_info, get_gpu_cper_entries
config 15 set_power_cap, set_gpu_perf_level, reset_gpu

使用工作流程

CodeMode公开了三个元工具,而不是一次公开完整的列表:

  1. 搜索 --按关键字查找工具: Search("temperature")
  2. GetSchemas --检查特定工具的参数和返回类型
  3. 执行 --在沙盒环境中使用参数运行该工具

交互流程示例:

Search("ecc errors")           → [get_gpu_total_ecc_count, get_gpu_ecc_count, ...]
GetSchemas(["get_gpu_total_ecc_count"])  → {gpu_index: int = 0} -> dict
Execute: get_gpu_total_ecc_count(gpu_index=0)

配置工具需要确认:

Execute: set_power_cap(gpu_index=0, power_cap_watts=200)
→ {"status": "confirmation_required", "confirmation_token": "<token>", ...}

Execute: set_power_cap(gpu_index=0, power_cap_watts=200, confirmation_token="<token>")
→ {"status": "success"}

提示

请求这些提示以获得结构化指导:

提示 描述
gpu_health_assessment 逐步GPU健康检查工作流程
performance_tuning 识别并解决性能瓶颈
multi_gpu_diagnostics 诊断多个GPU之间的问题
safe_configuration 通过确认流程安全修改GPU配置

码头工人

使用Docker构建和运行:

docker build -t mcp-amdsmi .
docker run --device=/dev/kfd --device=/dev/dri mcp-amdsmi

使用docker编写:

docker-compose up

发展

使用开发依赖项进行安装:

pip install /opt/rocm/share/amd_smi
pip install -e ".[dev]"

或者使用Makefile:

make install   # Create venv and install dependencies

运行测试(单元测试使用模拟amdsmi——不需要GPU):

make test      # pytest with coverage

运行硬件集成测试(需要AMD GPU):

.venv/bin/pytest tests/ -v -m gpu

代码质量:

make format    # black + isort
make lint      # flake8 + mypy
make check     # format + lint + test (full quality gate)

项目结构

mcp-amdsmi/
├── mcp_amdsmi/
│   ├── server.py          # FastMCP server with CodeMode transform
│   ├── helpers.py         # get_handle() and confirmation-token logic
│   ├── types.py           # Enum/string resolution utilities
│   ├── tools/
│   │   ├── system_info.py # 12 tools
│   │   ├── monitoring.py  # 15 tools
│   │   ├── power.py       # 5 tools
│   │   ├── pcie_topology.py # 10 tools
│   │   ├── process.py     # 5 tools
│   │   ├── ras.py         # 8 tools
│   │   └── config.py      # 15 tools (confirmation-gated)
│   └── prompts/
│       ├── health.py
│       ├── performance.py
│       ├── multi_gpu.py
│       └── safety.py
├── tests/
├── pyproject.toml
├── Makefile              # make test, make check, make format, etc.
├── Dockerfile
├── docker-compose.yml
└── .github/workflows/    # CI/CD (ci.yml, release.yml)

已知限制(MI300X/数据中心GPU)

一些 amdsmi API返回 AMDSMI_STATUS_NOT_SUPPORTED 在MI300X等数据中心GPU上。在这些情况下,这些工具将引发错误。已知的不受支持的功能:

工具 问题 解决方法
get_temp_metric 所有传感器类型(热点、边缘、vram、hbm_0)返回NOT_SUPPORTED 使用 get_gpu_metrics_info 其中包括 temperature_hotspot, temperature_mem, temperature_vrsoc
get_gpu_fan_speed / get_gpu_fan_rpms / get_gpu_fan_speed_max 注意_支持--MI300X使用被动机箱冷却 无需解决方法;检查 get_gpu_metrics_info 为了 current_fan_speed 如果可用
set_gpu_fan_speed / reset_gpu_fan 注意_支持--没有用户可访问的风扇 数据中心GPU不适用
get_gpu_pci_throughput NOT_支持 使用 get_gpu_metrics_info 为了 pcie_bandwidth_inst / pcie_bandwidth_acc
get_gpu_cper_entries 需要root权限(AMDSMI_STATUS_NO_PERM) 以提升的权限运行

这个 get_gpu_metrics_info 该工具返回一个全面的度量blob,其中通常包含无法通过单个度量工具获得的数据。当特定工具返回NOT_SUPPORTED时,请尝试 get_gpu_metrics_info 作为一种退路。

故障排除

amdsmi 导入错误/未定义符号 --The amdsmi Python包版本必须与提供的ROCm版本匹配 libamd_smi.so.做 不 从PyPI安装amdsmi(pip install amdsmi);而是从ROCm源安装: pip install /opt/rocm/share/amd_smi。请参阅 AMD SMI安装文档 了解详情。

GPU设备上的权限被拒绝 --将您的用户添加到 render 和 video 组,或以适当的权限运行。

导入错误 --验证包含以下内容的虚拟环境 mcp-amdsmi 在MCP客户端配置中引用。