MCP普罗米修斯服务器
](https://github.com/drewstreib/mcp-prom-haskell/releases/tag/v1.0.1)   
概述
Haskell中的生产就绪模型上下文协议(MCP)服务器实现,为Claude Desktop提供了对Prometheus度量和查询的访问。基于Haskell的最佳实践构建,包括适当的异常处理、严格的评估模式和全面的错误恢复。
《阿登特辑》 -v1.0.1采用了先进的Haskell技术,以避免常见的脚踏枪,并确保线程安全、稳健的操作。
特性
- 🚀 Claude桌面集成 -无缝MCP协议支持
- 📊 完整的普罗米修斯API -查询、发现和探索指标
- 🔍 5强大的工具 -从即时查询到指标发现
- 🛡️ 生产就绪 -全面的错误处理和记录
- 🧵 线程安全 -严格的评估可防止延迟I/O挂起
- 🔧 Haskell最佳实践 -正确的异常处理,没有SomeException反模式
- 🧪 测试覆盖率 -包括单元和集成测试
快速开始
选项1:使用预构建二进制文件(推荐)
- 克隆存储库:
git clone https://github.com/drewstreib/mcp-prom-haskell.git
cd mcp-prom-haskell/mcp-prometheus-server- 使用预构建的二进制文件:
./testbin/mcp-prometheus-server --prometheus-url http://your-prometheus-server:9090选项2:从源代码构建
make build
# Binary will be in testbin/mcp-prometheus-server选项3:Docker(开发)
# Start test Prometheus instance
docker-compose up -d prometheus
# Build and run
docker build -t mcp-prometheus-server .
docker run -it --rm \
--network mcp-prometheus-server_mcp-network \
-e PROMETHEUS_URL=http://prometheus:9090 \
mcp-prometheus-serverClaude桌面配置
添加到您的Claude Desktop配置文件中:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json\ 窗户: %APPDATA%\Claude\claude_desktop_config.json\ Linux: ~/.config/claude/claude_desktop_config.json
{
"mcpServers": {
"prometheus": {
"command": "/path/to/mcp-prom-haskell/mcp-prometheus-server/testbin/mcp-prometheus-server",
"args": [
"--prometheus-url",
"http://your-prometheus-server:9090"
]
}
}
}替换 /path/to/ 使用您到存储库的实际路径。
可用工具
1. prometheus_query
在特定时间点执行即时PromQL查询。
示例:“当前的CPU使用率是多少?”
rate(node_cpu_seconds_total[5m])2. prometheus_query_range
在一定时间范围内执行查询以进行趋势分析。
示例:“显示过去一小时的内存使用情况”
node_memory_Active_bytes3. prometheus_series
查找与特定标签选择器匹配的时间序列。
示例:“节点导出器作业有哪些可用指标?”
4. prometheus_metrics
列出系统中所有可用的度量名称。
示例:“我可以查询哪些指标?”
5. prometheus_labels
发现跨指标使用的所有标签名称。
示例:“有哪些标签可用于过滤?”
Haskell实现细节
此服务器展示了生产就绪的Haskell实践:
异常处理
- 不
SomeException反面模式 -仅捕获特定的、可恢复的异常 IOException用于I/O操作 -优雅地处理stdin/stdout故障HttpException用于网络通话 -提供详细的Prometheus连接错误
螺纹安全与性能
- BangPatterns用于严格评估 -防止日志记录中的延迟I/O挂起
- 带时间戳的结构化日志记录 -线程安全、原子日志写入
- UTF-8文本处理 -全面支持Unicode
JSON-RPC合规性
- 适当的通知处理 -根据规范,对通知没有响应
- 类型安全消息解析 -全面的错误恢复
- 协议版本匹配 -完全兼容克劳德桌面
手动安装
先决条件
- GHC 9.12+和阴谋集团3.0+
- 或使用GHCup(推荐):
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh建筑
git clone https://github.com/drewstreib/mcp-prom-haskell.git
cd mcp-prom-haskell/mcp-prometheus-server
make build测试
使用Docker运行测试
docker-compose run --rm mcp-prometheus-server-test手动运行测试
# Unit tests only
cabal test
# With integration tests (requires Prometheus)
export PROMETHEUS_URL=http://your-prometheus-server:9090
cabal test配置
环境变量
PROMETHEUS_URL-Prometheus服务器的URL(默认值:http://your-prometheus-server:9090)
命令行选项
mcp-prometheus-server --prometheus-url http://prometheus:9090发展
项目结构
mcp-prometheus-server/
├── app/ # Main executable
├── src/ # Library source code
│ ├── MCP/ # MCP protocol implementation
│ └── Prometheus/ # Prometheus client
├── test/ # Test suites
├── Dockerfile # Docker image definition
└── docker-compose.yml # Development environment添加新端点
- 在中添加客户端功能
src/Prometheus/Client.hs - 在中添加工具定义
src/MCP/Server.hs - 在中添加测试
test/IntegrationSpec.hs - 更新文档
故障排除
Docker问题
集装箱立即出口:MCP服务器需要stdio交互。使用 -it 旗帜:
docker run -it --rm mcp-prometheus-server:latest无法连接到Prometheus:确保容器位于同一网络上:
docker network create mcp-net
docker run --network mcp-net ...构建问题
阴谋集团依赖性错误:更新您的包裹索引:
cabal updateGHC版本不匹配:使用GHCup安装正确的版本:
ghcup install ghc 9.6.4
ghcup set ghc 9.6.4贡献
我们欢迎捐款!看 ROADMAP.md 对于计划中的功能。
- 分叉存储库
- 创建要素分支
- 添加新功能的测试
- 确保所有测试通过
- 提交拉取请求
许可证
BSD 3条款许可证-请参阅 许可证 文件以获取详细信息。
致谢
《阿登特辑》v1.0.1
此版本代表了生产就绪的Haskell代码,避免了常见的陷阱:
- ✅ 不
SomeException反模式 - ✅ I/O密集型功能的严格评估
- ✅ 线程安全日志记录模式
- ✅ 正确的JSON-RPC通知处理
- ✅ 无崩溃的全面错误恢复

