@solomonneas/librenms-mcp 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,47 +1,142 @@
1
- # librenms-mcp
1
+ <p align="center">
2
+ <img src="docs/assets/librenmsctrl-social-preview.jpg" alt="librenmsctrl banner" width="900">
3
+ </p>
2
4
 
3
- MCP server exposing LibreNMS read + safe-write tools via API token auth. Three-tier write gating: reads are open, writes require `confirm: true`, destructive ops would require `confirm: true` + `destructive: true` (v1 ships tier 1 + tier 2 only; tier 3 destructive ops are deferred).
5
+ <h1 align="center">librenmsctrl</h1>
4
6
 
5
- ## Tools
7
+ <p align="center">
8
+ <strong>An operator control CLI for LibreNMS: inspect devices, ports, port health, alerts, and events over API-token auth, with an MCP adapter for agent workflows.</strong>
9
+ </p>
6
10
 
7
- **Reads (10):** `librenms_status`, `librenms_list_devices`, `librenms_get_device`, `librenms_list_ports`, `librenms_get_port`, `librenms_port_health`, `librenms_list_alerts`, `librenms_get_alert`, `librenms_alert_history`, `librenms_event_log`.
11
+ <p align="center">
12
+ <a href="https://lidless.dev/librenms-mcp"><strong>Website &rarr; lidless.dev/librenms-mcp</strong></a>
13
+ </p>
8
14
 
9
- **Safe writes (3, require `confirm: true`):** `librenms_ack_alert`, `librenms_unmute_alert`, `librenms_set_maintenance`.
15
+ <p align="center">
16
+ <img src="https://shieldcn.dev/npm/@solomonneas/librenms-mcp.svg" alt="npm version">
17
+ <img src="https://shieldcn.dev/badge/ctrl-CLI-2563EB.svg" alt="control CLI">
18
+ <img src="https://shieldcn.dev/badge/MCP-compatible-8A2BE2.svg" alt="MCP compatible">
19
+ <img src="https://shieldcn.dev/badge/license-MIT-green.svg" alt="MIT license">
20
+ </p>
10
21
 
