kubectl MCP server

Enables natural language interaction with Kubernetes resources, allowing developers to manage clusters through conversational interfaces instead of complex kubectl commands.
Back to servers
Setup instructions
Provider
Rohit Ghumare
Release date
Apr 02, 2025
Language
Python
Package
Stats
3.7K downloads
650 stars

The kubectl-mcp-tool allows AI assistants to interact with Kubernetes clusters through natural language. It implements the Model Context Protocol (MCP) to bridge AI assistants like Claude, Cursor, and Windsurf with Kubernetes operations.

Installation

Requirements

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

Install from PyPI

pip install kubectl-mcp-tool

To install a specific version:

pip install kubectl-mcp-tool==1.1.1

Install Development Version

pip install git+https://github.com/rohitg00/kubectl-mcp-server.git

Verify Installation

After installation, verify the tool is working correctly:

kubectl-mcp --help

Docker Installation

You can use the pre-built Docker image instead of local installation:

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

# Run the container with your kubeconfig mounted
docker run -p 8081:8000 \
           -v $HOME/.kube:/root/.kube \
           rohitghumare64/kubectl-mcp-server:latest

Setting Up with AI Assistants

Basic Configuration

The MCP server can be configured with AI assistants using the following pattern:

{
  "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"
      }
    }
  }
}

Claude Desktop Configuration

Add the following to ~/.config/claude/mcp.json (Windows: %APPDATA%\Claude\mcp.json):

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

Cursor AI Configuration

Add a new global MCP server to your Cursor AI settings:

{
  "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 to ~/.cursor/mcp.json for global settings.

Windsurf Configuration

Add the following to ~/.config/windsurf/mcp.json (Windows: %APPDATA%\WindSurf\mcp.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:

bash install.sh

Advanced Configuration

You can customize the server behavior with environment variables:

  • MCP_LOG_FILE: Path to log file
  • 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"

Testing the Connection

To test if the server is working correctly:

python -m kubectl_mcp_tool.simple_ping

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

Alternatively, run the server directly:

python -m kubectl_mcp_tool

Using the Tool

Once configured, you can interact with your Kubernetes cluster by asking natural language questions in your AI assistant. Examples include:

  • "List all pods in the default namespace"
  • "Show me the deployments in the kube-system namespace"
  • "Scale the nginx deployment to 3 replicas"
  • "Get logs from the database pod"
  • "Describe the ingress controller pod"

The tool will translate these requests into the appropriate kubectl commands and return the results.

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "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"}}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "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"
            }
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "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"
            }
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later