mcp-k8s-context-server
MCP K8s Context Server
FastMCP サーバー。Kubernetes を LLM が利用可能な読み取り専用ツール群として公開し、さらにポッドの健全性分析とリソース傾向追跡のための分析レイヤーを提供します。
機能
ツール | 説明 |
| 名前空間内のポッドを、フェーズと再起動情報とともに一覧表示 |
| ポッドの詳細なステータス、状態、コンテナの状態を取得 |
| 最近のポッドログを末尾から取得 |
| デプロイメントの完全な仕様を JSON として取得 |
| 分析: ログをスキャンし、エラーパターンを検出し、異常なポッドをランク付け |
| 分析: Metrics API からの CPU/メモリを、履歴 SQLite 永続化とともに取得 |
Related MCP server: Kube MCP
プロジェクト構造
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 validationローカル開発
# 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.pyクラスター内デプロイ (minikube)
前提条件
# Install minikube, kubectl, docker
minikube version # >= 1.32
kubectl version # >= 1.28
docker version # >= 24ステップ 1 — minikube を起動
minikube start --cpus=2 --memory=4096ステップ 2 — metrics-server を有効化 (get_resource_trends に必要)
minikube addons enable metrics-serverステップ 3 — イメージをビルドして 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-serverステップ 4 — Kubernetes マニフェストを適用
# 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.yamlステップ 5 — Pod が実行中であることを確認
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)"ステップ 6 — クラスター内で読み取り専用ツールをテスト
# 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 .ステップ 7 — RBAC が書き込み操作をブロックすることを証明
ServiceAccount には 書き込み動詞がありません。これを確認するには:
# 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.crt期待される出力:
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"API サーバーからのこの 403 Forbidden 応答は、RBAC スコープが機能していることの生の証拠です — ServiceAccount はリソースを読み取ることはできますが、変更することはできません。
RBAC 最小権限設計
哲学
必要なものだけを許可し、それ以外は明示的に拒否する。
MCP サーバーは 可観測性ツール です — オペレーターと AI システムが何が起こっているかを理解するためにクラスターの状態を読み取ります。リソースを作成、変更、または削除する正当な理由はありません。
許可されるもの
リソース | 動詞 | 理由 |
|
|
|
|
|
|
|
|
|
|
|
|
明示的に許可されないもの
動詞 | 除外理由 |
| どのツールもリソースを作成しない |
| どのツールもリソースを変更しない |
| 誤用された場合に壊滅的。読み取りツールには不要 |
| 権限昇格を防止 |
つまり、侵害された MCP サーバーは、ポッドを削除したり、デプロイメントをゼロにスケールダウンしたり、シークレットを変更したり、実行中のワークロードに影響を与えることは できません。侵害された MCP サーバーの爆発半径は、情報の 読み取り に限定され、情報の破壊には及びません。
分析レイヤー
analyze_pod_health
名前空間内のすべてのポッドを一覧表示します。
ポッドごとに最大 500 行のログを取得します。
既知の障害インジケーターのカタログとパターンマッチングを行います:
OOMKilled,CrashLoopBackOffPython/Java 例外 (Traceback, RuntimeError など)
Panic, SIGSEGV/SIGKILL, 接続エラー, Permission denied
Liveness/Readiness プローブの失敗
ポッドごとに ヘルススコア を計算します (低いほど悪い)。
エラー頻度カウントとともに、最も悪いものから順にポッドを返します。
結果を SQLite に永続化し、履歴分析を可能にします。
get_resource_trends
Deployment 仕様からポッドセレクターを解決します。
ポッド仕様からリソース 制限 を読み取ります。
Kubernetes Metrics API (
metrics.k8s.io/v1beta1) にライブの CPU/メモリを問い合わせます。CPU とメモリの両方について、平均、ピーク、および制限に対する割合を計算します。
各スナップショットを
mcp_analytics.dbに 永続化 し、呼び出しをまたいで傾向が蓄積されるようにします。
metrics-serverアドオンが必要:minikube addons enable metrics-server
CI / 継続的インテグレーション
GitHub Actions ワークフロー (.github/workflows/ci.yml) は、プッシュと PR のたびに実行されます:
Docker Build — イメージをプッシュせずにビルドします (Dockerfile + 依存関係を検証)。
kubeconform — すべての
k8s/*.yamlマニフェストを Kubernetes 1.29 スキーマに対して厳格モードで検証します。ruff —
k8s_mcp_server.pyを Python エラーとスタイルについて lint します。
環境変数
変数 | デフォルト | 説明 |
|
| SQLite 分析データベースへのパス |
ライセンス
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