feat: add lab-monitoring MCP server for Prometheus and Alertmanager
New MCP server that queries live Prometheus and Alertmanager HTTP APIs with 8 tools: list_alerts, get_alert, search_metrics, get_metric_metadata, query (PromQL), list_targets, list_silences, and create_silence. Extends the MCP core with ModeCustom and NewGenericServer for servers that don't require a database. Includes CLI with direct commands (alerts, query, targets, metrics), NixOS module, and comprehensive httptest-based tests. Bumps existing binaries to 0.2.1 due to shared internal/mcp change. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
74
CLAUDE.md
74
CLAUDE.md
@@ -20,7 +20,12 @@ Search and query NixOS configuration options. Uses nixpkgs as source.
|
||||
### Home Manager Options (`hm-options`)
|
||||
Search and query Home Manager configuration options. Uses home-manager repository as source.
|
||||
|
||||
All servers share the same architecture:
|
||||
### Lab Monitoring (`lab-monitoring`)
|
||||
Query Prometheus metrics and Alertmanager alerts. Unlike other servers, this queries live HTTP APIs — no database or indexing needed.
|
||||
- 8 tools: list/get alerts, search metrics, get metadata, PromQL query, list targets, list/create silences
|
||||
- Configurable Prometheus and Alertmanager URLs via flags or environment variables
|
||||
|
||||
The nixpkgs/options/hm servers share a database-backed architecture:
|
||||
- Full-text search across option/package names and descriptions
|
||||
- Query specific options/packages with full metadata
|
||||
- Index multiple revisions (by git hash or channel name)
|
||||
@@ -38,8 +43,9 @@ All servers share the same architecture:
|
||||
## Project Status
|
||||
|
||||
**Complete and maintained** - All core features implemented:
|
||||
- Full MCP servers with 6 tools each
|
||||
- PostgreSQL and SQLite backends with FTS
|
||||
- Full MCP servers (6 tools each for nixpkgs/options, 8 tools for monitoring)
|
||||
- PostgreSQL and SQLite backends with FTS (for nixpkgs/options servers)
|
||||
- Live API queries for Prometheus/Alertmanager (monitoring server)
|
||||
- NixOS modules for deployment
|
||||
- CLI for manual operations
|
||||
- Comprehensive test suite
|
||||
@@ -53,8 +59,10 @@ labmcp/
|
||||
│ │ └── main.go # Combined options+packages CLI (primary)
|
||||
│ ├── nixos-options/
|
||||
│ │ └── main.go # NixOS options CLI (legacy)
|
||||
│ └── hm-options/
|
||||
│ └── main.go # Home Manager options CLI
|
||||
│ ├── hm-options/
|
||||
│ │ └── main.go # Home Manager options CLI
|
||||
│ └── lab-monitoring/
|
||||
│ └── main.go # Prometheus/Alertmanager CLI
|
||||
├── internal/
|
||||
│ ├── database/
|
||||
│ │ ├── interface.go # Store interface (options + packages)
|
||||
@@ -82,15 +90,23 @@ labmcp/
|
||||
│ │ ├── indexer.go # Home Manager indexing
|
||||
│ │ ├── types.go # Channel aliases, extensions
|
||||
│ │ └── *_test.go # Indexer tests
|
||||
│ └── packages/
|
||||
│ ├── indexer.go # Nix packages indexing
|
||||
│ ├── parser.go # nix-env JSON parsing
|
||||
│ ├── types.go # Package types, channel aliases
|
||||
│ └── *_test.go # Parser tests
|
||||
│ ├── packages/
|
||||
│ │ ├── indexer.go # Nix packages indexing
|
||||
│ │ ├── parser.go # nix-env JSON parsing
|
||||
│ │ ├── types.go # Package types, channel aliases
|
||||
│ │ └── *_test.go # Parser tests
|
||||
│ └── monitoring/
|
||||
│ ├── types.go # Prometheus/Alertmanager API types
|
||||
│ ├── prometheus.go # Prometheus HTTP client
|
||||
│ ├── alertmanager.go # Alertmanager HTTP client
|
||||
│ ├── handlers.go # MCP tool definitions + handlers
|
||||
│ ├── format.go # Markdown formatting utilities
|
||||
│ └── *_test.go # Tests (httptest-based)
|
||||
├── nix/
|
||||
│ ├── module.nix # NixOS module for nixos-options
|
||||
│ ├── hm-options-module.nix # NixOS module for hm-options
|
||||
│ └── package.nix # Parameterized Nix package
|
||||
│ ├── module.nix # NixOS module for nixos-options
|
||||
│ ├── hm-options-module.nix # NixOS module for hm-options
|
||||
│ ├── lab-monitoring-module.nix # NixOS module for lab-monitoring
|
||||
│ └── package.nix # Parameterized Nix package
|
||||
├── testdata/
|
||||
│ └── options-sample.json # Test fixture
|
||||
├── flake.nix
|
||||
@@ -124,6 +140,19 @@ labmcp/
|
||||
| `list_revisions` | List all indexed revisions |
|
||||
| `delete_revision` | Delete an indexed revision |
|
||||
|
||||
### Monitoring Server (lab-monitoring)
|
||||
|
||||
| Tool | Description |
|
||||
|------|-------------|
|
||||
| `list_alerts` | List alerts with optional filters (state, severity, receiver) |
|
||||
| `get_alert` | Get full details for a specific alert by fingerprint |
|
||||
| `search_metrics` | Search metric names with substring filter, enriched with metadata |
|
||||
| `get_metric_metadata` | Get type, help text, and unit for a specific metric |
|
||||
| `query` | Execute instant PromQL query |
|
||||
| `list_targets` | List scrape targets with health status |
|
||||
| `list_silences` | List active/pending silences |
|
||||
| `create_silence` | Create a silence (confirms with user first) |
|
||||
|
||||
## Key Implementation Details
|
||||
|
||||
### Database
|
||||
@@ -212,6 +241,17 @@ hm-options delete <revision> # Delete indexed revision
|
||||
hm-options --version # Show version
|
||||
```
|
||||
|
||||
### lab-monitoring
|
||||
```bash
|
||||
lab-monitoring serve # Run MCP server on STDIO
|
||||
lab-monitoring serve --transport http # Run MCP server on HTTP
|
||||
lab-monitoring alerts # List alerts
|
||||
lab-monitoring alerts --state active # Filter by state
|
||||
lab-monitoring query 'up' # Instant PromQL query
|
||||
lab-monitoring targets # List scrape targets
|
||||
lab-monitoring metrics node # Search metric names
|
||||
```
|
||||
|
||||
### Channel Aliases
|
||||
|
||||
**nixpkgs-search/nixos-options**: `nixos-unstable`, `nixos-stable`, `nixos-24.11`, `nixos-24.05`, etc.
|
||||
@@ -220,6 +260,9 @@ hm-options --version # Show version
|
||||
|
||||
## Notes for Claude
|
||||
|
||||
### Planning
|
||||
When creating implementation plans, the first step should usually be to **checkout an appropriately named feature branch** (e.g., `git checkout -b feature/lab-monitoring`). This keeps work isolated and makes PRs cleaner.
|
||||
|
||||
### Development Workflow
|
||||
- **Always run `go fmt ./...` before committing Go code**
|
||||
- **Run Go commands using `nix develop -c`** (e.g., `nix develop -c go test ./...`)
|
||||
@@ -257,7 +300,8 @@ Version is defined in multiple places that must stay in sync:
|
||||
- `cmd/nixpkgs-search/main.go`
|
||||
- `cmd/nixos-options/main.go`
|
||||
- `cmd/hm-options/main.go`
|
||||
- `internal/mcp/server.go` (in `DefaultNixOSConfig`, `DefaultHomeManagerConfig`, `DefaultNixpkgsPackagesConfig`)
|
||||
- `cmd/lab-monitoring/main.go`
|
||||
- `internal/mcp/server.go` (in `DefaultNixOSConfig`, `DefaultHomeManagerConfig`, `DefaultNixpkgsPackagesConfig`, `DefaultMonitoringConfig`)
|
||||
- `nix/package.nix`
|
||||
|
||||
### User Preferences
|
||||
@@ -284,6 +328,7 @@ nix develop -c go test -bench=. -benchtime=1x -timeout=30m ./internal/homemanage
|
||||
nix build .#nixpkgs-search
|
||||
nix build .#nixos-options
|
||||
nix build .#hm-options
|
||||
nix build .#lab-monitoring
|
||||
|
||||
# Run directly
|
||||
nix run .#nixpkgs-search -- options serve
|
||||
@@ -291,6 +336,7 @@ nix run .#nixpkgs-search -- packages serve
|
||||
nix run .#nixpkgs-search -- index nixos-unstable
|
||||
nix run .#hm-options -- serve
|
||||
nix run .#hm-options -- index hm-unstable
|
||||
nix run .#lab-monitoring -- serve
|
||||
```
|
||||
|
||||
### Indexing Performance
|
||||
|
||||
Reference in New Issue
Block a user