Kubectl MCP Server

Kubectl MCP Server

Natural language Kubernetes management for AI assistants using the Model Context Protocol.

734
Stars
137
Forks
734
Watchers
14
Issues
Kubectl MCP Server enables AI assistants such as Claude and Cursor to interact with Kubernetes clusters using natural language through the Model Context Protocol (MCP). It supports a wide range of Kubernetes operations including resource management, Helm integration, monitoring, diagnostics, and advanced security features. The server is designed to handle context-aware commands, maintain session memory, and provide intelligent command construction and explanations. Integration with multiple AI assistants and flexible transport protocols are supported for a seamless user experience.

Key Features

Connects to and manages Kubernetes clusters
Natural language query processing for kubectl operations
Memory persistence for context-aware commands
Helm v3 support for application lifecycle management
Supports advanced security features such as RBAC validation and security context auditing
Cluster and resource monitoring with historical performance tracking
Diagnostics and error analysis for troubleshooting
Multiple transport protocol support including stdio and SSE
Integration with leading AI assistants
Extensible framework for adding custom Kubernetes operations

Use Cases

Managing Kubernetes resources through conversational AI interfaces
Automating cluster diagnostics and troubleshooting with natural language
Onboarding teams with human-friendly Kubernetes explanations
Monitoring cluster health and resource utilization programmatically
Securing Kubernetes clusters with automated RBAC validation and audits
Streamlining Helm chart deployments and upgrades
Switching between namespaces or clusters seamlessly via AI commands
Analyzing cluster events and logs with natural language queries
Executing context-aware batch operations across resources
Testing and developing Kubernetes workflows with mock data support

README

Kubectl MCP Server

A Model Context Protocol (MCP) server for Kubernetes that enables AI assistants like Claude, Cursor, and others to interact with Kubernetes clusters through natural language.

License: MIT Python Kubernetes MCP PyPI version

🎥 Live Demo - Watch kubectl-mcp-tool in Action with Claude!

Claude MCP

🎥 Live Demo - Watch kubectl-mcp-tool in Action with Cursor!

Cursor MCP

🎥 Live Demo - Watch kubectl-mcp-tool in Action with Windsurf!

Windsurf MCP

Features

Core Kubernetes Operations

  • Connect to a Kubernetes cluster
  • List and manage pods, services, deployments, and nodes
  • Create, delete, and describe pods and other resources
  • Get pod logs and Kubernetes events
  • Support for Helm v3 operations (installation, upgrades, uninstallation)
  • kubectl explain and api-resources support
  • Choose namespace for next commands (memory persistence)
  • Port forward to pods
  • Scale deployments and statefulsets
  • Execute commands in containers
  • Manage ConfigMaps and Secrets
  • Rollback deployments to previous versions
  • Ingress and NetworkPolicy management
  • Context switching between clusters

Natural Language Processing

  • Process natural language queries for kubectl operations
  • Context-aware commands with memory of previous operations
  • Human-friendly explanations of Kubernetes concepts
  • Intelligent command construction from intent
  • Fallback to kubectl when specialized tools aren't available
  • Mock data support for offline/testing scenarios
  • Namespace-aware query handling

Monitoring

  • Cluster health monitoring
  • Resource utilization tracking
  • Pod status and health checks
  • Event monitoring and alerting
  • Node capacity and allocation analysis
  • Historical performance tracking
  • Resource usage statistics via kubectl top
  • Container readiness and liveness tracking

Security

  • RBAC validation and verification
  • Security context auditing
  • Secure connections to Kubernetes API
  • Credentials management
  • Network policy assessment
  • Container security scanning
  • Security best practices enforcement
  • Role and ClusterRole management
  • ServiceAccount creation and binding
  • PodSecurityPolicy analysis
  • RBAC permissions auditing
  • Security context validation

Diagnostics

  • Cluster diagnostics and troubleshooting
  • Configuration validation
  • Error analysis and recovery suggestions
  • Connection status monitoring
  • Log analysis and pattern detection
  • Resource constraint identification
  • Pod health check diagnostics
  • Common error pattern identification
  • Resource validation for misconfigurations
  • Detailed liveness and readiness probe validation