11
- **Destructive (tier 3):** not in v1. Operations like device deletion, alert rule removal, and bulk port resets are intentionally absent until the gate pattern has more field time.
22
+ librenmsctrl is a local operator control CLI for [LibreNMS](https://www.librenms.org/), the open-source network monitoring system. It gives shells, cron, and CI a typed command surface for reading your monitored network: devices, ports, port health, alerts, alert history, and the event log over LibreNMS API-token auth.
12
23
 
13
- ## Configuration
24
+ The same package remains MCP-compatible for agent workflows. `librenmsctrl mcp` starts the stdio [Model Context Protocol](https://modelcontextprotocol.io) adapter, and the existing `librenms-mcp` binary continues to work for launchers and configs that already use it. The MCP adapter can acknowledge or mute alerts only when you pass an explicit `confirm: true`. It differs from pointing an agent at the raw LibreNMS REST API in one way that matters: every write is gated, every argument is schema-validated before it leaves the host, and your token is redacted from all output, so a hallucinated tool call cannot change your monitoring state by accident.
14
25
 
15
- Set the following env vars. Both credential vars are required.
26
+ > **Status: work in progress.** v1 ships read tools (tier 1) and confirm-gated safe writes (tier 2) only. Destructive operations (tier 3) such as device deletion, alert-rule removal, and bulk port resets are intentionally deferred until the write-gate pattern has more field time. Treat it as early but usable; the read path and the two write gates are tested.
16
27
 
17
- ```
18
- LIBRENMS_URL=https://librenms.example.local
19
- LIBRENMS_TOKEN=<your-api-token>
28
+ ## What it does
20
29
 
21
- # Optional: skip TLS cert validation (homelab self-signed certs).
22
- # Accepts true/1/yes (case-insensitive). Defaults to false.
23
- LIBRENMS_TLS_INSECURE=false
24
- ```
30
+ librenmsctrl turns a [LibreNMS](https://www.librenms.org/) instance into a scriptable control surface for network monitoring and observability work: list the devices LibreNMS is polling over SNMP, pull a single device or port, check port health and utilization, read current alerts and alert history, and tail the event log. It authenticates with a LibreNMS API token, talks to the LibreNMS `/api/v0` REST API under the hood, and can emit human-readable tables or raw JSON for piping.
25
31
 
26
- Trailing slashes on `LIBRENMS_URL` are stripped. The API token is registered with the redactor on startup and masked from all log + error output.
32
+ For MCP clients, the `mcp` subcommand exposes the same LibreNMS client core as structured tool output an agent can reason over. The package name is still `@solomonneas/librenms-mcp`, and the back-compat `librenms-mcp` bin is intentionally kept stable.
27
33
 
28
- ## Install
34
+ Writes are gated in three tiers:
29
35
 
30
- ```
36
+ - **Tier 1 (reads)**: open. No confirm flag. Status, device and port listings, single device or port, port health, alert listings, alert history, event log.
37
+ - **Tier 2 (safe writes)**: require an explicit `confirm: true` argument, documented on every write tool's JSON schema. Acknowledge an alert, unmute an alert, or put a device into a maintenance window. A tool call missing the flag throws `WriteGateError` before any HTTP traffic leaves the host.
38
+ - **Tier 3 (destructive)**: not implemented in v1. When added, ops like device deletion and alert-rule removal will additionally require `destructive: true`. The model cannot bypass either gate from a hallucinated call.
39
+
40
+ Every tool call is validated against its published TypeBox `inputSchema` before the tool runs. Ids, port ids, device ids, limits, and the `type`/`state` filters are bounds- and enum-checked, so a malformed or injection-style argument is rejected up front and never reaches a LibreNMS URL path or query string. Interpolated path and query values are additionally URL-encoded as defense-in-depth. The API token is registered with the redactor on startup and masked from all log and error output.
41
+
42
+ ## Quickstart
43
+
44
+ Published to npm as [`@solomonneas/librenms-mcp`](https://www.npmjs.com/package/@solomonneas/librenms-mcp). Install the package to get the `librenmsctrl` operator CLI and the back-compat `librenms-mcp` MCP launcher.
45
+
46
+ ```bash
47
+ # start the MCP adapter on demand through the back-compat `librenms-mcp` bin
48
+ npx -y @solomonneas/librenms-mcp
49
+
50
+ # install the global `librenmsctrl` and `librenms-mcp` binaries
31
51
  npm install -g @solomonneas/librenms-mcp
32
52
  ```
33
53
 
34
- Or run via npx:
54
+ It needs Node 20+ and two env vars, `LIBRENMS_URL` and `LIBRENMS_TOKEN`.
55
+
56
+ ```bash
57
+ export LIBRENMS_URL=https://librenms.example.local
58
+ export LIBRENMS_TOKEN=<your-api-token>
35
59
 
60
+ librenmsctrl status
61
+ librenmsctrl alerts list --state 1
62
+ librenmsctrl --json ports health --metric errors_in --limit 10
36
63
  ```
37
- npx -y @solomonneas/librenms-mcp
64
+
65
+ The MCP adapter speaks stdio. A quick way to confirm it starts is to feed it an MCP `tools/list` request:
66
+
67
+ ```bash
68
+ export LIBRENMS_URL=https://librenms.example.local
69
+ export LIBRENMS_TOKEN=<your-api-token>
70
+ echo '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | npx -y @solomonneas/librenms-mcp
38
71
  ```
39
72
 
40
- ## Setup
73
+ You should get back a JSON listing of the 13 tools above. In normal use you point an MCP client at the same command instead.
41
74
 
42
- ### Claude Desktop
75
+ ## Tools
76
+
77
+ The MCP adapter exposes 13 tools: 10 reads, 3 confirm-gated safe writes. This list is generated from the server's tool registration in [`mcp-server.ts`](mcp-server.ts).
78
+
79
+ **Reads (10, open):**
80
+
81
+ | Tool | What it does |
82
+ |---|---|
83
+ | `librenms_status` | LibreNMS instance status check. |
84
+ | `librenms_list_devices` | List monitored devices. |
85
+ | `librenms_get_device` | Fetch a single device by id. |
86
+ | `librenms_list_ports` | List ports across devices. |
87
+ | `librenms_get_port` | Fetch a single port detail. |
88
+ | `librenms_port_health` | Port health and utilization view. |
89
+ | `librenms_list_alerts` | List current alerts. |
90
+ | `librenms_get_alert` | Fetch a single alert by id. |
91
+ | `librenms_alert_history` | Historical alert records. |
92
+ | `librenms_event_log` | Read the device event log. |
93
+
94
+ **Safe writes (3, require `confirm: true`):**
95
+
96
+ | Tool | What it does |
97
+ |---|---|
98
+ | `librenms_ack_alert` | Acknowledge an active alert by id. |
99
+ | `librenms_unmute_alert` | Unmute a previously muted alert. |
100
+ | `librenms_set_maintenance` | Put a device into a maintenance window. |
101
+
102
+ ## Configuration
103
+
104
+ Set the following env vars. Both credential vars are required.
105
+
106
+ | Variable | Required | Default | Notes |
107
+ |---|---|---|---|
108
+ | `LIBRENMS_URL` | yes | - | Base URL of your LibreNMS instance. Trailing slashes are stripped. |
109
+ | `LIBRENMS_TOKEN` | yes | - | LibreNMS API token. Registered with the redactor on startup and masked from all output. |
110
+ | `LIBRENMS_TLS_INSECURE` | no | `false` | Skip TLS cert validation for homelab self-signed certs. Accepts `true`/`1`/`yes`, case-insensitive. |
111
+
112
+ ## CLI
113
+
114
+ `librenmsctrl` is the read-only operator **control CLI** for shells, cron, and CI. It shares the LibreNMS client core with the MCP adapter and talks to the same `/api/v0` API over token auth. It exposes only the read tools (tier 1); the confirm-gated writes (`ack`, `set_maintenance`, `unmute`) are intentionally not surfaced in the CLI.
115
+
116
+ ```bash
117
+ # installed globally as `librenmsctrl`, or via `npx -p @solomonneas/librenms-mcp librenmsctrl ...`
118
+ librenmsctrl status # instance health (exit 1 if no system data)
119
+ librenmsctrl devices list --type down
120
+ librenmsctrl devices get core-sw1
121
+ librenmsctrl ports list core-sw1
122
+ librenmsctrl ports get 42
123
+ librenmsctrl ports health --metric errors_in --limit 10
124
+ librenmsctrl alerts list --state 1 # 0=ok, 1=active, 2=ack
125
+ librenmsctrl alerts get 7
126
+ librenmsctrl alerts history --device-id 3 --limit 25
127
+ librenmsctrl events list --limit 50
128
+ librenmsctrl --json status # raw JSON for piping
129
+ ```
130
+
131
+ Run `librenmsctrl help` for the full flag list. It reads the same `LIBRENMS_URL`, `LIBRENMS_TOKEN`, and `LIBRENMS_TLS_INSECURE` env vars as the server. Exit codes: `0` success, `1` runtime error (LibreNMS unreachable, call failed, or `status` with no system data), `2` usage error (unknown command/flag or bad value).
43
132
 
44
- `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
133
+ ### Starting the MCP server
134
+
135
+ `librenmsctrl mcp` (or the back-compat `librenms-mcp` bin) starts the stdio MCP server. If a launcher referenced the file path `dist/mcp-server.js` directly, point it at `dist/mcp-bin.js` (or `dist/cli.js mcp`); launchers that use the `librenms-mcp` bin name need no change.
136
+
137
+ ## MCP client config
138
+
139
+ Copy-paste this into your MCP client. It is the canonical `mcpServers` shape used by Claude Desktop and Claude Code; both `LIBRENMS_URL` and `LIBRENMS_TOKEN` are required.
45
140
 
46
141
  ```json
47
142
  {
@@ -65,11 +160,30 @@ npx -y @solomonneas/librenms-mcp
65
160
  claude mcp add librenms -s user -- npx -y @solomonneas/librenms-mcp
66
161
  ```
67
162
 
68
- Then export env vars in your shell (`~/.bashrc`, `~/.zshrc`) or pass `--env` flags.
163
+ Then export `LIBRENMS_URL` and `LIBRENMS_TOKEN` in your shell (`~/.bashrc`, `~/.zshrc`) or pass `--env` flags on the `claude mcp add` line.
164
+
165
+ ### Claude Desktop
166
+
167
+ Add the `mcpServers` block above to `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows).
168
+
169
+ ### Codex CLI
170
+
171
+ `~/.codex/config.toml`:
172
+
173
+ ```toml
174
+ [mcp_servers.librenms]
175
+ command = "npx"
176
+ args = ["-y", "@solomonneas/librenms-mcp"]
177
+
178
+ [mcp_servers.librenms.env]
179
+ LIBRENMS_URL = "https://librenms.example.local"
180
+ LIBRENMS_TOKEN = "<your-api-token>"
181
+ LIBRENMS_TLS_INSECURE = "false"
182
+ ```
69
183
 
70
184
  ### OpenClaw
71
185
 
72
- Plugin loads automatically once installed. Config goes in your `~/.openclaw/openclaw.json` `plugins.entries.librenms` (or use the bundled `openclaw.plugin.json`):
186
+ The plugin loads automatically once installed. Config goes in your `~/.openclaw/openclaw.json` under `plugins.entries.librenms` (or use the bundled `openclaw.plugin.json`):
73
187
 
74
188
  ```json
75
189
  {
@@ -86,48 +200,42 @@ Plugin loads automatically once installed. Config goes in your `~/.openclaw/open
86
200
 
87
201
  Env vars from `~/.openclaw/workspace/.env` are inherited by the plugin.
88
202
 
89
- ### Hermes Agent
203
+ ## Safety
90
204
 
91
- Add to `~/.config/hermes/agents.yaml`:
205
+ This MCP uses a three-tier write-gating pattern:
92
206
 
93
- ```yaml
94
- mcp_servers:
95
- librenms:
96
- command: npx
97
- args: ["-y", "@solomonneas/librenms-mcp"]
98
- env:
99
- LIBRENMS_URL: https://librenms.example.local
100
- LIBRENMS_TOKEN: <your-api-token>
101
- LIBRENMS_TLS_INSECURE: "false"
102
- ```
207
+ - **Tier 1 (reads):** open. No confirm flag needed.
208
+ - **Tier 2 (safe writes):** require an explicit `confirm: true` arg. The JSON schema documents this on every write tool. A tool call without the confirm flag throws `WriteGateError` before any HTTP traffic.
209
+ - **Tier 3 (destructive):** not implemented in v1. When added, ops like device deletion, alert-rule removal, and bulk port resets will additionally require `destructive: true`.
103
210
 
104
- ### Codex CLI
211
+ **Input validation:** every tool call is validated against its published TypeBox `inputSchema` before the tool runs. Ids, port ids, device ids, limits, and the `type`/`state` filters are bounds- and enum-checked, so a malformed or injection-style argument (a non-integer id, an off-enum filter, an unexpected extra field) is rejected up front and never reaches a LibreNMS URL path or query string. Interpolated path and query values are additionally URL-encoded as defense-in-depth.
105
212
 
106
- `~/.codex/config.toml`:
213
+ **API token scope:** start with a "Read Only" token role in LibreNMS (Settings > API > New API Token > Read Only) and verify the read tools work end-to-end. Grade up to "Normal User" or "Global Read/Write" only after you have confirmed the redactor is masking your token in your transcripts and that the model is honoring the confirm gate. Tokens can be revoked instantly from the same Settings > API screen.
107
214
 
108
- ```toml
109
- [mcp_servers.librenms]
110
- command = "npx"
111
- args = ["-y", "@solomonneas/librenms-mcp"]
215
+ **TLS:** the `LIBRENMS_TLS_INSECURE=true` toggle exists for homelab self-signed certs. Leave it `false` in any environment with a real CA-signed cert.
112
216
 
113
- [mcp_servers.librenms.env]
114
- LIBRENMS_URL = "https://librenms.example.local"
115
- LIBRENMS_TOKEN = "<your-api-token>"
116
- LIBRENMS_TLS_INSECURE = "false"
117
- ```
217
+ See [SECURITY.md](SECURITY.md) for the vulnerability-reporting policy.
118
218
 
119
- ## Safety
219
+ ## Why not just point an agent at the LibreNMS API?
220
+
221
+ You can hand an agent a generic HTTP tool and the LibreNMS API token, and for read-only exploration that works. The difference shows up the moment a write is possible:
222
+
223
+ - **No write gate.** A generic HTTP tool will happily `PUT` or `DELETE` whatever the model decides to send. librenms-mcp refuses every write unless the call carries `confirm: true`, and refuses destructive shapes entirely in v1.
224
+ - **No input validation.** A raw API tool passes whatever the model produced straight into a URL. librenms-mcp bounds- and enum-checks every argument against a published schema and URL-encodes interpolated values before any request is built.
225
+ - **Token leakage.** A generic tool echoes request and response detail, including your token, into the transcript. librenms-mcp registers the token with a redactor on startup and masks it from all log and error output.
226
+ - **Shaped tools beat one giant endpoint.** Thirteen named, described tools give the model a far better surface to reason over than one `call this REST API` tool with a free-form path argument.
120
227
 
121
- This MCP uses the same three-tier write-gating pattern as the rest of the `solomonneas/*-mcp` family:
228
+ ## What librenms-mcp is not
122
229
 
123
- - **Tier 1 (reads):** open. No confirm flag needed. Status, device + port listings, single-port detail, port health, alert listings, alert history, event log.
124
- - **Tier 2 (safe writes):** require an explicit `confirm: true` arg. The JSON schema documents this on every write tool. Alert acknowledge/unmute and entering device maintenance live here. A hallucinated tool call without the confirm flag throws `WriteGateError` before any HTTP traffic.
125
- - **Tier 3 (destructive):** not implemented in v1. When added, ops like device deletion, alert rule removal, and bulk port resets will additionally require `destructive: true`. The model cannot bypass either gate from a hallucinated call.
230
+ - It is not a LibreNMS replacement or a poller. It reads an existing LibreNMS instance over the API; it does not collect SNMP itself.
231
+ - It is not a dashboard. Output is structured tool data for an agent, not a UI. For a NOC dashboard view, see [watchtower](https://github.com/solomonneas/watchtower).
232
+ - It does not delete devices, remove alert rules, or do bulk port resets. Tier-3 destructive operations are deliberately absent in v1.
233
+ - It is not a hosted service. It runs locally over stdio, talks only to the LibreNMS URL you configure, and starts no daemon.
126
234
 
127
- **API token scope recommendation:** start with a "Read Only" token role in LibreNMS (Settings > API > New API Token > Read Only) and verify the read tools work end-to-end. Grade up to "Normal User" or "Global Read/Write" only after you've confirmed the redactor is masking your token in your transcripts and that the model is honoring the confirm gate. Tokens can be revoked instantly from the same Settings > API screen.
235
+ ## Contributing
128
236
 
129
- The `LIBRENMS_TLS_INSECURE=true` toggle exists for homelab self-signed certs. Leave it `false` in any environment with a real CA-signed cert.
237
+ Patches welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for what lands easily, [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md), and the issue and PR templates under [.github/](.github). All public output should be scrubbed of personal hostnames, tokens, and real IPs.
130
238
 
131
239
  ## License
132
240
 
133
- MIT
241
+ [MIT](LICENSE).