内容
# logicmonitor-mcp
一款模型上下文协议(MCP)服务器,暴露 [LogicMonitor REST API](https://www.logicmonitor.com/swagger-ui-master/api-v3/dist/swagger.json) 作为LLM可以调用的工具。 以Docker镜像形式发布,通过stdio运行。
## 功能暴露
大约40个便捷、精选的工具,涵盖主要资源领域:
| 领域 | 工具 |
|---|---|
| 设备 | `list_devices`, `get_device`, `create_device`, `update_device`, `delete_device`, `get_device_properties`, `set_device_property`, `delete_device_property`, `list_device_instances`, `list_device_alerts` |
| 设备组 | `list_device_groups`, `get_device_group`, `create_device_group`, `update_device_group`, `delete_device_group`, `list_devices_in_group`, `list_device_group_properties`, `set_device_group_property` |
| 警报 | `list_alerts`, `get_alert`, `ack_alert`, `ack_alerts_bulk`, `add_alert_note` |
| SDTs | `list_sdts`, `get_sdt`, `create_sdt`, `update_sdt`, `delete_sdt` |
| 仪表盘 | `list_dashboards`, `get_dashboard`, `list_dashboard_groups`, `get_dashboard_group`, `list_widgets`, `get_widget`, `get_widget_data` |
| 报告 | `list_reports`, `get_report`, `run_report`, `get_report_task`, `list_report_groups` |
| 数据源 | `list_datasources`, `get_datasource`, `list_device_datasources`, `list_device_datasource_instances`, `get_instance_data`, `list_datasource_instance_groups` |
| 收集器 | `list_collectors`, `get_collector`, `update_collector`, `delete_collector`, `list_collector_groups`, `get_collector_group`, `list_collector_versions` |
| 用户和角色 | `list_users`, `get_user`, `create_user`, `update_user`, `delete_user`, `list_roles`, `get_role`, `list_api_tokens` |
| 网站 | `list_websites`, `get_website`, `create_website`, `update_website`, `delete_website`, `list_website_groups`, `get_website_group`, `get_website_checkpoint_data` |
| 审计和运维笔记 | `list_audit_logs`, `get_audit_log`, `list_ops_notes`, `create_ops_note` |
另外三个通用工具提供了对规范中其他所有端点的完全覆盖:
- `lm_list_tags` — 列出所有资源标签及其端点数量
- `lm_list_endpoints` — 发现端点(可按标签或子字符串筛选)
- `lm_describe_endpoint` — 显示任意端点的参数/正文架构
- `lm_api_request` — 调用任意LM REST端点,支持任意方法/路径/查询/正文
OpenAPI规范与镜像捆绑在一起,因此发现功能可在离线状态下使用。
## 配置
设置两个环境变量。在LogicMonitor的 **设置 → 用户和角色 → API令牌** 中生成一个Bearer令牌。
| 变量 | 必需 | 描述 |
|---|---|---|
| `LM_ACCOUNT` | 是 | 门户前缀 — `<account>` in `<account>.logicmonitor.com` |
| `LM_BEARER_TOKEN` | 是 | Bearer令牌 (`lmb_…`) |
| `LM_API_VERSION` | 否 | API版本头。默认 `3` |
| `LM_HTTP_TIMEOUT` | 否 | 请求超时(秒)。默认 `30` |
参见 `.env.example`。
## 构建
```bash
docker build -t logicmonitor-mcp .
```
## 运行
服务器通过stdio进行MCP通信,因此客户端启动容器。传递 `-i`(交互式)以保持stdin打开,并传递 `--rm` 以在客户端断开连接时清理容器:
```bash
docker run --rm -i \
-e LM_ACCOUNT=yourcompany \
-e LM_BEARER_TOKEN=lmb_xxxxxxxx \
logicmonitor-mcp
```
### Claude Desktop / Claude Code
添加到您的MCP配置(`~/Library/Application Support/Claude/claude_desktop_config.json` on macOS, 或 `~/.claude.json`):
```json
{
"mcpServers": {
"logicmonitor": {
"command": "docker",
"args": [
"run", "--rm", "-i",
"-e", "LM_ACCOUNT",
"-e", "LM_BEARER_TOKEN",
"logicmonitor-mcp"
],
"env": {
"LM_ACCOUNT": "yourcompany",
"LM_BEARER_TOKEN": "lmb_xxxxxxxx"
}
}
}
}
```
## 在本地运行,无需Docker
```bash
pip install -e .
export LM_ACCOUNT=yourcompany LM_BEARER_TOKEN=lmb_xxxxxxxx
python -m logicmonitor_mcp
```
## 过滤器说明
LogicMonitor使用查询字符串筛选语法。以下是几个快速示例:
- `displayName:"web-*"` — 显示名称以 `web-` 开头的设备
- `severity>=3` — 警告级别为警告或更高
- `cleared:"false",acked:"false"` — 打开的、未确认的警报(逗号 = 与)
- `hostStatus:"normal"|hostStatus:"dead"` — 管道 = 或
将筛选器传递给任何接受 `filter` 参数的工具。
## 变更
此服务器暴露了完整的CRUD接口 — `create_*`、`update_*`、`delete_*` 工具和通用 `lm_api_request` 可以写入您的LogicMonitor门户。确保Bearer令牌的角色权限与您希望LLM具有的访问级别相匹配,并且在需要写入时优先使用只读角色。