AI Agents for SRE: Agentic Ops for Routine Work, Safely

AI agents for SRE are good at the dull, well-bounded jobs nobody wants: chasing expiring certificates, triaging the ops ticket queue, summarising dependency bumps. Give them production write access too early and they become your next incident. By the end of this post you can pick safe agent tasks, expose internal tools through a read-only MCP server, add one scoped write, and log every call.
How agentic ops works
An agent is an LLM running in a loop: read a goal, pick a tool, inspect the result, decide the next step. Agentic ops points that loop at operational chores. The agent never holds admin credentials; it only sees the tools you expose.
The Model Context Protocol (MCP) is the standard plumbing: an MCP server publishes typed tools, and clients such as Claude Code call them. The diagram shows what this post builds.
Notice the two paths: reads use read-only credentials, while the single write waits for approval and logs itself first. That log is your record of what changed.
Which tasks suit AI agents for SRE
A good agent task is frequent, boring, easy to check and cheap to undo. A toil audit hands you the first candidates. Two questions sort the rest: how much damage can one wrong call do (the blast radius), and how fast can a human reverse it?
| Task | Blast radius | Undo | Agent role |
|---|---|---|---|
| Certificate expiry checks | None | Not needed | Run unattended |
| Ticket triage labels | One ticket | Seconds | Act after approval |
| Dependency bumps | One repo, behind CI | Revert the PR | Propose a draft PR |
| Restarts and scaling | One service | Mostly | Suggest only |
| Production data changes | Customers | Often impossible | Never |
Reads are safe to automate fully. Small, reversible writes such as a label or a draft PR are fine with review. Customer data, deletions and multi-service changes stay with humans. Restarts belong in deterministic auto-remediation with guardrails, not in a free-form LLM loop.
Expose internal tools through an MCP server, read-only first
Start with tools that cannot change anything. You learn how the agent behaves and how many tokens it burns, at zero risk. This server uses v2 of the MCP Python SDK (pip install "mcp[cli]"; on 1.x, import FastMCP instead) and exposes two certificate checks.
# sre_tools.py
import json, socket, ssl, subprocess, time
from mcp.server.mcpserver import MCPServer
from mcp.types import ToolAnnotations
mcp = MCPServer("sre-tools")
READ_ONLY = ToolAnnotations(readOnlyHint=True)
@mcp.tool(annotations=READ_ONLY)
def list_certificates(namespace: str) -> list[dict]:
"""cert-manager Certificates in a namespace: expiry, renewal time, Ready status."""
out = subprocess.run(["kubectl", "get", "certificates", "-n", namespace, "-o", "json"],
capture_output=True, text=True, check=True).stdout
rows = []
for c in json.loads(out)["items"]:
st = c.get("status", {})
ready = any(x["type"] == "Ready" and x["status"] == "True" for x in st.get("conditions", []))
rows.append({"name": c["metadata"]["name"], "notAfter": st.get("notAfter"),
"renewalTime": st.get("renewalTime"), "ready": ready})
return rows # only the fields the agent needs
@mcp.tool(annotations=READ_ONLY)
def cert_days_left(host: str, port: int = 443) -> int:
"""Days until the TLS certificate served at host:port expires."""
with socket.create_connection((host, port), timeout=5) as sock:
with ssl.create_default_context().wrap_socket(sock, server_hostname=host) as tls:
not_after = ssl.cert_time_to_seconds(tls.getpeercert()["notAfter"])
return int((not_after - time.time()) // 86400)
if __name__ == "__main__":
mcp.run() # stdio transport by default
The docstring is what the agent reads, so state exactly what each tool returns. readOnlyHint tells the client a tool changes nothing, but the MCP spec says clients must treat annotations as untrusted unless the server is trusted. The real guardrail is the credential: give the server a service account that can only read.
Register it with Claude Code. Everything after -- starts the server, and --env points kubectl at the read-only kubeconfig:
claude mcp add --transport stdio \
--env KUBECONFIG=/etc/sre-agent/readonly.kubeconfig \
sre-tools -- python3 /opt/sre-tools/sre_tools.py
claude mcp list # sre-tools should show as connected
Now ask the agent which certificates in the payments namespace are unhealthy. It calls list_certificates and answers with something like this:
payments-api-tls expires 2026-12-09 renewal 2026-11-09 ready: False
checkout-tls expires 2027-02-02 renewal 2027-01-03 ready: True
A renewal time in the past with a failed Ready condition means cert-manager tried to renew and failed, often on a broken DNS or HTTP challenge. If the server will not connect, run the Python command by hand; a missing package or an unreachable cluster is the usual cause. To test tools without an agent, uv run mcp dev sre_tools.py opens the MCP Inspector.
Add scoped writes behind human approval
After a few quiet weeks of reads, add one write: the smallest useful one. For ticket triage that is adding labels: it routes work to the right team, and a wrong label comes off in seconds. The flowchart shows every check a write passes.
Keep the scope in code, not in the prompt. This tool, added to sre_tools.py, accepts one repository and a fixed label set, writes an audit record, then calls the GitHub CLI.
import os
from pathlib import Path
TRIAGE_REPO = "acme/ops-tickets"
ALLOWED = {"team:platform", "team:network", "sev:3", "sev:4", "needs-info"}
AUDIT_LOG = Path(os.environ.get("AUDIT_LOG", "/var/log/sre-agent/audit.jsonl"))
def audit(tool: str, **args) -> None:
"""Append one JSON line per write attempt, before it runs."""
entry = {"ts": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()), "tool": tool, "args": args}
with AUDIT_LOG.open("a") as f:
f.write(json.dumps(entry) + "\n")
@mcp.tool(annotations=ToolAnnotations(readOnlyHint=False, destructiveHint=False, idempotentHint=True))
def label_ticket(number: int, labels: list[str], reason: str) -> str:
"""Add triage labels to one ops ticket. Explain the evidence in reason."""
if blocked := set(labels) - ALLOWED: # sev:1 and sev:2 stay human-only
raise ValueError(f"labels not allowed: {sorted(blocked)}")
audit("label_ticket", number=number, labels=labels, reason=reason)
subprocess.run(["gh", "issue", "edit", str(number), "--repo", TRIAGE_REPO,
"--add-label", ",".join(labels)], check=True, capture_output=True)
return f"#{number} labelled {', '.join(labels)}"
The allowlist runs first, so an agent that tries sev:1 gets the error back as its tool result and must ask a human. The reason argument makes it justify each call in the audit log. Give the server a GitHub token that can only triage this one repository, so the scope holds even if the code has a bug.
Next, make the client ask before every write. In .claude/settings.json, allow the reads, require confirmation for the write, and deny raw commands that bypass the server:
{
"permissions": {
"allow": ["mcp__sre-tools__list_certificates", "mcp__sre-tools__cert_days_left"],
"ask": ["mcp__sre-tools__label_ticket"],
"deny": ["Bash(kubectl delete *)", "Bash(kubectl apply *)"]
}
}
Rules name MCP tools as mcp__, the server, two underscores, then the tool. Claude Code now runs certificate checks silently but shows you each label call, with its arguments, before it runs. Deny rules match command prefixes, so kubectl -n prod delete slips past them. They are a speed bump; the read-only kubeconfig is the wall.
Audit trail and the trust ladder
Approval prompts catch mistakes in the moment; the audit log answers questions later. Every write leaves one line:
{"ts": "2026-12-01T09:42:17Z", "tool": "label_ticket", "args": {"number": 4182,
"labels": ["team:network", "sev:3"], "reason": "DNS timeouts, same as #4177"}}
Ship the file to your log platform and add the model name and prompt version to each entry. Then "what did the agent change on Tuesday?" becomes a query, and you get an eval set: replay last month's tickets against a new model or prompt, and compare its labels with what humans chose.
The trust ladder below is how I introduce agents: observe, suggest, propose, act after approval, then act alone inside a budget. It is the same discipline behind the guard-railed automated upgrades I ran across a 2000+ machine fleet with host draining: small steps, each proven before the next.
Promote a task one rung only on evidence, for example a month of approved calls with no reverts. Demote it after any incident. Even the top rung keeps a daily action budget, a token budget per run and a kill switch that removes the write tools. For steps that must run in a fixed order, an executable runbook beats a free-roaming agent.
Common pitfalls
- Treating hints as security. Annotations and "never delete anything" in a prompt are suggestions. Scope the credentials.
- One giant tool. A generic
run_kubectl(args)makes every allowlist meaningless. Expose narrow, typed tools. - Unbounded output. Raw namespace YAML burns tokens. Return only the fields needed.
- Logging after the call. A write that crashes halfway leaves no trace. Audit first, then act.
Key takeaways
- Give agents frequent, checkable, reversible tasks; keep production data changes human-only.
- Expose tools through MCP, read-only first; enforce scope with credentials and code.
- Gate every write with an approval prompt and record it in an audit log before it runs.
- Climb the trust ladder one rung at a time, backed by evals on replayed work.
Related articles

RAG in Production: Evals, Observability, Cost, Freshness
Take a runbook RAG bot from demo to production: gate changes on recall@k and faithfulness evals, trace retrieval and generation with OpenTelemetry, set latency and groundedness SLOs, and cut cost with caching and incremental re-indexing.

AI Post-Mortems: Faster Drafts That Stay Blameless
Let an LLM draft the post-mortem without letting it assign blame: build the timeline in code from Slack, Prometheus alerts and GitHub deploys, draft with a blameless prompt, lint the wording in CI, and keep causes and action items human.

Natural-Language Observability: LLMs That Write PromQL
Let engineers ask Prometheus questions in plain English. Ground the LLM in your real metric names, validate every generated query for syntax, cardinality and range, and ship it as a read-only MCP tool.