RS系统健康监视器-MCP服务器🚀
   
一个功能强大的模型上下文协议(MCP)服务器,为RS Systems挡风玻璃维修应用程序提供全面的健康监测。与Claude Desktop无缝集成,通过自然语言交互提供实时监控、警报和诊断。
🌟 为什么选择MCP服务器?
- 🔍 实时监控:从Claude Desktop监控您的整个RS系统基础设施
- 💬 自然语言接口:问“我的数据库性能如何?”或“是否有任何卡住的修复?”
- 🗄️ 数据库不可知:同时适用于SQLite(开发)和PostgreSQL(生产)
- ⚡ 快速性能:所有监控工具的平均响应时间为4.82ms
- 🎯 生产就绪:通过全面的错误处理,测试成功率为87.5%
📊 测试结果和性能
我们的全面测试显示了出色的可靠性:
✅ Tests Passed: 7/8 tools (87.5% success rate)
⚡ Average Response Time: 4.82ms
🚀 Fastest Response: 0.01ms
📈 Slowest Response: 22.52msMCP工作工具:
- ✅ 数据库性能监控(1.95ms)
- ✅ 维修队列监控(6.18ms)
- ✅ API性能检查(22.52ms)
- ✅ S3存储分析(0.01ms)
- ✅ 用户活动跟踪(3.01ms)
- ✅ 警报管理(0.03ms)
- ✅ 背景监测(0.02ms)
🚀 快速入门(5分钟)
1.先决条件检查
python3 --version # Requires 3.11+2.克隆和设置
git clone https://github.com/00one00/rs_systems_mcp_health_monitor.git
cd rs_systems_mcp_health_monitor
# Create and activate virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\\Scripts\\activate
# Install dependencies
pip install -r requirements.txt3.配置环境
cp .env.example .env
# Edit .env to point to your database最低配置要求:
# For SQLite (Development)
DATABASE_URL=sqlite:///path/to/your/db.sqlite3
# For PostgreSQL (Production)
DATABASE_URL=postgresql://username:password@localhost:5432/rs_systems
# Enable/disable features
ENABLE_DATABASE_MONITORING=true
ENABLE_S3_MONITORING=false # Set to true if you have AWS credentials4.测试服务器
python test_mcp_tools.py5.与克劳德桌面集成
添加到您的Claude Desktop配置(claude_desktop_config.json):
macOS/Linux:
{
"mcpServers": {
"rs-health-monitor": {
"command": "/path/to/venv/bin/python",
"args": ["-m", "src.server"],
"cwd": "/path/to/rs_systems_mcp_health_monitor",
"env": {
"PYTHONPATH": "/path/to/rs_systems_mcp_health_monitor"
}
}
}
}窗户:
{
"mcpServers": {
"rs-health-monitor": {
"command": "C:\\path\\to\\venv\\Scripts\\python.exe",
"args": ["-m", "src.server"],
"cwd": "C:\\path\\to\\rs_systems_mcp_health_monitor",
"env": {
"PYTHONPATH": "C:\\path\\to\\rs_systems_mcp_health_monitor"
}
}
}
}重新启动克劳德桌面 你准备好了! 🎉
💬 Claude使用示例
配置后,您可以在Claude Desktop中通过自然语言与RS系统进行交互:
🔍 系统健康检查
You: "Check the overall health of my RS Systems application"
Claude: [Uses system_health_summary tool]
Sample Output:
# RS Systems Health Summary
**Overall Health Score:** 85.2/100 (HEALTHY)
**Active Alerts:** 0
**Components Checked:** database, api, queue, activity
**Database Status:** HEALTHY (response: 1.95ms)
**Queue Status:** HEALTHY (5 repairs in progress)📈 数据库性能
You: "How is my database performing? Any slow queries?"
Claude: [Uses check_database_performance tool]
Sample Output:
# Database Performance Report
**Status:** HEALTHY
**Database Type:** SQLite
**Database Size:** 0.34 MB
**Response Time:** 1.95ms
**Tables Found:** 25 tables
**Top Tables by Size:**
- auth_permission: 88 rows
- technician_portal_repair: 34 rows🔧 维修队列监控
You: "Show me the current repair queue status"
Claude: [Uses monitor_repair_queue tool]
Sample Output:
# Repair Queue Status
**Queue Health:** HEALTHY
**Active Repairs:** 13 total
**Status Distribution:**
- COMPLETED: 18 repairs
- IN_PROGRESS: 5 repairs
- PENDING: 4 repairs
- APPROVED: 3 repairs
- REQUESTED: 4 repairs👥 技术人员活动
You: "Are my technicians active today?"
Claude: [Uses track_user_activity tool]
Sample Output:
# User Activity Report
**Total Technicians:** 8
**Active Today:** 2 technicians
**Total Users:** 15
**Recent Activity:** Normal levels🚨 警报管理
You: "Show me any system alerts"
Claude: [Uses get_active_alerts tool]
Sample Output:
# Active System Alerts
**Current Alerts:** 0 active
**Alert Status:** All systems normal
**Last Check:** 2025-09-17 09:47:14🛠️ 所有MCP工具参考
| 工具名称 | 用途 | 响应时间 | 状态 |
|---|---|---|---|
system_health_summary | 整体系统运行状况仪表板 | ~2ms | ✅ 工作 |
check_database_performance | 数据库指标和性能 | 1.95ms | ✅ 工作 |
monitor_repair_queue | 维修工作流程监控 | 6.18ms | ✅ 工作 |
check_api_performance | API端点运行状况检查 | 22.52ms | ✅ 工作 |
analyze_s3_usage | AWS S3存储监控 | 0.01毫秒 | ✅ 工作 |
track_user_activity | 用户和技术人员活动 | 3.01ms | ✅ 工作 |
get_active_alerts | 警报管理系统 | 0.03ms | ✅ 工作 |
start_monitoring | 开始后台监控 | 0.02ms | ✅ 工作 |
stop_monitoring | 停止后台监控 | 0.03ms | ✅ 工作 |
resolve_alert | 将警报标记为已解决 | ~1ms | ✅ 工作 |
🏗️ 架构概述
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Claude Desktop │◄──►│ MCP Server │◄──►│ RS Systems DB │
│ │ │ │ │ (SQLite/PG) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐
│ Monitors: │
│ • Database │
│ • API │
│ • Queue │
│ • Activity │
│ • Storage │
│ • Alerts │
└─────────────────┘关键部件:
- 数据库适配器层:自动检测SQLite与PostgreSQL,并相应地调整查询
- 监视器模块:针对不同系统组件的独立监控服务
- 警报管理器:处理阈值并管理警报生命周期
- MCP接口:为Claude Desktop集成提供自然语言工具
🔧 数据库兼容性
SQLite支持(开发/测试)
- ✅ 全面健康监测
- ✅ 维修队列分析
- ✅ 用户活动跟踪
- ✅ 表统计
- ⚠️ 有限的慢速查询检测(SQLite不提供详细的查询日志)
PostgreSQL支持(生产)
- ✅ 全面健康监测
- ✅ 高级慢速查询检测
- ✅ 连接池监控
- ✅ 锁检测
- ✅ 性能分析
自动检测:系统会自动从中检测您的数据库类型 DATABASE_URL 并使用适当的适配器。
📋 配置参考
核心设置
# Database (Required)
DATABASE_URL=sqlite:///path/to/db.sqlite3
# Feature Toggles
ENABLE_DATABASE_MONITORING=true # Core database health
ENABLE_API_MONITORING=true # API endpoint health
ENABLE_QUEUE_MONITORING=true # Repair queue status
ENABLE_S3_MONITORING=false # AWS S3 storage (requires credentials)
ENABLE_ACTIVITY_MONITORING=true # User activity patterns
# Performance Thresholds
ALERT_THRESHOLD_DB_QUERY_MS=500 # Slow query threshold
ALERT_THRESHOLD_API_RESPONSE_MS=2000 # API response threshold
ALERT_THRESHOLD_QUEUE_STUCK_HOURS=24 # Stuck repair threshold
# Logging
LOG_LEVEL=INFO
LOG_FILE_PATH=./logs/health.logAWS S3配置(可选)
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
AWS_REGION=us-east-1
S3_BUCKET_NAME=rs-systems-media松弛通知(可选)
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR/WEBHOOK/URL
SLACK_CHANNEL=#rs-systems-alerts🔍 故障排除指南
常见问题及解决方案
1.“数据库连接失败”
原因:数据库URL不正确或缺少数据库文件
解决方案:
# Check if database file exists (for SQLite)
ls -la /path/to/your/db.sqlite3
# Test database connection
python -c "
import sqlite3
conn = sqlite3.connect('path/to/db.sqlite3')
print('✅ Database accessible')
conn.close()
"
# Verify DATABASE_URL format
# SQLite: sqlite:///absolute/path/to/file.sqlite3
# PostgreSQL: postgresql://user:pass@host:port/dbname2.“没有这样的表:技师_门户_维修”
原因:数据库架构与RS系统结构不匹配
解决方案:
# Check available tables
python -c "
import sqlite3
conn = sqlite3.connect('path/to/db.sqlite3')
cursor = conn.cursor()
cursor.execute(\"SELECT name FROM sqlite_master WHERE type='table'\")
tables = cursor.fetchall()
print('Available tables:', [t[0] for t in tables])
conn.close()
"
# Ensure you're pointing to the correct RS Systems database3.“MCP服务器未连接到克劳德桌面”
解决方案:
# 1. Check Python path is correct
which python # Should match path in claude_desktop_config.json
# 2. Test server manually
source venv/bin/activate
python -m src.server
# 3. Check Claude Desktop logs
# macOS: ~/Library/Logs/Claude/
# Windows: %APPDATA%/Claude/Logs/
# 4. Verify configuration syntax
python -c "import json; json.load(open('path/to/claude_desktop_config.json'))"4.“SSL证书错误”
原因:外部服务的网络/SSL问题
解决方案:
# Disable S3 monitoring if no AWS credentials
ENABLE_S3_MONITORING=false
# Use placeholder Slack webhook (monitoring will still work)
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR/WEBHOOK/URL5.“权限被拒绝”错误
解决方案:
# Ensure logs directory exists and is writable
mkdir -p logs
chmod 755 logs
# Check file permissions
ls -la .env
chmod 644 .env性能优化
响应时间慢
# Check database size
du -h /path/to/db.sqlite3
# Monitor resource usage
python test_mcp_tools.py # Shows detailed performance metrics
# Adjust monitoring intervals
MONITORING_INTERVAL_SECONDS=60 # Increase for less frequent checks🧪 开发与测试
运行测试
# Comprehensive MCP tools test
python test_mcp_tools.py
# Basic functionality test
python test_server.py
# Test specific monitor
python -c "
import asyncio
from src.monitors.database import DatabaseMonitor
monitor = DatabaseMonitor()
result = asyncio.run(monitor.check_health())
print(f'Database health: {result.status}')
"添加自定义监视器
# 1. Create new monitor in src/monitors/
class CustomMonitor:
async def check_health(self):
# Your monitoring logic
pass
# 2. Register in src/server.py
self.custom_monitor = CustomMonitor()
# 3. Add MCP tool
@self.server.call_tool()
async def custom_check(arguments):
return await self.custom_monitor.check_health()🚀 部署选项
开发(SQLite)
- ✅ 快速设置
- ✅ 无外部依赖关系
- ✅ 非常适合测试
生产(PostgreSQL)
- ✅ 高级监控功能
- ✅ 更好的性能分析
- ✅ 生产级可靠性
Docker部署
# Use included Docker setup
docker-compose up -d rs-health-monitor
# Or build manually
docker build -t rs-health-monitor .
docker run -d --name rs-health-monitor --env-file .env rs-health-monitor📈 功能路线图
当前版本(v1.0)
- ✅ SQLite和PostgreSQL支持
- ✅ 10个MCP监控工具
- ✅ 实时健康检查
- ✅ 警报管理
- ✅ Claude桌面集成
即将推出的功能
- 🔄 高级分析仪表板
- 🔄 自定义警报规则
- 🔄 电子邮件通知
- 🔄 历史指标存储
- 🔄 性能趋势
🤝 贡献
- 分叉存储库
- 创建要素分支:
git checkout -b feature-name - 运行测试:
python test_mcp_tools.py - 提交更改:
git commit -m "Add feature: description" - 推送到分支:
git push origin feature-name - 创建拉取请求
开发设置
# Install development dependencies
pip install -r requirements.txt
# Run code formatting
black src/
# Run type checking
mypy src/
# Run linting
pylint src/📄 许可证
MIT许可证-请参阅 许可证 详细信息文件
🆘 支持
🙏 致谢
- 内置于 模型上下文协议SDK 通过Anthropic
- 设计用于 克劳德桌面 整合
- 支持 RS系统 挡风玻璃维修平台
______________________________________________________________________
RS系统健康监测 -借助克劳德的力量,让您的挡风玻璃维修应用程序平稳运行! 🚗✨
