FM

feiskyer/mcp-kubernetes-server

Developer tools
20 stars 0 forks Quality 90 Trend 90

A Model Context Protocol (MCP) server that enables AI assistants to interact with Kubernetes clusters.

Overview

The mcp-kubernetes-server is a server implementing the Model Context Protocol (MCP) to enable AI assistants (such as Claude, Cursor, and GitHub Copilot) to interact with Kubernetes clusters. It acts as a bridge, translating natural language requests from these assistants into Kubernetes operations and returning the results. - Query Kubernetes resources - Execute kubectl commands - Manage Kubernetes clusters through natural language interactions - Diagnose and interpret the states of Kubernetes resources The mcp-kubernetes-server acts as an intermediary between AI assistants (that support the Model Context Protocol) and your Kubernetes cluster. It receives natural language requests from these assistants, translates them into kubectl commands or direct Kubernetes API calls, and executes them against the target cluster. The server then processes the results and returns a structured response, enabling seamless interaction with your Kubernetes environment via the AI assistant.

README

mcp-kubernetes-server

The mcp-kubernetes-server is a server implementing the Model Context Protocol (MCP) to enable AI assistants (such as Claude, Cursor, and GitHub Copilot) to interact with Kubernetes clusters. It acts as a bridge, translating natural language requests from these assistants into Kubernetes operations and returning the results.

It allows AI assistants 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

The mcp-kubernetes-server acts as an intermediary between AI assistants (that support the Model Context Protocol) and your Kubernetes cluster. It receives natural language requests from these assistants, translates them into kubectl commands or direct Kubernetes API calls, and executes them against the target cluster. The server then processes the results and returns a structured response, enabling seamless interaction with your Kubernetes environment via the AI assistant.

How To Install

Prerequisites

Before installing mcp-kubernetes-server, ensure you have the following:

  • A working Kubernetes cluster.
  • A kubeconfig file correctly configured to access your Kubernetes cluster (the server requires this file for interaction).
  • The kubectl command-line tool installed and in your system’s PATH (used by the server to execute many Kubernetes commands).
  • The helm command-line tool installed and in your system’s PATH (used by the server for Helm chart operations).
  • Python >= 3.11, if you plan to install and run the server directly using uvx (without Docker).

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/feiskyer/mcp-kubernetes-server"
      ]
    }
  }
}

UVX

To run the server using uvx (a tool included with uv, the Python packager), first ensure uv is installed:

Config your MCP servers in Claude Desktop, Cursor, ChatGPT Copilot, Github Copilot and other supported AI clients, e.g.

{
  "mcpServers": {
    "kubernetes": {
      "command": "uvx",
      "args": [
        "mcp-kubernetes-server"
      ],
      "env": {
        "KUBECONFIG": ""
      }
    }
  }
}

MCP Server Options

Usage

Once the mcp-kubernetes-server is installed and configured in your AI client (using the JSON snippets provided in the ‘How to install’ section for Docker or UVX), you can start interacting with your Kubernetes cluster through natural language. For example, you can ask:

What is the status of my Kubernetes cluster?

What is wrong with my nginx pod?

Verifying the server: If you’re running the server with stdio transport (common for uvx direct execution), the AI client will typically start and manage the server process. For sse or streamable-http transports, the server runs independently. You would have started it manually (e.g., uvx mcp-kubernetes-server --transport sse) and should see output in your terminal indicating it’s running (e.g., INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)). You can also check for any error messages in the server terminal if the AI client fails to connect.

Available Tools

The mcp-kubernetes-server provides a comprehensive set of tools for interacting with Kubernetes clusters, categorized by operation type:

Development

How to run the project locally:

uv run -m src.mcp_kubernetes_server.main

How to inspect MCP server requests and responses:

npx @modelcontextprotocol/inspector uv run -m src.mcp_kubernetes_server.main

Troubleshooting

Here are some common issues and their solutions when working with mcp-kubernetes-server:

Issue: mcp-kubernetes-server cannot connect to the Kubernetes cluster or reports authentication errors. Solution:

  • Ensure your kubeconfig file is correctly configured and points to the intended cluster.
  • Verify that the path to your kubeconfig file is correctly specified in the mcpServers configuration (for Docker, ensure the mount path is correct; for uvx, ensure the KUBECONFIG environment variable is set correctly).
  • Check that the credentials in your kubeconfig have the necessary permissions to perform operations on the cluster. You can test this with kubectl directly (e.g., kubectl get pods).

Issue: kubectl or helm commands return an error like “command not found” or are disabled. Solution:

  • If running via uvx, ensure kubectl and/or helm are installed on your system and available in your PATH. Refer to the “Prerequisites” section for installation guidance.
  • If you see a message like “Write operations are not allowed” or “Delete operations are not allowed”, the server might have been started with flags like --disable-kubectl, --disable-helm, --disable-write, or --disable-delete. Check the server’s startup command and the “MCP Server Options” section in the README for details on these flags.

Issue: How can I see the raw requests and responses between my AI client and the mcp-kubernetes-server? Solution:

  • You can use the @modelcontextprotocol/inspector tool as mentioned in the “Development” section: npx @modelcontextprotocol/inspector uv run -m src.mcp_kubernetes_server.main. This will show you the MCP messages being exchanged.

Issue: The server starts but the AI client cannot connect. Solution:

  • If using stdio transport (default for uvx direct execution), ensure your AI client is configured to launch the mcp-kubernetes-server command correctly.
  • If using sse or streamable-http transport, ensure the host and port configured in the mcp-kubernetes-server (e.g., --host 0.0.0.0 --port 8000) are reachable from where your AI client is running. Check for firewall rules or network configuration issues. Also, verify the AI client is configured with the correct URL for the server.

Contribution

This project is open source, available on GitHub at feiskyer/mcp-kubernetes-server and licensed under the Apache License.

If you would like to contribute to the project, please follow these guidelines:

  1. Fork the repository and clone it to your local machine.
  2. Create a new branch for your changes.
  3. Make your changes and commit them with a descriptive commit message.
  4. Push your changes to your forked repository.
  5. Open a pull request to the main repository.

LICENSE

The project is licensed under the Apache License 2.0. See the LICENSE file for more details.

View this README on GitHub

Install

docker run -i --rm --mount type=bind src=/home/username/.kube/config dst=/home/mcp/.kube/config ghcr.io/feiskyer/mcp-kubernetes-server

Configuration

{ "mcpServers": { "kubernetes": { "command": "docker", "args": [ "run", "-i", "--rm", "--mount", "type=bind,src=/home/username/.kube/config,dst=/home/mcp/.kube/config", "ghcr.io/feiskyer/mcp-kubernetes-server" ] } } }