brushtrail-mcp
by b0bc
README.md
# brushtrail-mcp
A small, **read-only** [MCP](https://modelcontextprotocol.io) server for a home lab. It gives Claude Desktop (or any MCP client) one endpoint with a curated set of tools for **Zabbix** and **Elasticsearch**, and you can add more sources as "packs".
- One endpoint, one token per client, one entry in Claude Desktop
- 12 focused tools instead of hundreds, so the model picks the right one
- Read-only by construction: Zabbix only gets `*.get` calls, Elasticsearch only gets `GET` and `_search`
- Stateless Streamable HTTP on the official MCP TypeScript SDK v2, with a fresh server instance per request
- Serves both current (2026-07-28) and 2025-era MCP clients, including `mcp-remote`
- JSON audit log line for every tool call (which client, which tool, args, duration, ok/error)
- Docker image built by GitHub Actions and published to GHCR
## Tools
| Tool | What it does |
|---|---|
| `zabbix_problems` | Unresolved problems now: host, severity, age, tags |
| `zabbix_recent_events` | Problems that started in the last N hours, resolved or ongoing, with duration |
| `zabbix_hosts` | Hosts with groups, maintenance, and interface availability (agent/SNMP up or down) |
| `zabbix_host_items` | Items on a host with latest values; finds the `itemid` for history |
| `zabbix_item_history` | Values over time with min/max/avg; falls back to hourly trends |
| `zabbix_triggers` | Triggers in PROBLEM state, or all triggers on a host |
| `elastic_cluster_health` | Status, shards, pending tasks, and why any shards are unassigned |
| `elastic_nodes` | Per-node roles, master, heap/RAM/CPU/disk, load |
| `elastic_indices` | Indices by size with health and doc counts |
| `elastic_aggregate` | Counts over time and top values of a field. Cheap, use first |
| `elastic_search` | Matching documents, newest first, long fields clipped |
| `homelab_check` | Can the server reach and authenticate to each backend? |
## Deploy on a VM
Needs Docker with the compose plugin.
```bash
git clone https://github.com/b0bc/brushtrail-mcp.git
cd brushtrail-mcp
cp .env.example .env
openssl rand -hex 32 # use the output as the claude-desktop token
nano .env # fill in tokens, Zabbix and Elasticsearch details
docker compose pull # or: docker compose build
docker compose up -d
docker compose logs -f # look for "listening" and "backend_ok"
curl http://localhost:3000/healthz
```
The GHCR image is published by the `ci` workflow on every push to `main`. **The first time the package is published it is private.** Either make it public (GitHub → your profile → Packages → `brushtrail-mcp` → Package settings → Change visibility), or run `docker login ghcr.io` on the VM with a token that has `read:packages`. You can also skip the registry: comment out `image:`, uncomment `build: .` in `docker-compose.yml`, and run `docker compose up -d --build`.
To update: `git pull && docker compose pull && docker compose up -d`.
### Private CA / self-signed certificates
If Zabbix or Elasticsearch use a private CA, copy the CA certificate to `./certs/ca.pem` and set `NODE_EXTRA_CA_CERTS=/certs/ca.pem` in `.env`. Don't turn off TLS verification.
## Backend credentials (read-only)
### Zabbix (6.4+ / 7.x)
1. **User group**: create e.g. `mcp-readers` with **Read** permission on the host groups the server should see.
2. **User role**: type *User*. Under *API methods*, choose *Allow list* and add `*.get` and `apiinfo.version`. The server never calls anything else, and this enforces it on the Zabbix side too.
3. **User**: create `mcp-reader` in that group with that role.
4. **API token**: Users → API tokens → create one for `mcp-reader` and put it in `ZABBIX_TOKEN`.
On Zabbix older than 6.4, set `ZABBIX_AUTH_MODE=body`.
### Elasticsearch
Create an API key limited to the indices you want readable, and keep `ELASTIC_INDEX_ALLOWLIST` the same:
```json
POST /_security/api_key
{
"name": "brushtrail-mcp",
"role_descriptors": {
"mcp_read": {
"cluster": ["monitor"],
"indices": [
{ "names": ["logs-*"], "privileges": ["read", "view_index_metadata", "monitor"] }
]
}
}
}
```
Put the `encoded` value from the response in `ELASTIC_API_KEY`. The API key is the real security boundary. The allowlist is a second fence that also stops the model from wandering into `*`.
## Connect clients
### Claude Desktop
Claude Desktop's own "custom connector" setting calls from Anthropic's cloud, so it can't reach a LAN-only VM. Instead, add the server to `claude_desktop_config.json` through the [`mcp-remote`](https://www.npmjs.com/package/mcp-remote) bridge, which runs on your PC. This needs Node.js installed.
```json
{
"mcpServers": {
"homelab": {
"command": "npx",
"args": [
"-y", "mcp-remote",
"http://mcp-vm.lan:3000/mcp",
"--header", "Authorization:${AUTH_HEADER}",
"--allow-http"
],
"env": { "AUTH_HEADER": "Bearer <claude-desktop token from .env>" }
}
}
}
```
If the server is behind a TLS reverse proxy (haproxy/nginx), use the `https://` URL and drop `--allow-http`. Restart Claude Desktop after editing.
### Claude Code
```bash
claude mcp add --transport http homelab http://mcp-vm.lan:3000/mcp \
--header "Authorization: Bearer <token>"
```
### MCP Inspector (testing)
```bash
npx @modelcontextprotocol/inspector
```
Choose *Streamable HTTP*, URL `http://mcp-vm.lan:3000/mcp`, and add an `Authorization: Bearer <token>` header.
### More clients
Give every client its own token so the audit log tells them apart:
```
MCP_TOKENS=claude-desktop=<hex>,holmes=<hex>,laptop=<hex>
```
## Configuration
All settings are environment variables; see [`.env.example`](.env.example).
| Variable | Default | Notes |
|---|---|---|
| `MCP_TOKENS` | required | `name=token,...`; tokens at least 24 characters |
| `PACKS` | `zabbix,elastic` | Which packs to load |
| `PORT` / `BIND_HOST` | `3000` / `0.0.0.0` | |
| `ALLOWED_HOSTS` | off | Accept only these `Host` headers (DNS-rebinding protection) |
| `TRUST_PROXY` | off | `1` or the proxy IP, when behind a reverse proxy |
| `MAX_OUTPUT_CHARS` | `60000` | Larger tool results are truncated with a hint |
| `LOG_LEVEL` | `info` | `debug`, `info`, `warn`, `error` |
| `ZABBIX_URL`, `ZABBIX_TOKEN` | required with zabbix pack | |
| `ZABBIX_AUTH_MODE` | `header` | `body` for Zabbix < 6.4 |
| `ELASTIC_URL` | required with elastic pack | |
| `ELASTIC_API_KEY` or `ELASTIC_USERNAME`/`ELASTIC_PASSWORD` | required with elastic pack | |
| `ELASTIC_INDEX_ALLOWLIST` | `*` (warns) | e.g. `logs-*,filebeat-*` |
| `ELASTIC_MAX_FIELD_CHARS` | `1500` | Long fields are clipped |
## Logs and audit
Logs are JSON lines on stdout/stderr (`docker compose logs`). Every tool call writes one record with `"audit": true`:
```json
{"ts":"2026-12-01T20:14:03.112Z","level":"info","msg":"tool_call","audit":true,"client":"claude-desktop","tool":"zabbix_problems","args":{"min_severity":"warning"},"ok":true,"durationMs":84,"outputChars":1532,"truncated":false}
```
Tokens and backend credentials are never logged.
## Adding a pack
1. Create `src/packs/<name>.ts` exporting a factory that returns `{ name, tools, check }`. See `zabbix.ts` for the pattern: read env with the helpers in `config.ts`, and define tools with `defineTool` and a zod input schema.
2. Register it in `src/packs/index.ts`.
3. Add it to `PACKS` and add its env vars to `.env.example`.
Keep tools read-only and their output small. Return summaries and let the model ask for detail.
## Development
```bash
npm install
npm test # end-to-end tests against mock Zabbix/Elasticsearch
npm run dev # watch mode; needs a .env exported into the shell
npm run build && npm start
```
## Security notes
- **Exposure.** Run on your LAN or behind a VPN/reverse proxy, not on the open internet. Bearer tokens are the only authentication.
- **Fresh server per request.** Each request builds a new `McpServer`, which avoids the cross-client data leak class fixed in SDK 1.26.0 (CVE-2026-25536).
- **Container hardening.** The container runs as a non-root user with a read-only filesystem, all capabilities dropped and `no-new-privileges`.
## License
MIT
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues