Redfish MCP 服务器(Go 语言)
](https://golang.org)  
一个高性能的MCP(模型上下文协议)服务器实现,采用Go语言编写,用于与支持Redfish的基础设施进行交互。该服务器为AI代理和应用程序提供自然语言访问Redfish API端点的能力,从而实现对数据中心基础设施的智能管理和监控。
概述
Redfish MCP服务器使AI驱动的工作流能够通过自然语言查询与符合Redfish标准的服务器进行交互。它提供了一个标准化的接口,用于访问现代基础设施组件的硬件信息、传感器数据以及管理功能。
主要特点
- 🚀 火箭/飞速前进(表情符号,常用于表示快速、前进或火箭等意象) 高性能使用编译后的二进制文件实现的原生Go程序,内存占用低
- 🔍(放大镜图标,通常表示搜索、查看细节或调查) Redfish API 集成全面支持Redfish v1.x API规范
- 🤖 机器人 兼容MCP(微软认证专业人员/微软认证合作伙伴等,具体含义根据上下文确定)与MCP客户端和AI助手无缝集成
- 🔐(锁形符号,常用于表示保密、安全或密码等含义) 安全认证支持基于基本和会话的身份验证
- 🌐 表示“互联网”或“全球网络”。 多种运输方式stdio、SSE 和流式 HTTP 传输选项
- 🔄 翻译成中文是:循环(或旋转) 并发操作基于Goroutine的并发发现与请求
- 📊(表格) 结构化数据访问基于JSON的资源数据检索(含头部信息)
- 🛠️(工具或修理的符号,无直接对应中文文字,可理解为“工具”或根据上下文意译为相关词汇) 可扩展架构模块化设计,便于定制
快速入门
# Clone the repository
git clone https://github.com/theoriginalaiexplorer/mcp-redfish-go.git
cd mcp-redfish-go
# Build the server
go build -o bin/redfish-mcp ./cmd/redfish-mcp
# Configure environment
export REDFISH_HOSTS='[{"address": "192.168.1.100", "username": "admin", "password": "secret"}]'
# Run the server
./bin/redfish-mcp安装
先决条件
- Go 1.21或更高版本
- 访问支持Redfish的基础设施
从源代码构建
# Clone the repository
git clone https://github.com/theoriginalaiexplorer/mcp-redfish-go.git
cd mcp-redfish-go
# Initialize Go module
go mod tidy
# Build for your platform
go build -o bin/redfish-mcp ./cmd/redfish-mcp
# Or build for multiple platforms
make go-build-all预编译的二进制文件
从(官方/指定)网站下载最新发布的二进制文件 发布 页面用于:
- Linux(AMD64架构)
- macOS(amd64架构)
- Windows(适用于64位AMD处理器)
MCP 工具
服务器提供了两个主要的MCP工具,用于与Redfish基础设施进行交互:
list_servers
列出所有可访问的已配置Redfish服务器。
示例用法:
List all available Redfish servers回应:
{
"servers": ["192.168.1.100", "192.168.1.101"]
}get_resource_data
从特定的Redfish资源端点获取数据。
参数:
urlRedfish 资源的 URL(例如。,https://192.168.1.100/redfish/v1/Systems/1)
示例用法:
Get the system information from https://192.168.1.100/redfish/v1/Systems/1回答:
{
"headers": {
"content-type": ["application/json"],
"etag": ["\"12345\""]
},
"data": {
"@odata.id": "/redfish/v1/Systems/1",
"Name": "System1",
"Manufacturer": "Example Corp"
}
}配置
服务器支持通过环境变量或JSON文件进行配置。配置在启动时进行验证,以确保正确设置。
配置方法
- JSON 文件 (推荐用于复杂配置):
./bin/redfish-mcp --config config.json- 环境变量 (默认):
export REDFISH_HOSTS='[{"address": "192.168.1.100"}]'
./bin/redfish-mcpJSON 配置文件
创建一个 config.json 包含完整配置的文件:
{
"redfish": {
"hosts": [
{
"address": "192.168.1.100",
"port": 443,
"username": "admin",
"password": "secret123",
"auth_method": "session",
"tls_server_ca_cert": "/path/to/ca-cert.pem"
}
],
"port": 443,
"auth_method": "session",
"username": "default_user",
"password": "default_pass",
"tls_server_ca_cert": "",
"insecure_skip_verify": false,
"discovery_enabled": false,
"discovery_interval": 30
},
"mcp": {
"transport": "stdio",
"log_level": "INFO"
}
}在没有SSL证书的情况下访问服务器
对于使用带有自签名或无效SSL证书的Redfish服务器进行开发或测试的情况,您可以跳过证书验证:
环境变量:
export REDFISH_INSECURE_SKIP_VERIFY=trueJSON 配置:
{
"redfish": {
"insecure_skip_verify": true
}
}⚠️(表示警告或注意的符号,无具体文字含义) 安全警告: 仅限使用 insecure_skip_verify 在开发或受信任的环境中。此选项禁用SSL证书验证,使连接容易受到中间人攻击。
环境变量
| 变量 | 描述 | 默认值 | 是否必需 | ||
|---|---|---|---|---|---|
| (无对应中文) | (无对应中文) | (无对应中文) | (无对应中文) | REDFISH_CONFIG_FILE | |
| JSON配置文件的路径 | - | 否 | REDFISH_HOSTS | [{"address":"127.0.0.1"}] | 主机配置的 JSON 数组 |
| 是\* | REDFISH_PORT | 443 | 默认的Redfish端口 | ||
| 不 | REDFISH_AUTH_METHOD | basic | 认证方法: session 或者 session | ||
| 序号 | REDFISH_USERNAME | "" 默认用户名 | |||
| 不 | REDFISH_PASSWORD | "" | 默认密码 | ||
| 编号 | REDFISH_SERVER_CA_CERT | "" | CA证书路径 | ||
| 不(No) | REDFISH_INSECURE_SKIP_VERIFY | false | 跳过SSL证书验证 | ||
| 序号 | REDFISH_DISCOVERY_ENABLED | false | 启用SSDP发现 | ||
| 序号 | REDFISH_DISCOVERY_INTERVAL | 30 | 发现间隔(秒) | ||
| 序号 | MCP_TRANSPORT | stdio | 交通: sse, streamable-http , stdio | ||
| 编号 | MCP_REDFISH_LOG_LEVEL | DEBUG | 日志级别: INFO, WARNING, ERROR, CRITICAL , INFO |
| 不 |
\*当不使用JSON配置文件时为必填项
主机配置 REDFISH_HOSTS 每个主机在
address或者JSON文件可以指定:port(必填):IP地址或主机名username(可选):端口号password(可选):针对特定主机的用户名auth_method(可选):特定主机的密码basic(可选):sessiontls_server_ca_cert或者
(可选):自定义CA证书路径
验证
服务器在启动时验证配置,如果配置无效,则会退出并显示详细的错误信息。
运行服务器
# Build the server
go build -o bin/redfish-mcp ./cmd/redfish-mcp
# Set configuration
export REDFISH_HOSTS='[{"address": "192.168.1.100", "username": "admin", "password": "secret"}]'
# Run with stdio transport (default)
./bin/redfish-mcp
# Or use a config file
./bin/redfish-mcp --config redfish-config.json基本用法
交通
该服务器支持多种MCP传输机制:
stdio 传输(默认)
export MCP_TRANSPORT="stdio"
./bin/redfish-mcp用于与MCP客户端直接集成的标准输入/输出通信。
SSE Transport(服务器发送事件)
export MCP_TRANSPORT="sse"
./bin/redfish-mcp
# Server will be available at http://localhost:8000/sse基于HTTP的网络通信,用于远程客户端。
可流式传输的HTTP传输
export MCP_TRANSPORT="streamable-http"
./bin/redfish-mcp针对特定MCP实现的替代HTTP传输方式。
Makefile 目标
make go-build # Build the binary
make go-run # Run the server
make go-test # Run tests
make go-fmt # Format code
make go-vet # Lint code使用提供的 Makefile 进行常见操作:
与MCP客户端的集成
Claude Desktop(中文可译为“克劳德桌面版”或根据具体语境简化为“克劳德桌面”,但通常直接保留原名以体现品牌特色) claude_desktop_config.json将服务器添加到您的(系统/列表/配置中等,具体根据上下文确定)
{
"mcpServers": {
"redfish": {
"command": "/path/to/bin/redfish-mcp",
"env": {
"REDFISH_HOSTS": "[{\"address\": \"192.168.1.100\", \"username\": \"admin\", \"password\": \"secret123\"}]",
"MCP_TRANSPORT": "stdio"
}
}
}
}:
带有GitHub Copilot的VS Code .vscode/mcp.json在您的 VS Code 设置中进行配置,或者
{
"mcp": {
"servers": {
"redfish": {
"command": "/path/to/bin/redfish-mcp",
"env": {
"REDFISH_HOSTS": "[{\"address\": \"192.168.1.100\", \"username\": \"admin\", \"password\": \"secret123\"}]",
"MCP_TRANSPORT": "stdio"
}
}
}
}
}:
MCP 检查器
npx @modelcontextprotocol/inspector /path/to/bin/redfish-mcp使用MCP Inspector测试服务器: 如需更多信息,请参阅VS Code 文档
。
测试
单元测试
# Run all tests
go test ./...
# Run with race detection
go test -race ./...
# Run with coverage
go test -cover ./...
# Using Makefile
make go-test运行Go测试套件:
MCP 检测器(或 MCP 检查器)
# Build and test
go build -o bin/redfish-mcp ./cmd/redfish-mcp
npx @modelcontextprotocol/inspector ./bin/redfish-mcp使用MCP Inspector与服务器进行交互式测试:
集成测试 REDFISH_HOSTS 服务器可以使用真实的Redfish硬件或模拟器进行测试。请确保您的
配置指向可访问的终端节点。
- 示例用例人工智能助手
- 使大型语言模型能够通过Redfish API获取基础设施数据。聊天机器人与虚拟助手
检索数据,并提供个性化回复。
发展
- 先决条件
- Go 1.21 或更高版本
Git
# Clone the repository
git clone https://github.com/theoriginalaiexplorer/mcp-redfish-go.git
cd mcp-redfish-go
# Install dependencies
go mod tidy
# Build
go build ./cmd/redfish-mcp设置
# Format code
go fmt ./...
# Lint code
go vet ./...
# Run tests
go test ./...
# Build for development
go build -o bin/redfish-mcp ./cmd/redfish-mcp
# Run the server
./bin/redfish-mcp开发工作流程
.
├── cmd/redfish-mcp/ # Main application
│ └── main.go # Entry point
├── pkg/ # Go packages
│ ├── config/ # Configuration management
│ │ ├── config.go # Config structs and validation
│ │ ├── env.go # Environment parsing
│ │ └── config_test.go # Unit tests
│ ├── redfish/ # Redfish client and discovery
│ │ ├── client.go # HTTP client with retry logic
│ │ ├── discovery.go # SSDP discovery
│ │ └── types.go # Type definitions
│ ├── mcp/ # MCP server implementation
│ │ └── server.go # MCP server setup and tools
│ └── common/ # Shared utilities
│ └── hosts.go # Host management
├── .github/workflows/ # CI/CD workflows
│ └── release.yml # Release automation
├── Makefile # Build and development tasks
└── README.md # This file项目结构
- 代码质量格式化
go fmt: - 为了保持格式的一致性代码检查(或代码规范检查)
go vet: - 用于静态分析测试
go test - 进行全面的单元测试,使用模块
用于依赖管理的Go模块
- 贡献;助力
- 为仓库创建分支(或:克隆仓库)
- 创建一个特性分支
- 在进行更改时进行测试
go test ./...跑go vet ./... - 并且
提交一个拉取请求
许可证 此项目采用Apache License 2.0授权——详见 许可证
文件中详述。
贡献;做出贡献