Advanced Features

  • Multiple transport protocols support (stdio, SSE)
  • Integration with multiple AI assistants
  • Extensible tool framework
  • Custom resource definition support
  • Cross-namespace operations
  • Batch operations on multiple resources
  • Intelligent resource relationship mapping
  • Error explanation with recovery suggestions
  • Volume management and identification

Architecture

Model Context Protocol (MCP) Integration

The Kubectl MCP Tool implements the Model Context Protocol (MCP), enabling AI assistants to interact with Kubernetes clusters through a standardized interface. The architecture consists of:

  1. MCP Server: A compliant server that handles requests from MCP clients (AI assistants)
  2. Tools Registry: Registers Kubernetes operations as MCP tools with schemas
  3. Transport Layer: Supports stdio, SSE, and HTTP transport methods
  4. Core Operations: Translates tool calls to Kubernetes API operations
  5. Response Formatter: Converts Kubernetes responses to MCP-compliant responses

Request Flow

Request Flow

Dual Mode Operation

The tool operates in two modes:

  1. CLI Mode: Direct command-line interface for executing Kubernetes operations
  2. Server Mode: Running as an MCP server to handle requests from AI assistants

Installation

For detailed installation instructions, please see the Installation Guide.

You can install kubectl-mcp-tool directly from PyPI:

bash
pip install kubectl-mcp-tool

For a specific version:

bash
pip install kubectl-mcp-tool==1.1.1

The package is available on PyPI: https://pypi.org/project/kubectl-mcp-tool/1.1.1/

Prerequisites

  • Python 3.9+
  • kubectl CLI installed and configured
  • Access to a Kubernetes cluster
  • pip (Python package manager)

Global Installation

bash
# Install latest version from PyPI
pip install kubectl-mcp-tool

# Or install development version from GitHub
pip install git+https://github.com/rohitg00/kubectl-mcp-server.git

Local Development Installation

bash
# Clone the repository
git clone https://github.com/rohitg00/kubectl-mcp-server.git
cd kubectl-mcp-server

# Install in development mode
pip install -e .

Verifying Installation

After installation, verify the tool is working correctly:

bash
kubectl-mcp --help

Note: This tool is designed to work as an MCP server that AI assistants connect to, not as a direct kubectl replacement. The primary command available is kubectl-mcp serve which starts the MCP server.

Docker Image

If you prefer using Docker, a pre-built image is available on Docker Hub:

bash
# Pull the latest image
docker pull rohitghumare64/kubectl-mcp-server:latest

Running the image

The server inside the container listens on port 8000. Bind any free host port to 8000 and mount your kubeconfig:

bash
# Replace 8081 with any free port on your host
# Mount your local ~/.kube directory for cluster credentials

docker run -p 8081:8000 \
           -v $HOME/.kube:/root/.kube \
           rohitghumare64/kubectl-mcp-server:latest
  • -p 8081:8000 maps host port 8081 → container port 8000.
  • -v $HOME/.kube:/root/.kube mounts your kubeconfig so the server can reach the cluster.

Building a multi-architecture image (AMD64 & ARM64)

If you want to build and push a multi-arch image (so it runs on both x86_64 and Apple Silicon), use Docker Buildx:

bash
# Ensure Buildx and QEMU are installed once per machine
# docker buildx create --name multiarch --use
# docker buildx inspect --bootstrap

# Build and push for linux/amd64 and linux/arm64
# (replace <your_username> if you're publishing to your own registry)

docker buildx build \
  --platform linux/amd64,linux/arm64 \
  -t rohitghumare64/kubectl-mcp-server:latest \
  --push .

The published image will contain a manifest list with both architectures, and Docker will automatically pull the correct variant on each machine.

Configuration

The MCP server is allowed to access these paths to read your Kubernetes configuration:

yaml
run:
  volumes:
    - '{{kubectl-mcp-server.kubeconfig}}:/root/.kube'
