k8s
MCP server for Kubernetes
claude mcp add --transport stdio homayoonalimohammadi-k8s-mcp-server node bin/k8s-mcp-server \ --env LOG_LEVEL="info" \ --env KUBECONFIG="~/.kube/config" \ --env LOG_FORMAT="text" \ --env SERVER_NAME="k8s-mcp-server" \ --env K8S_IN_CLUSTER="false" \ --env SERVER_VERSION="1.0.0"
How to use
This MCP server provides tools to interact with Kubernetes clusters via a Model Context Protocol interface. It exposes two primary tools: getResource for retrieving a specific Kubernetes resource by kind, name, and optional namespace; and listResources for listing resources with optional namespace and label-based filtering. The server supports both in-cluster and external configurations, using the Kubernetes Go client library under the hood. You can operate it from an MCP client by calling the tools with the appropriate parameters, and the server will return structured data representing the Kubernetes objects.
To get started, run the server in your environment (in-cluster or with a kubeconfig), then use the MCP client to call the tools. For example, you can fetch a Pod named my-pod in the default namespace, list Deployments in a specific namespace, or filter Pods with a label selector like app=nginx. The server handles authentication via kubeconfig when outside the cluster and uses the in-cluster service account when configured to do so. It also provides configurable logging for easier debugging and operational insight.
How to install
Prerequisites:
- Go 1.23.2 or later
- Access to a Kubernetes cluster
- If running outside the cluster, a valid kubeconfig file
Installation and setup:
-
Clone the repository git clone https://github.com/HomayoonAlimohammadi/k8s-mcp-server cd k8s-mcp-server
-
Build from source make build
This will produce the binary in ./bin/k8s-mcp-server
-
Run the server (example)
Using default configuration
./bin/k8s-mcp-server
-
Optional: customize environment variables SERVER_NAME=my-k8s-server
LOG_LEVEL=debug
KUBECONFIG=/path/to/kubeconfig
K8S_IN_CLUSTER=false
./bin/k8s-mcp-server
Note: If you prefer a containerized approach, you can build a Docker image with the Go binary and run it via Docker commands.
Additional notes
Environment variables:
- SERVER_NAME: Identifier for the server (default: k8s-mcp-server)
- SERVER_VERSION: Server version (default: 1.0.0)
- KUBECONFIG: Path to kubeconfig when running outside the cluster (default: ~/.kube/config)
- K8S_IN_CLUSTER: Set to true to use in-cluster configuration (default: false)
- LOG_LEVEL: Logging level (debug, info, warn, error) (default: info)
- LOG_FORMAT: Log format (text, json) (default: text) Tips and common issues:
- Ensure access to the Kubernetes cluster from the host or environment where the server runs.
- If running inside a cluster, enable K8S_IN_CLUSTER=true and remove or adjust KUBECONFIG.
- Validate that kubectl can access the cluster using the same kubeconfig or in-cluster credentials.
- If you encounter network or authentication errors, verify permissions for the service account or kubeconfig context.
- The server supports filtering via labelSelector when listing resources; ensure you pass valid label selectors (e.g., app=nginx).
Related MCP Servers
trpc-agent-go
trpc-agent-go is a powerful Go framework for building intelligent agent systems using large language models (LLMs) and tools.
station
Station is our open-source runtime that lets teams deploy agents on their own infrastructure with full control.
tiger-cli
Tiger CLI is the command-line interface for Tiger Cloud. It includes an MCP server for helping coding agents write production-level Postgres code.
gopls
MCP server for golang projects development: Expand AI Code Agent ability boundary to have a semantic understanding and determinisic information for golang projects.
kubernetes
A Model Context Protocol (MCP) server for the Kubernetes API.
gcp-cost
💰 An MCP server that enables AI assistants to estimate Google Cloud costs, powered by Cloud Billing Catalog API and built with Genkit for Go