这是首个通用的服务健康监测工具,适用于Claude桌面版及兼容MCP的AI助手。它是一个专业级的MCP服务器,能让AI助手以企业级的安全性监测Web服务、API和HTTP端点,非常适合DevOps和服务监控,确保服务平稳运行。
本项目由 Natasha 与Claude Sonnet 4合作完成,是一个学习实践项目,无需MCP服务器开发经验!
如果你刚接触MCP开发或对AI辅助编程感兴趣,这个项目展示了在AI指导下学习所能取得的成果。查看我们的 开发流程 和 贡献指南 获取更多见解!
在学习MCP开发的过程中,我希望构建一个能通过AI对话真正用于监测服务的工具。这个MCP服务器为Claude(以及其他AI助手)提供了一种便捷的方式,可通过聊天自然地检查服务健康状况。
git clone https://github.com/natashanajdovski/service-health-mcp.git
cd service-health-mcp
npm install
npm run build
%APPDATA%\Claude\claude_desktop_config.json~/Library/Application Support/Claude/claude_desktop_config.json~/.config/Claude/claude_desktop_config.json{
"mcpServers": {
"service-health": {
"command": "node",
"args": ["C:\\path\\to\\service-health-mcp\\dist\\server.js"],
"cwd": "C:\\path\\to\\service-health-mcp"
}
}
}
"Check if google.com is healthy"📝 "Check if google.com is healthy"
📝 "Is api.github.com responding properly?"
📝 "Test if my-website.com is up"
📝 "Check if api.example.com/health is healthy with a 15 second timeout"
📝 "Test httpbin.org/post using POST method"
📝 "Check if my-api.com returns 201 status code"
📝 "Check if our production API is responding normally"
📝 "Test all our microservices for health"
📝 "Monitor our CDN endpoints"
✅ **健康检查结果**
**URL**:https://api.github.com
**状态**:HEALTHY
**响应时间**:127ms
**HTTP状态**:200 (OK)
**消息**:Endpoint is healthy (200) - 127ms response time
**检查时间**:2024-07-24T21:30:00.000Z
**解读**:
🎉 端点运行正常!未检测到问题。
❌ **健康检查结果**
**URL**:https://down-service.com
**状态**:UNHEALTHY
**响应时间**:5000ms
**消息**:Network error: Connection timeout
**检查时间**:2024-07-24T21:30:00.000Z
**解读**:
🚨 端点存在问题,可能已关闭或配置错误,需要进行调查。
| 特性分类 | 详情 |
|---|---|
| 🔍 健康监测 | - ✅ HTTP/HTTPS端点测试 - ✅ 响应时间测量 - ✅ 状态码验证 - ✅ 支持自定义头部 - ✅ 支持多种HTTP方法 - ✅ 可配置超时时间(1 - 30秒) |
| 🛡️ 企业级安全 | - ✅ 防止SSRF攻击 - ✅ 阻止内部网络访问 - ✅ 输入验证与清理 - ✅ 协议限制(仅支持HTTP/HTTPS) - ✅ 端口过滤与安全默认设置 - ✅ 零凭证暴露 |
| ⚡ 性能 | - ✅ 亚秒级响应时间 - ✅ 高效的连接处理 - ✅ 最小化资源使用 - ✅ 非阻塞异步操作 - ✅ 优化的错误处理 - ✅ 智能重试逻辑 |
| 🔧 开发者体验 | - ✅ 完全支持TypeScript - ✅ 专业的错误消息 - ✅ 全面的日志记录 - ✅ 易于MCP集成 - ✅ 热重载开发 - ✅ 详细的文档 |
本MCP服务器实现了企业级的安全措施以防止攻击:
❌ 阻止:localhost, 127.0.0.1
❌ 阻止:192.168.x.x, 10.x.x.x, 172.16 - 31.x.x
❌ 阻止:169.254.169.254(云元数据)
❌ 阻止:非HTTP协议(ftp, file等)
✅ 允许:仅公共HTTP/HTTPS端点
npm run dev # 🔄 热重载开发
npm run build # 🏗️ 生产构建
npm run start # 🚀 运行构建版本
npm run clean # 🧹 清理构建文件
npx @modelcontextprotocol/inspector src/server.ts
service-health-mcp/
├── src/
│ ├── server.ts # 🎯 主MCP服务器
│ ├── health/
│ │ └── http-checker.ts # 🔍 核心健康逻辑
│ ├── security/
│ │ └── url-validator.ts # 🛡️ SSRF防护
│ └── tools/
│ └── check-http.ts # 🛠️ MCP工具接口
├── dist/ # 📦 编译后的JavaScript
├── docs/ # 📚 文档
└── package.json # 📋 项目配置
check_http_endpoint检查HTTP/HTTPS端点是否健康且可响应。
| 参数 | 类型 | 是否必需 | 默认值 | 描述 |
|---|---|---|---|---|
url |
string |
✅ 是 | - | 要检查的URL(例如,https://google.com) |
method |
"GET" | "POST" | "PUT" | "DELETE" |
❌ 否 | "GET" |
要使用的HTTP方法 |
timeout |
number |
❌ 否 | 10000 |
请求超时时间(毫秒,1000 - 30000) |
expectedStatus |
number |
❌ 否 | 200 |
预期的HTTP状态码(100 - 599) |
headers |
Record |
❌ 否 | {} |
可选的HTTP头部 |
{
"url": "https://api.example.com/health",
"method": "GET",
"timeout": 15000,
"expectedStatus": 200,
"headers": {
"User-Agent": "Health-Checker/1.0",
"Accept": "application/json"
}
}
{
status: "healthy" | "unhealthy" | "warning";
responseTime: number; // 毫秒
statusCode?: number; // HTTP状态码
message: string; // 人类可读的描述
details: {
url: string;
timestamp: string; // ISO 8601格式
error?: string; // 错误详情(如果适用)
}
}
Claude无法识别健康检查工具。
npm run build 并检查是否有错误出现网络错误或超时。
❌ Network error: Client network socket disconnected
由于安全原因URL被阻止。
❌ Access to internal networks and localhost is not allowed
这是有意设置的!安全系统正常工作:
curl响应时间慢或超时。
我们欢迎所有技能水平的贡献者!这个项目由一名学习者在AI的辅助下构建,我们很高兴能壮大社区。
git clone https://github.com/yourusername/service-health-mcp.gitgit checkout -b feature/amazing-featuregit commit -m "Add amazing feature"git push origin feature/amazing-feature查看 CONTRIBUTING.md 获取详细指南。
打开一个问题来建议功能或对优先级进行投票。
MIT许可证 - 详情请查看 LICENSE 文件。
简而言之:你可以自由使用、修改和分发这个项目,只需包含许可证声明。
🚀 用 ❤️、TypeScript和Claude AI构建 | 让服务监测人人可用
⭐ 如果这个项目对你有帮助,请给它加星! ⭐