mcp-k8s-context-server
Provides read-only tools to list pods, get pod status and logs, retrieve deployment manifests, analyze pod health, and track resource trends from a Kubernetes cluster.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mcp-k8s-context-serverList all pods in the default namespace and check if any have high restart counts"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MCP K8s Context Server
A FastMCP server that exposes Kubernetes as a set of read-only tools consumable by LLMs, plus an analytics layer for pod-health analysis and resource-trend tracking.
Features
Tool | Description |
| List pods in a namespace with phase and restart info |
| Detailed pod status, conditions, and container states |
| Tail recent pod logs |
| Full deployment spec as JSON |
| Analytics: scan logs, detect error patterns, rank unhealthy pods |
| Analytics: CPU/memory from Metrics API with historical SQLite persistence |
Related MCP server: Kube MCP
Project Structure
mcp-k8s-context-server/
├── k8s_mcp_server.py # FastMCP server (all tools)
├── requirements.txt # Python dependencies
├── Dockerfile # Container image definition
├── k8s/
│ ├── serviceaccount.yaml # ServiceAccount + Namespace
│ ├── role.yaml # Least-privilege ClusterRole (read-only)
│ ├── rolebinding.yaml # ClusterRoleBinding
│ └── deployment.yaml # Deployment + Service
└── .github/
└── workflows/
└── ci.yml # Build + kubeconform validationLocal Development
# Create and activate a virtual environment
python -m venv .venv && source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Run with local kubeconfig (falls back automatically from in-cluster config)
python k8s_mcp_server.pyIn-Cluster Deployment (minikube)
Prerequisites
# Install minikube, kubectl, docker
minikube version # >= 1.32
kubectl version # >= 1.28
docker version # >= 24Step 1 — Start minikube
minikube start --cpus=2 --memory=4096Step 2 — Enable metrics-server (required for get_resource_trends)
minikube addons enable metrics-serverStep 3 — Build and load the image into minikube
# Build locally
docker build -t mcp-k8s-server:latest .
# Load into minikube's image registry (no registry push needed)
minikube image load mcp-k8s-server:latest
# Verify the image is available
minikube image ls | grep mcp-k8s-serverStep 4 — Apply Kubernetes manifests
# Apply in dependency order: SA → Role → Binding → Deployment
kubectl apply -f k8s/serviceaccount.yaml
kubectl apply -f k8s/role.yaml
kubectl apply -f k8s/rolebinding.yaml
kubectl apply -f k8s/deployment.yamlStep 5 — Verify the Pod is Running
kubectl get pods -n mcp-system
# Expected:
# NAME READY STATUS RESTARTS AGE
# mcp-k8s-server-xxxxxxxxx-xxxxx 1/1 Running 0 30s
kubectl logs -n mcp-system deploy/mcp-k8s-server
# Expected: "Using in-cluster Kubernetes config (ServiceAccount token)"Step 6 — Test read-only tools in-cluster
# Port-forward to access the server from your laptop
kubectl port-forward -n mcp-system svc/mcp-k8s-server 8000:8000 &
# Create a test pod to query
kubectl run nginx-test --image=nginx --restart=Never
# Test list_pods
curl -s http://localhost:8000/tools/list_pods \
-H 'Content-Type: application/json' \
-d '{"namespace":"default"}' | jq .
# Test get_pod_logs
curl -s http://localhost:8000/tools/get_pod_logs \
-H 'Content-Type: application/json' \
-d '{"pod_name":"nginx-test","namespace":"default","tail_lines":20}' | jq .
# Test analyze_pod_health
curl -s http://localhost:8000/tools/analyze_pod_health \
-H 'Content-Type: application/json' \
-d '{"namespace":"default","hours":1}' | jq .Step 7 — Prove RBAC blocks write operations
The ServiceAccount has no write verbs. To confirm this:
# Exec into the pod and try to delete another pod using the SA token
MCP_POD=$(kubectl get pod -n mcp-system -l app=mcp-k8s-server -o jsonpath='{.items[0].metadata.name}')
kubectl exec -n mcp-system $MCP_POD -- \
kubectl delete pod nginx-test --namespace=default \
--token=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token) \
--server=https://kubernetes.default.svc \
--certificate-authority=/var/run/secrets/kubernetes.io/serviceaccount/ca.crtExpected output:
Error from server (Forbidden): pods "nginx-test" is forbidden:
User "system:serviceaccount:mcp-system:mcp-server-sa" cannot delete
resource "pods" in API group "" in the namespace "default"This 403 Forbidden response from the API server is the live proof that the RBAC scoping works — the ServiceAccount can read but cannot modify any resource.
RBAC Least-Privilege Design
Philosophy
Grant only what is needed, explicitly deny everything else.
The MCP server is an observability tool — it reads cluster state to help operators and AI systems understand what's happening. It has no legitimate reason to create, modify, or delete any resource.
What is granted
Resource | Verbs | Reason |
|
|
|
|
|
|
|
|
|
|
|
|
What is explicitly NOT granted
Verb | Reason for exclusion |
| No tool creates any resource |
| No tool modifies any resource |
| Catastrophic if misused; no read tool needs it |
| Prevents privilege escalation |
This means a compromised MCP server cannot delete pods, scale deployments down to zero, modify secrets, or affect any running workload. The blast radius of a compromised MCP server is limited to reading information — not disrupting it.
Analytics Layer
analyze_pod_health
Lists all pods in the namespace.
Fetches up to 500 log lines per pod.
Pattern-matches against a catalogue of known failure indicators:
OOMKilled,CrashLoopBackOffPython/Java exceptions (Traceback, RuntimeError, etc.)
Panic, SIGSEGV/SIGKILL, Connection errors, Permission denied
Liveness/Readiness probe failures
Computes a health score per pod (lower = worse).
Returns pods ranked worst-first with error frequency counts.
Persists results to SQLite for historical analysis.
get_resource_trends
Resolves pod selector from the Deployment spec.
Reads resource limits from pod specs.
Queries the Kubernetes Metrics API (
metrics.k8s.io/v1beta1) for live CPU/memory.Computes: average, peak, and % of limit for both CPU and memory.
Persists each snapshot to
mcp_analytics.dbso trends build up across calls.
Requires
metrics-serveraddon:minikube addons enable metrics-server
CI / Continuous Integration
The GitHub Actions workflow (.github/workflows/ci.yml) runs on every push and PR:
Docker Build — builds the image without pushing (validates Dockerfile + dependencies).
kubeconform — validates all
k8s/*.yamlmanifests against the Kubernetes 1.29 schema in strict mode.ruff — lints
k8s_mcp_server.pyfor Python errors and style.
Environment Variables
Variable | Default | Description |
|
| Path to the SQLite analytics database |
License
MIT
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- Alicense-qualityBmaintenanceProvides read-only access to Kubernetes clusters for AI assistants.23MIT
- AlicenseAqualityCmaintenanceEnables AI assistants to interact with and manage Kubernetes clusters, supporting operations on pods, deployments, services, configmaps, secrets, namespaces, metrics, and events with built-in safety features for destructive actions.9141MIT
- AlicenseAqualityAmaintenanceEnables safe, read-only interaction with Kubernetes clusters, allowing users to list resources and fetch logs without any create/update/delete operations.116Apache 2.0
- Flicense-qualityCmaintenanceExposes Kubernetes cluster management tools to LLMs, enabling querying pods, deployments, logs, metrics, and managing port forwards via natural language.1
Related MCP Connectors
Read-only bank access for your AI agent. Connects Claude, ChatGPT, Cursor, Gemini, Codex.
Read-only access to Auralogs production logs: search logs, inspect errors, review AI analyses.
Operate Linux, macOS and Windows from your LLM. Every action runs through an auditable allowlist.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/Krishna1704M/mcp-k8s-context-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server