config:
  description: The MCP server is allowed to access this path
  parameters:
    type: object
    properties:
      kubeconfig:
        type: string
        default:
          $HOME/.kube
    required:
      - kubeconfig

This configuration allows users to add their kubeconfig directory to the container, enabling the MCP server to authenticate with their Kubernetes cluster.

Usage with AI Assistants

Using the MCP Server

The MCP Server (kubectl_mcp_tool.mcp_server) is a robust implementation built on the FastMCP SDK that provides enhanced compatibility across different AI assistants:

Note: If you encounter any errors with the MCP Server implementation, you can fall back to using the minimal wrapper by replacing kubectl_mcp_tool.mcp_server with kubectl_mcp_tool.minimal_wrapper in your configuration. The minimal wrapper provides basic capabilities with simpler implementation.

  1. Direct Configuration

    json
    {
      "mcpServers": {
        "kubernetes": {
          "command": "python",
          "args": ["-m", "kubectl_mcp_tool.mcp_server"],
          "env": {
            "KUBECONFIG": "/path/to/your/.kube/config",
            "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
            "MCP_LOG_FILE": "/path/to/logs/debug.log",
            "MCP_DEBUG": "1"
          }
        }
      }
    }
    
  2. Key Environment Variables

    • MCP_LOG_FILE: Path to log file (recommended to avoid stdout pollution)
    • MCP_DEBUG: Set to "1" for verbose logging
    • MCP_TEST_MOCK_MODE: Set to "1" to use mock data instead of real cluster
    • KUBECONFIG: Path to your Kubernetes config file
    • KUBECTL_MCP_LOG_LEVEL: Set to "DEBUG", "INFO", "WARNING", or "ERROR"
  3. Testing the MCP Server You can test if the server is working correctly with:

    bash
    python -m kubectl_mcp_tool.simple_ping
    

    This will attempt to connect to the server and execute a ping command.

    Alternatively, you can directly run the server with:

    bash
    python -m kubectl_mcp_tool
    

Claude Desktop

Add the following to your Claude Desktop configuration at ~/Library/Application\ Support/Claude/claude_desktop_config.json (Windows: %APPDATA%\Claude\mcp.json):

json
{
  "mcpServers": {
    "kubernetes": {
      "command": "python",
      "args": ["-m", "kubectl_mcp_tool.mcp_server"], 
      "env": {
        "KUBECONFIG": "$HOME/.kube/config" // or whatever your path is for the config file
      }
    }
  }
}

Cursor AI

Add the following to your Cursor AI settings under MCP by adding a new global MCP server:

json
{
  "mcpServers": {
    "kubernetes": {
      "command": "python",
      "args": ["-m", "kubectl_mcp_tool.mcp_server"],
      "env": {
        "KUBECONFIG": "/path/to/your/.kube/config",
        "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin"
      }
    }
  }
}

Save this configuration to ~/.cursor/mcp.json for global settings.

Note: Replace /path/to/your/.kube/config with the actual path to your kubeconfig file. On most systems, this is ~/.kube/config.

Windsurf

Add the following to your Windsurf configuration at ~/.config/windsurf/mcp.json (Windows: %APPDATA%\WindSurf\mcp.json):

json
{
  "mcpServers": {
    "kubernetes": {
      "command": "python",
      "args": ["-m", "kubectl_mcp_tool.mcp_server"],
      "env": {
        "KUBECONFIG": "/path/to/your/.kube/config"
      }
    }
  }
}

Automatic Configuration

For automatic configuration of all supported AI assistants, run the provided installation script:

bash
bash install.sh

Star History

Star History Chart

Repository Owner

rohitg00
rohitg00

User

Repository Details

Language Python
Default Branch main
Size 99,383 KB
Contributors 6
License MIT License
MCP Verified Nov 11, 2025

Programming Languages

Python
99.28%
Shell
0.46%
Dockerfile
0.26%

Tags

Topics

ai deployment devops genai kubernetes kubernetes-cluster llms mcp mcp-server

