Skip to main content
Glama
README.md
# opsprobe

**Let an AI agent investigate production, without handing it the keys.**

[![ci](https://github.com/narkhedeakshay26/opsprobe/actions/workflows/ci.yml/badge.svg)](https://github.com/narkhedeakshay26/opsprobe/actions/workflows/ci.yml)
![python](https://img.shields.io/badge/python-3.10%2B-blue)
![MCP](https://img.shields.io/badge/MCP-server-purple)
![license](https://img.shields.io/badge/license-MIT-green)

opsprobe is an [MCP](https://modelcontextprotocol.io) server that gives AI assistants (Claude Code,
Claude Desktop, any MCP client) a **fixed set of safe diagnostic tools** for your systems: metrics,
logs, health checks, read-only host checks and your team's runbooks. It wraps every call in
guardrails, and **anything that changes something waits for a person to approve that exact command.**

---

## In one minute

AI assistants are good at incident triage: they read metrics and logs quickly and connect the dots.
But the usual way to let one help is to give it a shell, and then it can run *anything* on
*any* host, with nobody watching. Most teams rightly say no.

opsprobe is the middle ground:

| The agent can | The agent cannot |
|---|---|
| Query Prometheus and Loki (time ranges and output capped) | Reach any host, URL or command that isn't in `opsprobe.yaml` |
| Hit allowlisted health endpoints | Pass arguments outside their allowed patterns (no `; rm -rf /`) |
| Run read-only checks (`df`, log tail, `/proc`…) on listed hosts | Change anything without a person approving that exact command |
| Run your team's runbooks step by step | Approve its own request: approval exists only in a human-run CLI |
| Request a change, such as a restart | See secrets: tokens, keys and passwords are redacted before it sees them |

**Every call is written to an audit log**: who asked what, on which target, and whether it was allowed.

---

## See it work (5 minutes)

The demo is a fictional two-service shop. **checkout** places an order every half second by calling
**payments**. Payments has a bug: it leaks one pooled connection every few charges, and after about a
minute the pool is empty and every order fails.

```bash
git clone https://github.com/narkhedeakshay26/opsprobe.git && cd opsprobe
pip install -e .
docker compose -f examples/demo/docker-compose.yml up -d     # shop + Prometheus + Loki
```

**Connect an agent.** For Claude Code:

```bash
claude mcp add opsprobe -- opsprobe serve -c "$PWD/examples/demo/opsprobe.yaml"
```

(Claude Desktop: see [docs/connecting.md](docs/connecting.md).) Then ask:

> *"Checkout is failing orders. Find out why and fix it."*

What happens:

1. The agent calls `list_targets`, sees the `checkout-failing` runbook and runs it.
2. The runbook's probes show:
   - payments health `503`;
   - `payments_pool_in_use` at 20/20;
   - log lines `connection pool exhausted (20/20 in use)`.
3. The agent calls `request_action restart_container container=shop-payments` and tells you:
   ```
   PENDING APPROVAL 7f3a9c21
     action:  restart_container
     host:    docker-host
     command: docker restart shop-payments
   ```
4. **You** approve it in a terminal. That's the only way it can be approved:
   ```bash
   opsprobe approve 7f3a9c21 -c examples/demo/opsprobe.yaml
   ```
5. The agent calls `execute_approved`. Payments restarts and checkout recovers. The runbook also
   tells the agent the restart is only a band-aid because the leak is the real bug, so it should
   say so.
6. Review everything that happened:
   ```bash
   opsprobe audit -c examples/demo/opsprobe.yaml
   ```

**No agent handy?** Call the same tools yourself, exactly as the agent would:

```bash
opsprobe call -c examples/demo/opsprobe.yaml run_runbook name=checkout-failing
opsprobe call -c examples/demo/opsprobe.yaml run_check host=payments check=app_log lines=5
opsprobe call -c examples/demo/opsprobe.yaml run_check host=payments check=app_log_head lines=3   # watch the api_key get redacted
```

CI runs this whole scenario on every push ([`tests/e2e_demo.sh`](tests/e2e_demo.sh)): the shop
breaks, the runbook finds the cause, the approval flow restarts payments, and health returns to 200.

---

## How it works

```mermaid
flowchart LR
    A["AI agent<br/>(any MCP client)"] -- tool call --> G
    subgraph G["opsprobe"]
        direction TB
        R[rate limit] --> L[allowlists<br/>hosts · checks · URLs · arg patterns]
        L --> X[run]
        X --> S[redact secrets] --> C[cap output] --> AU[(audit log)]
    end
    X --> P[(Prometheus)]
    X --> Lo[(Loki)]
    X --> H[hosts<br/>docker exec · ssh · local]
    G -- text result --> A
    A -. request_action .-> Q[(pending approvals)]
    U["👤 person"] -- "opsprobe approve &lt;id&gt;" --> Q
    Q -. approved, once .-> X
```

### The tools the agent sees

| Tool | What it does | Guardrails |
|---|---|---|
| `list_targets` | Everything the agent may touch | – |
| `prom_query` | PromQL; instant, or a range summarised per series (last/min/max) | max range, max series |
| `loki_search` | LogQL, newest first | stream selector required, max range, max lines |
| `http_check` | GET a URL: status, latency, start of body | URL allowlist (globs), timeout |
| `run_check` | Run one named read-only command on one host | host and check allowlists, argument regexes, no shell |
| `list_runbooks` / `run_runbook` | Run a Markdown runbook's probes in order | every probe goes through the same guards |
| `request_action` | Ask for a change; returns an approval id | action and host allowlists, argument regexes, reason required |
| `execute_approved` | Run an approved action | once, before expiry, only if the command still matches exactly |

Every tool returns plain text written for a model. A refusal says what *is* allowed, so the agent
can correct itself instead of guessing:
`DENIED: host 'db-9' is not allowed. Allowed hosts: checkout, payments, docker-host`.

---

## Safety model

| Risk | How opsprobe handles it |
|---|---|
| Agent runs an arbitrary command | It can't: only named commands from `checks:` exist. Checks that look like changes (`rm`, `sudo`, `restart`, `curl`…) are **refused when the config loads** |
| Shell injection through arguments | Commands are split into arguments *before* values go in and run **without a shell**. Every value must fully match its regex. Over SSH every argument is quoted |
| Agent acts on the wrong machine | Hosts are an allowlist. An approval is bound to **one action + one host + the exact command** (SHA-256); any change in between voids it |
| Agent approves its own request | There is **no approve tool**. Approval only happens through `opsprobe approve`, run by a person |
| An approval reused or left lying around | Single use (marked used *before* running), and it expires (15 min by default) |
| Secrets reach the model | Built-in redaction (private keys, AWS keys, JWTs, bearer tokens, `password=`/`token=`/`api_key=`, URL credentials) plus your own patterns, applied to every output and to the audit log |
| Huge output or a looping agent | Output capped per call; calls per minute capped |
| "What did the AI do last night?" | JSON-lines audit log of every call, refusal, request, approval and execution |
| Something left running on servers | Nothing is installed or left running: every call is one short command |

**One thing you must do yourself:** keep the approval channel out of the agent's reach. If the same
agent also has an unrestricted shell on the machine where `opsprobe approve` works, it could run that
command itself. Run opsprobe where that agent has no shell, or as a different user. See
[docs/security.md](docs/security.md).

---

## Use it on your systems

1. **Write `opsprobe.yaml`.** Start from [`examples/demo/opsprobe.yaml`](examples/demo/opsprobe.yaml):
   every key is commented.
   ```yaml
   prometheus: { url: http://prometheus:9090 }
   loki:       { url: http://loki:3100 }
   http_check: { allow: ["https://*.internal.example/health"] }
   hosts:
     web-1: { executor: ssh, address: 10.0.0.11, user: probe, key_file: ~/.ssh/probe }
   checks:
     service_status: "systemctl status {unit} --no-pager"
     journal:        "journalctl -u {unit} -n {lines} --no-pager"
     disk:           "df -h"
   actions:
     restart_service: { command: "sudo systemctl restart {unit}", hosts: [web-1] }
   args:
     unit: "(nginx|api|worker)\\.service"
   runbooks: runbooks/
   ```
   Use a **dedicated read-only account** on hosts, plus one narrow sudo rule for the approved actions.
2. **Validate it:** `opsprobe check -c opsprobe.yaml`.
3. **Try the tools yourself:** `opsprobe call -c opsprobe.yaml list_targets`.
4. **Write runbooks** for your common incidents ([docs/runbooks.md](docs/runbooks.md)). A runbook is
   the best way to make an agent investigate the way *your team* would.
5. **Connect your MCP client** ([docs/connecting.md](docs/connecting.md)).

---

## CLI

```
opsprobe serve  [-c cfg] [--transport stdio|http]   run the MCP server
opsprobe tools                                       the tool descriptions the agent sees
opsprobe call   [-c cfg] TOOL key=value ...          call a tool yourself
opsprobe pending [-c cfg]                            approval requests waiting
opsprobe approve|deny [-c cfg] ID [--yes]            decide one (shows the exact command first)
opsprobe audit  [-c cfg] [--tail N]                  read the audit log
opsprobe check  [-c cfg]                             validate the config and runbooks
```

## Project layout

```
opsprobe/
├── opsprobe/
│   ├── config.py      opsprobe.yaml: allowlists, refuses unsafe checks at load time
│   ├── guard.py       rate limit, secret redaction, output cap, audit log
│   ├── tools.py       the tools (one guarded path for all of them)
│   ├── executors.py   local / docker exec / ssh, never through a shell
│   ├── approvals.py   request → human approve → execute once
│   ├── runbooks.py    Markdown runbooks with ```probe blocks
│   ├── server.py      MCP server (FastMCP), no approval tool by design
│   └── cli.py
├── examples/demo/     fictional shop, Prometheus, Loki, config, runbooks
├── docs/              security · runbooks · connecting
└── tests/             guardrail, tool and approval tests + a full end-to-end demo run in CI
```

## Docs

- [Security model](docs/security.md)
- [Writing runbooks](docs/runbooks.md)
- [Connecting Claude Code, Claude Desktop and other MCP clients](docs/connecting.md)

## Roadmap

- More back ends: Kubernetes (pods, events, logs) and Kafka consumer lag, read-only
- Approval through Slack buttons, in addition to the CLI
- Per-user identity on the HTTP transport (who asked, not just what)

MIT licensed. See [LICENSE](LICENSE).