内容
# 健康监控 MCP
> MCP 服务器健康监测、在线时间跟踪、Azure DevOps 管道状态,
> 以及通过自然语言工具进行警报评估。
[](https://github.com/oaslananka/health-monitor-mcp/actions/workflows/ci.yml)
[](https://github.com/oaslananka/health-monitor-mcp/actions/workflows/release.yml)
[](LICENSE)
[](https://scorecard.dev/viewer/?uri=github.com/oaslananka/health-monitor-mcp)
[](https://nodejs.org)
## 功能描述
`health-monitor-mcp` 维护一个您关心的 MCP 服务器注册表,对它们执行实时的 MCP 握手,记录 SQLite 中的健康历史,并通过 MCP 工具报告在线时间、延迟和警报阈值。它还跟踪 Azure DevOps 管道,以便可以在同一位置检查应用程序健康和交付健康。
## 快速开始
第一个公开的 npm 发布目标是 `health-monitor-mcp@1.0.0`。如果 npm 仍返回 `E404`,则发布门控尚未完成。
```bash
npm install -g health-monitor-mcp
health-monitor-mcp --version
```
安装软件包后的示例桌面 MCP 客户端条目:
```json
{
"name": "健康监控 MCP",
"version": "1.0.0",
"mcpName": "io.github.oaslananka/health-monitor-mcp",
"description": "监控 MCP 服务器健康、在线时间、响应时间和 Azure DevOps 管道",
"transport": "stdio",
"command": "health-monitor-mcp",
"args": []
}
```
## 工具参考
| 工具 | 用途 | 典型提示 |
| ---- | ------- | -------------- |
| `register_server` | 保存要监控的 MCP 服务器 | `注册 https://example.com/mcp 为 prod-gateway` |
| `check_server` | 对单个服务器运行实时健康检查 | `立即检查 prod-gateway` |
| `check_all` | 检查所有已注册的服务器 | `检查我所有的 MCP 服务器` |
| `get_uptime` | 返回在线时间和延迟统计信息 | `显示 prod-gateway 24 小时在线时间` |
| `get_dashboard` | 返回 JSON 仪表盘数据 | `给我一个 24 小时仪表盘` |
| `get_report` | 返回 Markdown 报告 | `为 24 小时生成 Markdown 健康报告` |
| `list_servers` | 显示已注册的服务器 | `列出所有受监控的服务器` |
| `unregister_server` | 删除服务器 | `停止监控 local-debugger` |
| `set_alert` | 配置阈值 | `如果 prod-gateway 超过 500 毫秒或低于 99% 在线时间,则发出警报` |
| `get_monitor_stats` | 显示监控级别的统计信息 | `监控器记录了多少次检查?` |
| `register_azure_pipelines` | 注册 Azure 管道组 | `跟踪我的存储库的 CI 和发布管道` |
| `check_pipeline_status` | 读取最新的 Azure 管道运行情况 | `检查我的发布组的管道状态` |
| `get_pipeline_logs` | 获取 Azure 构建日志 | `显示最新发布的失败日志` |
| `check_all_projects` | 结合 MCP 和 Azure 健康状况 | `检查所有项目` |
## Azure DevOps 集成
使用组织、项目、管道名称和 PAT 注册管道组:
```text
register_azure_pipelines 名称="健康监控 MCP" 组织="oaslananka" 项目="开源" pipeline_names=["健康监控 CI","发布 npm"] pat_token="..."
```
当设置 `HEALTH_MONITOR_ENCRYPTION_KEY` 时,PAT 令牌会使用 AES-256-GCM 在本地 SQLite 数据库中加密。当显式设置 `HEALTH_MONITOR_ALLOW_INSECURE_PAT_STORAGE=1` 时,提供本地不安全的存储。参见 [credential storage notes](https://github.com/oaslananka/health-monitor-mcp/blob/main/docs/security.md)。
## 警报配置
使用 `set_alert` 配置单个服务器:
| 字段 | 含义 |
| ----- | ------- |
| `max_response_time_ms` | 当检查超过此延迟时发出警报 |
| `min_uptime_percent` | 当选定的在线时间窗口低于此值时发出警报 |
| `consecutive_failures_before_alert` | 在连续出现此次数的非正常结果后发出警报 |
警报由 `check_server`、`check_all` 和 `get_dashboard` 内联评估。Webhook 交付计划在 v1.1 中实现,v1.0.x 中不附带 Webhook MCP 工具。
## 数据存储
- 默认数据库路径:`~/.mcp-health-monitor/health.db`
- 重写路径:`HEALTH_MONITOR_DB=/custom/path/health.db`
- 可选后台调度器:`HEALTH_MONITOR_AUTO_CHECK=1`
- HTTP MCP 端点令牌:`HEALTH_MONITOR_HTTP_TOKEN=...`
- HTTP 绑定主机:默认为 `127.0.0.1`
- 远程安全配置文件:`HEALTH_MONITOR_PROFILE=remote-safe`
- 远程 HTTP 源允许列表:`HEALTH_MONITOR_HTTP_ORIGIN_ALLOWLIST=https://client.example`
- 可选有状态 HTTP 会话:`HEALTH_MONITOR_HTTP_STATEFUL_SESSIONS=1`
- 有状态 HTTP 会话 TTL:默认为 `HEALTH_MONITOR_HTTP_SESSION_TTL_MS=1800000`
- 有状态 HTTP 会话上限:默认为 `HEALTH_MONITOR_HTTP_MAX_SESSIONS=100`
- 本地 stdio 检查选择加入:`HEALTH_MONITOR_ALLOW_STDIO=1`
- 可选 stdio 命令允许列表:`HEALTH_MONITOR_STDIO_ALLOWLIST=node,npx`
- HTTP 服务器健康端点:`GET /health`
配置由环境变量驱动;直接在您的 shell、服务管理器或 MCP 客户端环境块中使用上述变量。_stdio 监控启动本地子进程,除非设置 `HEALTH_MONITOR_ALLOW_STDIO=1` 或嵌入式应用程序通过运行时策略显式启用。保持可执行文件在 `command` 中,并将参数放在 `args` 中;例如,使用 `command="npx" args=["mcp-debug-recorder"]`。
数据库在文件支持的数据库上使用 WAL 模式,并在启动时自动应用模式迁移。
## Docker
构建和运行:
```bash
docker build -t health-monitor-mcp .
docker run --rm health-monitor-mcp node dist/mcp.js --version
```
HTTP 模式默认绑定到环回地址。对于远程 HTTP 部署,需要一个承载令牌、远程安全配置文件和源允许列表:
```bash
docker run --rm \
-p 127.0.0.1:3000:3000 \
-e HOST=0.0.0.0 \
-e HEALTH_MONITOR_PROFILE=remote-safe \
-e HEALTH_MONITOR_HTTP_TOKEN=change-me \
-e HEALTH_MONITOR_HTTP_ORIGIN_ALLOWLIST=https://client.example \
health-monitor-mcp
curl -X POST \
--oauth2-bearer "$HEALTH_MONITOR_HTTP_TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' \
http://127.0.0.1:3000/mcp
```
## 开发
```bash
corepack enable
corepack prepare pnpm@11.0.9 --activate
pnpm install --frozen-lockfile
pnpm run build
pnpm test
pnpm run test:integration
pnpm run lint
pnpm run lint:test
pnpm run format:check
pnpm run test:coverage
pnpm run docs:api:check
pnpm run ci
```
运行时支持 Node 24 LTS 或更新版本。CI、Docker、软件包元数据和本地开发命令都与 Node `>=24` 对齐。
## 架构
高级别模块映射:
- `src/app.ts`: MCP 工具注册和响应格式化
- `src/checker.ts`: 实时 MCP 连接性探测,带有重试/回退
- `src/registry.ts`: 服务器、检查和管道记录的 SQLite 读取/写入路径
- `src/db.ts` + `src/migrations.ts`: 连接设置和模式升级
- `src/server-http.ts` + `src/mcp.ts`: 本地 MCP 客户端和打包 CLI 使用的 HTTP 和 stdio 入口点
- `src/scheduler.ts`: 可选的后台自动检查循环
更多细节参见 [architecture.md](https://github.com/oaslananka/health-monitor-mcp/blob/main/docs/architecture.md)。决策理由参见 [docs/adr](https://github.com/oaslananka/health-monitor-mcp/blob/main/docs/adr/README.md),生成的 API 文档参见 [docs/api](https://github.com/oaslananka/health-monitor-mcp/blob/main/docs/api/README.md)。
## 路线图
详细的里程碑规划参见 [ROADMAP.md](https://github.com/oaslananka/health-monitor-mcp/blob/main/ROADMAP.md)。
- [x] v1.0:核心监控、在线时间、警报、Azure 管道、Markdown 报告
- [ ] v1.1:Slack、Discord 和自定义端点的 Webhook 通知
- [ ] v1.2:多提供商管道和通用 HTTP 监控
- [ ] v2.0:多用户支持和可选的外部机密提供程序集成
## 安全
阅读 [SECURITY.md](https://github.com/oaslananka/health-monitor-mcp/blob/main/SECURITY.md) 以获取漏洞报告,并阅读 [docs/security.md](https://github.com/oaslananka/health-monitor-mcp/blob/main/docs/security.md) 以获取特定于实现的存储详细信息。
## 贡献
参见 [contributing.md](https://github.com/oaslananka/health-monitor-mcp/blob/main/docs/contributing.md) 以获取设置、标准和 PR 期望。治理、三级标签和维护者响应目标在 [governance.md](https://github.com/oaslananka/health-monitor-mcp/blob/main/docs/governance.md) 中有文档。使用问题表单进行跟踪工作。
## 许可证
MIT