返回顶部
m

mcp-health-monitor

Auto-monitor MCP servers and AI services with health checks, auto-restart on failure, and Telegram alerts

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
63
下载量
0
收藏
概述
安装方式
版本历史

mcp-health-monitor

# MCP Health Monitor Automated health monitoring for MCP servers and AI services. Detects failures, auto-restarts services via `launchctl`, and sends Telegram alerts on incidents. Silent when everything is healthy. ## Supported Check Types | Type | Method | Auto-Restart | |------|--------|--------------| | HTTP Health | `curl` endpoint check | Yes (via launchctl) | | Process | `pgrep` process detection | Yes (via launchctl) | | Process-only | `pgrep` detection | No (expects external spawn) | ## Quick Start ### 1. Install the healthcheck script ```bash # Copy the script to your preferred location cp scripts/healthcheck.sh ~/.local/bin/mcp-healthcheck.sh chmod +x ~/.local/bin/mcp-healthcheck.sh ``` ### 2. Configure environment variables Create or update your `.env` file (path configurable via `ENV_FILE`): ```bash # Required for Telegram alerts (optional — script works without them) TELEGRAM_BOT_TOKEN=your-bot-token-here TELEGRAM_CHAT_ID=your-chat-id-here ``` ### 3. Configure services to monitor Edit the `SERVICES` array in `healthcheck.sh`. Each entry follows this format: ``` name|check_type|target|launchctl_label ``` **Fields:** - `name` — Display name for logs and alerts - `check_type` — `http` (HTTP endpoint) or `process` (pgrep pattern) - `target` — URL for http checks, or process grep pattern for process checks - `launchctl_label` — macOS launchctl service label for auto-restart (use `none` to skip restart) **Default configuration:** ```bash SERVICES=( "Claw-Empire|http|http://127.0.0.1:8790/api/health|com.claw-empire.server" "Hermes-Gateway|process|hermes_cli.main gateway|ai.hermes.gateway" "mem0-MCP|process|mem0_mcp/server.py|none" "Brave-Search-MCP|process|brave-search-mcp-server|none" "Context7-MCP|process|context7-mcp|none" ) ``` ### 4. Set up automated scheduling (macOS LaunchAgent) Create `~/Library/LaunchAgents/com.mcp-health-monitor.plist`: ```xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.mcp-health-monitor</string> <key>ProgramArguments</key> <array> <string>/bin/bash</string> <string>~/.local/bin/mcp-healthcheck.sh</string> </array> <key>StartInterval</key> <integer>300</integer> <key>StandardOutPath</key> <string>~/.local/logs/mcp-healthcheck-stdout.log</string> <key>StandardErrorPath</key> <string>~/.local/logs/mcp-healthcheck-stderr.log</string> <key>RunAtLoad</key> <true/> </dict> </plist> ``` Load the agent: ```bash launchctl load ~/Library/LaunchAgents/com.mcp-health-monitor.plist ``` ### 5. Linux alternative (systemd timer or cron) ```bash # crontab -e */5 * * * * /path/to/mcp-healthcheck.sh ``` For systemd, replace `launchctl stop/start` calls in the script with `systemctl restart`. ## Environment Variables | Variable | Required | Description | |----------|----------|-------------| | `ENV_FILE` | No | Path to `.env` file (default: `$HOME/.env`) | | `LOG_FILE` | No | Path to log file (default: `$HOME/.local/logs/mcp-healthcheck.log`) | | `TELEGRAM_BOT_TOKEN` | No | Telegram Bot API token for alerts | | `TELEGRAM_CHAT_ID` | No | Telegram chat/group ID for alerts | | `HTTP_TIMEOUT` | No | HTTP check timeout in seconds (default: `5`) | | `RESTART_DELAY` | No | Seconds to wait between stop and start (default: `3`) | ## Log Format Structured log entries: ``` [2026-03-30 14:00:00] [Claw-Empire] [OK] healthy (HTTP 200) [2026-03-30 14:00:00] [mem0-MCP] [FAIL] not running (process not found) [2026-03-30 14:00:00] [SYSTEM] [ALERT] 1 failures detected — sending notification ``` ## Telegram Alert Format Alerts are only sent when failures are detected. No notification on all-healthy runs. ``` 🚨 *MCP Health Check Alert* 2026-03-30 14:00:00 Failures detected (1): * mem0-MCP (process not found) Services with launchctl labels were auto-restarted. Process-only services await external respawn. ``` ## Customization ### Adding a new service Append to the `SERVICES` array: ```bash SERVICES+=( "My-Custom-MCP|process|my-custom-mcp-server|com.my-custom.mcp" ) ``` ### HTTP check with custom port ```bash SERVICES+=( "My-API|http|http://127.0.0.1:3000/health|com.my-api.server" ) ``` ### Disable auto-restart for a service Set the launchctl label to `none`: ```bash "My-Service|process|my-service-pattern|none" ``` ## Troubleshooting | Issue | Solution | |-------|----------| | Telegram alerts not sending | Verify `TELEGRAM_BOT_TOKEN` and `TELEGRAM_CHAT_ID` in your `.env` | | `launchctl` restart fails | Check the service label matches your `.plist` file name | | False positives on process checks | Adjust the `pgrep` pattern to be more specific | | Log file growing too large | Set up `logrotate` or periodic cleanup via cron |

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 mcp-health-monitor-1775931882 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 mcp-health-monitor-1775931882 技能

通过命令行安装

skillhub install mcp-health-monitor-1775931882

下载 Zip 包

⬇ 下载 mcp-health-monitor v1.0.0

文件大小: 5.92 KB | 发布时间: 2026-4-12 10:32

v1.0.0 最新 2026-4-12 10:32
Initial release of mcp-health-monitor:

- Automates health checks for MCP servers and AI services (HTTP and process checks).
- Auto-restarts failed services via launchctl; supports optional Telegram alerts for failures.
- Simple setup with environment variables and an editable services list in the script.
- macOS LaunchAgent and Linux (cron/systemd) scheduling supported.
- Detailed, structured logs and failure notifications only when issues are detected.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部