The mcp-kubernetes is a Model Context Protocol (MCP) server that enables AI assistants to interact with Kubernetes clusters.
Обзор
The mcp-kubernetes is a Model Context Protocol (MCP) server that enables AI assistants to interact with Kubernetes clusters.
README
mcp-kubernetes
The mcp-kubernetes is a Model Context Protocol (MCP) server that enables AI assistants to interact with Kubernetes clusters. It serves as a bridge between AI tools (like Claude, Cursor, and GitHub Copilot) and Kubernetes, translating natural language requests into Kubernetes operations and returning the results in a format the AI tools can understand.
It allows AI tools to:
- Query Kubernetes resources
- Execute kubectl commands
- Manage Kubernetes clusters through natural language interactions
- Diagnose and interpret the states of Kubernetes resources
How it works
How to install
Docker
Get your kubeconfig file for your Kubernetes cluster and setup in the mcpServers (replace src path with your kubeconfig path):
{
"mcpServers": {
"kubernetes": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"--mount",
"type=bind,src=/home/username/.kube/config,dst=/home/mcp/.kube/config",
"ghcr.io/azure/mcp-kubernetes"
]
}
}
}
Local
Config your MCP servers in Claude Desktop, Cursor, ChatGPT Copilot, Github Copilot and other supported AI clients, e.g.
{
"mcpServers": {
"kubernetes": {
"command": "",
"args": ["--transport", "stdio"],
"env": {
"KUBECONFIG": ""
}
}
}
}
Options
Environment variables:
KUBECONFIG: Path to your kubeconfig file, e.g./home//.kube/config.USE_LEGACY_TOOLS: Set totrueto use multiple specialized kubectl tools instead of the unifiedcall_kubectltool (default:false).
Command line arguments:
Usage of ./mcp-kubernetes:
--access-level string Access level (readonly, readwrite, or admin) (default "readonly")
--additional-tools string Comma-separated list of additional tools to support (kubectl is always enabled). Available: helm,cilium,hubble
--allow-namespaces string Comma-separated list of namespaces to allow (empty means all allowed)
--host string Host to listen for the server (only used with transport sse or streamable-http) (default "127.0.0.1")
--otlp-endpoint string OTLP endpoint for OpenTelemetry traces (e.g. localhost:4317, default "")
--port int Port to listen for the server (only used with transport sse or streamable-http) (default 8000)
--timeout int Timeout for command execution in seconds, default is 60s (default 60)
--transport string Transport mechanism to use (stdio, sse or streamable-http) (default "stdio")
Unified vs Legacy Tools
By default, mcp-kubernetes uses a single unified call_kubectl tool that consolidates all kubectl operations into one tool interface. This significantly reduces context consumption while maintaining full functionality.
To use the legacy mode with multiple specialized tools (6-7 separate tools), set the environment variable:
{
"mcpServers": {
"kubernetes": {
"command": "mcp-kubernetes",
"env": {
"USE_LEGACY_TOOLS": "true"
}
}
}
}
Access Levels
The --access-level flag controls what operations are allowed:
readonly(default): Only read operations are allowed (get, describe, logs, etc.)readwrite: Read and write operations are allowed (create, delete, apply, etc.)admin: All operations are allowed, including admin operations (cordon, drain, taint, etc.)
Tools and operations are filtered at registration time based on the access level, so AI assistants only see operations they can actually use.
Example configurations:
// Read-only access (default)
{
"mcpServers": {
"kubernetes": {
"command": "mcp-kubernetes"
}
}
}
// Read-write access
{
"mcpServers": {
"kubernetes": {
"command": "mcp-kubernetes",
"args": ["--access-level", "readwrite"]
}
}
}
// Admin access
{
"mcpServers": {
"kubernetes": {
"command": "mcp-kubernetes",
"args": ["--access-level", "admin"]
}
}
}
Usage
Ask any questions about Kubernetes cluster in your AI client. The MCP tools make it easier for AI assistants to understand and use kubectl operations.
Example Queries
What is the status of my Kubernetes cluster?
What is wrong with my nginx pod?
Show me all deployments in the production namespace
Scale my web deployment to 5 replicas
Check if I have permission to create pods
What is my current kubectl context?
List all available kubectl contexts
Switch to the production context
Available Tools
Unified Tool (Default)
By default, mcp-kubernetes uses a single unified call_kubectl tool that handles all kubectl operations. This approach significantly reduces context consumption compared to the legacy multi-tool approach.
call_kubectl - Execute kubectl commands
- Available in: All access levels (operations filtered by access level)
- Parameters:
command: The full kubectl command to execute including ‘kubectl’ prefix (e.g., “kubectl get pods -n default”, “kubectl apply -f deployment.yaml”)
- Examples:
# Get pods command: "kubectl get pods -n default" # Apply configuration command: "kubectl apply -f deployment.yaml" # Scale deployment command: "kubectl scale deployment nginx --replicas=3"
Legacy Tools (Optional)
When USE_LEGACY_TOOLS=true, the mcp-kubernetes server provides multiple specialized kubectl tools that group related operations together. Tools are automatically filtered based on your access level.
Kubectl Tools
Additional Tools
Telemetry
Telemetry collection is on by default.
To opt out, set the environment variable KUBERNETES_MCP_COLLECT_TELEMETRY=false.
OpenTelemetry Support
The mcp-kubernetes server supports exporting telemetry data using OpenTelemetry Protocol (OTLP). You can configure an OTLP endpoint to send traces to any OpenTelemetry-compatible backend:
{
"mcpServers": {
"kubernetes": {
"command": "mcp-kubernetes",
"args": ["--otlp-endpoint", "localhost:4317"]
}
}
}
Development
How to inspect MCP server requests and responses:
npx @modelcontextprotocol/inspector
Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.
Trademarks
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft’s Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party’s policies.
Установка
docker run -i --rm --mount type=bind src=/home/username/.kube/config dst=/home/mcp/.kube/config ghcr.io/azure/mcp-kubernetesКонфигурация
{
"mcpServers": {
"kubernetes": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"--mount",
"type=bind,src=/home/username/.kube/config,dst=/home/mcp/.kube/config",
"ghcr.io/azure/mcp-kubernetes"
]
}
}
}