k8s-readonly-mcp
v1.0.3Read-only Kubernetes MCP server for AI agents (Claude Code, Cursor, Gemini CLI, Codex CLI, VS Code Copilot).
A read-only Kubernetes MCP server for AI agents. Your agent can see pods, logs, events, deployments, services and nodes, and it cannot change anything. 1. Code wall: the server registers only read tools (21 of them, all marked readOnlyHint: true). No delete, patch, scale, exec or restart tool exists. 2. Cluster wall: you give it a ServiceAccount whose RBAC allows only get, list and watch. Kubernetes itself answers 403 Forbidden to any write. 1. Create the read-only identity and credential (once). This needs the setup script from the repository:
Summary extracted from the README.
k8s-readonly-mcp
A read-only Kubernetes MCP server for AI agents. Your agent can see pods, logs, events, deployments, services and nodes, and it cannot change anything.
Two independent walls enforce this:
- Code wall: the server registers only read tools (21 of them, all marked
readOnlyHint: true). No delete, patch, scale, exec or restart tool exists. - Cluster wall: you give it a ServiceAccount whose RBAC allows only
get,listandwatch. Kubernetes itself answers403 Forbiddento any write.
Quick start
-
Create the read-only identity and credential (once). This needs the setup script from the repository:
git clone https://github.com/Preetam-3/MCP_For_DevOps.git cd MCP_For_DevOps ./scripts/setup.sh demo 2h # writes ./mcp.kubeconfig -
Register the server with your agent:
claude mcp add --scope user k8s-readonly -e KUBECONFIG="$(pwd)/mcp.kubeconfig" -- npx -y k8s-readonly-mcpConfig snippets for Cursor, VS Code, Gemini CLI and Codex CLI are in the repository under
docs/clients/.
Scope of the guarantee: it covers this server and its credential. An agent that also has a shell can still use other credentials on your machine, so for important clusters run it where only the scoped kubeconfig exists.
Check it
KUBECONFIG=./mcp.kubeconfig NAMESPACE=demo npx -y -p k8s-readonly-mcp k8s-readonly-verify # proves writes are denied
KUBECONFIG=./mcp.kubeconfig npx -y -p k8s-readonly-mcp k8s-readonly-doctor # checks your setup
Configuration
| Variable | Meaning |
|---|---|
KUBECONFIG |
Required. Path to the scoped read-only kubeconfig. The server refuses to start without it, so it never silently uses your admin credential. |
K8S_READONLY_ALLOW_DEFAULT_KUBECONFIG |
Set to 1 to deliberately allow your default kubeconfig (not recommended) |
NAMESPACE_ALLOWLIST |
Comma-separated namespaces the server may read (default: the namespace of the current context) |
Requirements
Node.js 22.19 or newer, kubectl, and a Kubernetes cluster.
License
MIT