Join Our Newsletter

Stay updated with the latest AI tools, news, and offers by subscribing to our weekly newsletter.

We respect your privacy. Unsubscribe at any time.

Related MCPs

Discover similar Model Context Protocol servers

  • mcp-k8s

    mcp-k8s

    A Kubernetes MCP server enabling resource management via Model Control Protocol.

    mcp-k8s is a Kubernetes server that implements the Model Control Protocol (MCP), allowing users to interact with Kubernetes clusters through MCP-compatible tools. It supports querying and managing all Kubernetes resources, including custom resources, with fine-grained control over read and write operations. The server utilizes stdio communication and integrates with both Kubernetes and Helm, facilitating resource and Helm release management. It is designed to support natural language interactions with large language models for managing, diagnosing, and learning Kubernetes operations.

    • 129
    • MCP
    • silenceper/mcp-k8s
  • mcp-k8s-eye

    mcp-k8s-eye

    Kubernetes management and diagnostics tool with MCP protocol support.

    mcp-k8s-eye enables users to manage and analyze Kubernetes clusters using standardized Model Context Protocol (MCP) interfaces. It offers comprehensive resource operations, diagnostics, and resource usage monitoring through both stdio and SSE transports. Supporting generic and custom resource management along with advanced diagnostic tooling, it is geared for integration with AI clients and other MCP consumers.

    • 26
    • MCP
    • wenhuwang/mcp-k8s-eye
  • K8M

    K8M

    AI-driven lightweight Kubernetes dashboard with integrated MCP and multi-cluster management.

    K8M is an AI-enabled mini Kubernetes dashboard built with a focus on simplifying cluster management and enhancing user experience. Utilizing the Model Context Protocol (MCP), K8M offers visual management for MCP, allowing AI models to interact with Kubernetes resources and tools easily, supporting over 49 built-in MCP tools. It enables powerful multi-cluster management, integrates advanced AI capabilities such as chat-driven resource explanation and diagnostics, and supports custom large model integration including private deployments and models like Ollama.

    • 702
    • MCP
    • weibaohui/k8m
  • MCP K8S Go

    MCP K8S Go

    Golang-based MCP server that enables AI-driven interactions with Kubernetes clusters.

    MCP K8S Go provides a server implementation of the Model Context Protocol for managing and interacting with Kubernetes clusters. It offers functionality to list, retrieve, create, and modify Kubernetes resources such as contexts, namespaces, pods, and nodes using standardized context-aware approaches. Designed for integration with AI assistants like Claude Desktop, it enables prompting and tool execution to manage cluster state, monitor events, fetch pod logs, and run in-pod commands. The solution supports deployment via various installation methods including Docker, Node.js, and Go binaries.

    • 356
    • MCP
    • strowk/mcp-k8s-go
  • MCP Server Kubernetes

    MCP Server Kubernetes

    Connect and manage Kubernetes clusters via Model Context Protocol servers.

    MCP Server Kubernetes enables seamless connection and management of Kubernetes clusters through the Model Context Protocol. It supports loading kubeconfig from multiple sources, integrates easily with Claude Code, Claude Desktop, and VS Code, and offers flexible authentication mechanisms. Users can control clusters using standard command-line tools and extension integrations for multiple environments.

    • 1,181
    • MCP
    • Flux159/mcp-server-kubernetes
  • MKP

    MKP

    A Model Context Protocol server enabling LLM-powered applications to interact with Kubernetes clusters.

    MKP is a Model Context Protocol (MCP) server designed for Kubernetes environments, allowing large language model (LLM) powered applications to list, retrieve, and apply Kubernetes resources through a standardized protocol interface. Built natively in Go, it utilizes Kubernetes API machinery to provide direct, type-safe, and reliable operations without dependencies on CLI tools. MKP offers a minimalist, pluggable design enabling universal resource support, including custom resource definitions, and includes built-in rate limiting for production readiness.

    • 54
    • MCP
    • StacklokLabs/mkp
  • Didn't find tool you were looking for?

    Be as detailed as possible for better results