Calum Murray a2d16e9f41 feat: Multi Cluster Support (#348)
* feat: add cluster provider for kubeconfig

Signed-off-by: Calum Murray <cmurray@redhat.com>

* feat: move server to use ClusterProvider interface

Signed-off-by: Calum Murray <cmurray@redhat.com>

* feat: authentication middleware works with cluster provider

Signed-off-by: Calum Murray <cmurray@redhat.com>

* fix: unit tests work after cluster provider changes

Signed-off-by: Calum Murray <cmurray@redhat.com>

* feat: add tool mutator to add cluster parameter

Signed-off-by: Calum Murray <cmurray@redhat.com>

* test: handle cluster parameter

Signed-off-by: Calum Murray <cmurray@redhat.com>

* fix: handle lazy init correctly

Signed-off-by: Calum Murray <cmurray@redhat.com>

* refactor: move to using multi-strategy ManagerProvider

Signed-off-by: Calum Murray <cmurray@redhat.com>

* feat: add contexts_list tool

Signed-off-by: Calum Murray <cmurray@redhat.com>

* refactor: make tool mutator generic between cluster/context naming

Signed-off-by: Calum Murray <cmurray@redhat.com>

* feat: introduce tool filter

Signed-off-by: Calum Murray <cmurray@redhat.com>

* refactor: use new ManagerProvider/mutator/filter within mcp server

Signed-off-by: Calum Murray <cmurray@redhat.com>

* fix(test): tests expect context parameter in tool defs

Signed-off-by: Calum Murray <cmurray@redhat.com>

* feat: auth handles multi-cluster case correctly

Signed-off-by: Calum Murray <cmurray@redhat.com>

* fix: small changes from local testing

Signed-off-by: Calum Murray <cmurray@redhat.com>

* chore: fix enum test

Signed-off-by: Calum Murray <cmurray@redhat.com>

* review: Multi Cluster support (#1)

* nit: rename contexts_list to configuration_contexts_list

Besides the conventional naming, it helps LLMs understand the context of the tool by providing a certain level of hierarchy.

Signed-off-by: Marc Nuri <marc@marcnuri.com>

* fix(mcp): ToolMutator doesn't rely on magic strings

Signed-off-by: Marc Nuri <marc@marcnuri.com>

* refactor(api): don't expose ManagerProvider to toolsets

Signed-off-by: Marc Nuri <marc@marcnuri.com>

* test(mcp): configuration_contexts_list basic tests

Signed-off-by: Marc Nuri <marc@marcnuri.com>

* test(toolsets): revert edge-case test

This test should not be touched.

Signed-off-by: Marc Nuri <marc@marcnuri.com>

* test(toolsets): add specific metadata tests for multi-cluster

Signed-off-by: Marc Nuri <marc@marcnuri.com>

* fix(mcp): ToolFilter doesn't rely on magic strings (partially)

Signed-off-by: Marc Nuri <marc@marcnuri.com>

* test(api): IsClusterAware and IsTargetListProvider default values

Signed-off-by: Marc Nuri <marc@marcnuri.com>

* test(mcp): revert unneeded changes in mcp_tools_test.go

Signed-off-by: Marc Nuri <marc@marcnuri.com>

---------

Signed-off-by: Marc Nuri <marc@marcnuri.com>

* fix: always include configuration_contexts_list if contexts > 1

Signed-off-by: Calum Murray <cmurray@redhat.com>

* feat: include server urls in configuration_contexts_list

Signed-off-by: Calum Murray <cmurray@redhat.com>

---------

Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Marc Nuri <marc@marcnuri.com>
Co-authored-by: Marc Nuri <marc@marcnuri.com>
2025-10-06 12:01:16 +02:00
2025-10-06 12:01:16 +02:00
2025-02-11 03:57:36 +01:00
2025-02-17 15:51:07 +01:00

Kubernetes MCP Server

GitHub License npm PyPI - Version GitHub release (latest SemVer) Build

Features | 🚀 Getting Started | 🎥 Demos | ⚙️ Configuration | 🛠️ Tools | 🧑‍💻 Development

https://github.com/user-attachments/assets/be2b67b3-fc1c-4d11-ae46-93deba8ed98e

Features

A powerful and flexible Kubernetes Model Context Protocol (MCP) server implementation with support for Kubernetes and OpenShift.

  • Configuration:
    • Automatically detect changes in the Kubernetes configuration and update the MCP server.
    • View and manage the current Kubernetes .kube/config or in-cluster configuration.
  • Generic Kubernetes Resources: Perform operations on any Kubernetes or OpenShift resource.
    • Any CRUD operation (Create or Update, Get, List, Delete).
  • Pods: Perform Pod-specific operations.
    • List pods in all namespaces or in a specific namespace.
    • Get a pod by name from the specified namespace.
    • Delete a pod by name from the specified namespace.
    • Show logs for a pod by name from the specified namespace.
    • Top gets resource usage metrics for all pods or a specific pod in the specified namespace.
    • Exec into a pod and run a command.
    • Run a container image in a pod and optionally expose it.
  • Namespaces: List Kubernetes Namespaces.
  • Events: View Kubernetes events in all namespaces or in a specific namespace.
  • Projects: List OpenShift Projects.
  • ☸️ Helm:
    • Install a Helm chart in the current or provided namespace.
    • List Helm releases in all namespaces or in a specific namespace.
    • Uninstall a Helm release in the current or provided namespace.

Unlike other Kubernetes MCP server implementations, this IS NOT just a wrapper around kubectl or helm command-line tools. It is a Go-based native implementation that interacts directly with the Kubernetes API server.

There is NO NEED for external dependencies or tools to be installed on the system. If you're using the native binaries you don't need to have Node or Python installed on your system.

  • Lightweight: The server is distributed as a single native binary for Linux, macOS, and Windows.
  • High-Performance / Low-Latency: Directly interacts with the Kubernetes API server without the overhead of calling and waiting for external commands.
  • Cross-Platform: Available as a native binary for Linux, macOS, and Windows, as well as an npm package, a Python package, and container/Docker image.
  • Configurable: Supports command-line arguments to configure the server behavior.
  • Well tested: The server has an extensive test suite to ensure its reliability and correctness across different Kubernetes environments.

🚀 Getting Started

Requirements

  • Access to a Kubernetes cluster.

Claude Desktop

Using npx

If you have npm installed, this is the fastest way to get started with kubernetes-mcp-server on Claude Desktop.

Open your claude_desktop_config.json and add the mcp server to the list of mcpServers:

{
  "mcpServers": {
    "kubernetes": {
      "command": "npx",
      "args": [
        "-y",
        "kubernetes-mcp-server@latest"
      ]
    }
  }
}

VS Code / VS Code Insiders

Install the Kubernetes MCP server extension in VS Code Insiders by pressing the following link:

Install in VS Code Install in VS Code Insiders

Alternatively, you can install the extension manually by running the following command:

# For VS Code
code --add-mcp '{"name":"kubernetes","command":"npx","args":["kubernetes-mcp-server@latest"]}'
# For VS Code Insiders
code-insiders --add-mcp '{"name":"kubernetes","command":"npx","args":["kubernetes-mcp-server@latest"]}'

Cursor

Install the Kubernetes MCP server extension in Cursor by pressing the following link:

Install MCP Server

Alternatively, you can install the extension manually by editing the mcp.json file:

{
  "mcpServers": {
    "kubernetes-mcp-server": {
      "command": "npx",
      "args": ["-y", "kubernetes-mcp-server@latest"]
    }
  }
}

Goose CLI

Goose CLI is the easiest (and cheapest) way to get rolling with artificial intelligence (AI) agents.

Using npm

If you have npm installed, this is the fastest way to get started with kubernetes-mcp-server.

Open your goose config.yaml and add the mcp server to the list of mcpServers:

extensions:
  kubernetes:
    command: npx
    args:
      - -y
      - kubernetes-mcp-server@latest

🎥 Demos

Diagnosing and automatically fixing an OpenShift Deployment

Demo showcasing how Kubernetes MCP server is leveraged by Claude Desktop to automatically diagnose and fix a deployment in OpenShift without any user assistance.

https://github.com/user-attachments/assets/a576176d-a142-4c19-b9aa-a83dc4b8d941

Vibe Coding a simple game and deploying it to OpenShift

In this demo, I walk you through the process of Vibe Coding a simple game using VS Code and how to leverage Podman MCP server and Kubernetes MCP server to deploy it to OpenShift.

Vibe Coding: Build & Deploy a Game on Kubernetes

Supercharge GitHub Copilot with Kubernetes MCP Server in VS Code - One-Click Setup!

In this demo, I'll show you how to set up Kubernetes MCP server in VS code just by clicking a link.

Supercharge GitHub Copilot with Kubernetes MCP Server in VS Code - One-Click Setup!

⚙️ Configuration

The Kubernetes MCP server can be configured using command line (CLI) arguments.

You can run the CLI executable either by using npx, uvx, or by downloading the latest release binary.

# Run the Kubernetes MCP server using npx (in case you have npm and node installed)
npx kubernetes-mcp-server@latest --help
# Run the Kubernetes MCP server using uvx (in case you have uv and python installed)
uvx kubernetes-mcp-server@latest --help
# Run the Kubernetes MCP server using the latest release binary
./kubernetes-mcp-server --help

Configuration Options

Option Description
--port Starts the MCP server in Streamable HTTP mode (path /mcp) and Server-Sent Event (SSE) (path /sse) mode and listens on the specified port .
--log-level Sets the logging level (values from 0-9). Similar to kubectl logging levels.
--kubeconfig Path to the Kubernetes configuration file. If not provided, it will try to resolve the configuration (in-cluster, default location, etc.).
--list-output Output format for resource list operations (one of: yaml, table) (default "table")
--read-only If set, the MCP server will run in read-only mode, meaning it will not allow any write operations (create, update, delete) on the Kubernetes cluster. This is useful for debugging or inspecting the cluster without making changes.
--disable-destructive If set, the MCP server will disable all destructive operations (delete, update, etc.) on the Kubernetes cluster. This is useful for debugging or inspecting the cluster without accidentally making changes. This option has no effect when --read-only is used.
--toolsets Comma-separated list of toolsets to enable. Check the 🛠️ Tools and Functionalities section for more information.

🛠️ Tools and Functionalities

The Kubernetes MCP server supports enabling or disabling specific groups of tools and functionalities (tools, resources, prompts, and so on) via the --toolsets command-line flag or toolsets configuration option. This allows you to control which Kubernetes functionalities are available to your AI tools. Enabling only the toolsets you need can help reduce the context size and improve the LLM's tool selection accuracy.

Available Toolsets

The following sets of tools are available (all on by default):

Toolset Description
config View and manage the current local Kubernetes configuration (kubeconfig)
core Most common tools for Kubernetes management (Pods, Generic Resources, Events, etc.)
helm Tools for managing Helm charts and releases

Tools

config
  • configuration_view - Get the current Kubernetes configuration content as a kubeconfig YAML
    • minified (boolean) - Return a minified version of the configuration. If set to true, keeps only the current-context and the relevant pieces of the configuration for that context. If set to false, all contexts, clusters, auth-infos, and users are returned in the configuration. (Optional, default true)
core
  • events_list - List all the Kubernetes events in the current cluster from all namespaces

    • namespace (string) - Optional Namespace to retrieve the events from. If not provided, will list events from all namespaces
  • namespaces_list - List all the Kubernetes namespaces in the current cluster

  • projects_list - List all the OpenShift projects in the current cluster

  • pods_list - List all the Kubernetes pods in the current cluster from all namespaces

    • labelSelector (string) - Optional Kubernetes label selector (e.g. 'app=myapp,env=prod' or 'app in (myapp,yourapp)'), use this option when you want to filter the pods by label
  • pods_list_in_namespace - List all the Kubernetes pods in the specified namespace in the current cluster

    • labelSelector (string) - Optional Kubernetes label selector (e.g. 'app=myapp,env=prod' or 'app in (myapp,yourapp)'), use this option when you want to filter the pods by label
    • namespace (string) (required) - Namespace to list pods from
  • pods_get - Get a Kubernetes Pod in the current or provided namespace with the provided name

    • name (string) (required) - Name of the Pod
    • namespace (string) - Namespace to get the Pod from
  • pods_delete - Delete a Kubernetes Pod in the current or provided namespace with the provided name

    • name (string) (required) - Name of the Pod to delete
    • namespace (string) - Namespace to delete the Pod from
  • pods_top - List the resource consumption (CPU and memory) as recorded by the Kubernetes Metrics Server for the specified Kubernetes Pods in the all namespaces, the provided namespace, or the current namespace

    • all_namespaces (boolean) - If true, list the resource consumption for all Pods in all namespaces. If false, list the resource consumption for Pods in the provided namespace or the current namespace
    • label_selector (string) - Kubernetes label selector (e.g. 'app=myapp,env=prod' or 'app in (myapp,yourapp)'), use this option when you want to filter the pods by label (Optional, only applicable when name is not provided)
    • name (string) - Name of the Pod to get the resource consumption from (Optional, all Pods in the namespace if not provided)
    • namespace (string) - Namespace to get the Pods resource consumption from (Optional, current namespace if not provided and all_namespaces is false)
  • pods_exec - Execute a command in a Kubernetes Pod in the current or provided namespace with the provided name and command

    • command (array) (required) - Command to execute in the Pod container. The first item is the command to be run, and the rest are the arguments to that command. Example: ["ls", "-l", "/tmp"]
    • container (string) - Name of the Pod container where the command will be executed (Optional)
    • name (string) (required) - Name of the Pod where the command will be executed
    • namespace (string) - Namespace of the Pod where the command will be executed
  • pods_log - Get the logs of a Kubernetes Pod in the current or provided namespace with the provided name

    • container (string) - Name of the Pod container to get the logs from (Optional)
    • name (string) (required) - Name of the Pod to get the logs from
    • namespace (string) - Namespace to get the Pod logs from
    • previous (boolean) - Return previous terminated container logs (Optional)
    • tail (integer) - Number of lines to retrieve from the end of the logs (Optional, default: 100)
  • pods_run - Run a Kubernetes Pod in the current or provided namespace with the provided container image and optional name

    • image (string) (required) - Container Image to run in the Pod
    • name (string) - Name of the Pod (Optional, random name if not provided)
    • namespace (string) - Namespace to run the Pod in
    • port (number) - TCP/IP port to expose from the Pod container (Optional, no port exposed if not provided)
  • resources_list - List Kubernetes resources and objects in the current cluster by providing their apiVersion and kind and optionally the namespace and label selector (common apiVersion and kind include: v1 Pod, v1 Service, v1 Node, apps/v1 Deployment, networking.k8s.io/v1 Ingress, route.openshift.io/v1 Route)

    • apiVersion (string) (required) - apiVersion of the resources (examples of valid apiVersion are: v1, apps/v1, networking.k8s.io/v1)
    • kind (string) (required) - kind of the resources (examples of valid kind are: Pod, Service, Deployment, Ingress)
    • labelSelector (string) - Optional Kubernetes label selector (e.g. 'app=myapp,env=prod' or 'app in (myapp,yourapp)'), use this option when you want to filter the pods by label
    • namespace (string) - Optional Namespace to retrieve the namespaced resources from (ignored in case of cluster scoped resources). If not provided, will list resources from all namespaces
  • resources_get - Get a Kubernetes resource in the current cluster by providing its apiVersion, kind, optionally the namespace, and its name (common apiVersion and kind include: v1 Pod, v1 Service, v1 Node, apps/v1 Deployment, networking.k8s.io/v1 Ingress, route.openshift.io/v1 Route)

    • apiVersion (string) (required) - apiVersion of the resource (examples of valid apiVersion are: v1, apps/v1, networking.k8s.io/v1)
    • kind (string) (required) - kind of the resource (examples of valid kind are: Pod, Service, Deployment, Ingress)
    • name (string) (required) - Name of the resource
    • namespace (string) - Optional Namespace to retrieve the namespaced resource from (ignored in case of cluster scoped resources). If not provided, will get resource from configured namespace
  • resources_create_or_update - Create or update a Kubernetes resource in the current cluster by providing a YAML or JSON representation of the resource (common apiVersion and kind include: v1 Pod, v1 Service, v1 Node, apps/v1 Deployment, networking.k8s.io/v1 Ingress, route.openshift.io/v1 Route)

    • resource (string) (required) - A JSON or YAML containing a representation of the Kubernetes resource. Should include top-level fields such as apiVersion,kind,metadata, and spec
  • resources_delete - Delete a Kubernetes resource in the current cluster by providing its apiVersion, kind, optionally the namespace, and its name (common apiVersion and kind include: v1 Pod, v1 Service, v1 Node, apps/v1 Deployment, networking.k8s.io/v1 Ingress, route.openshift.io/v1 Route)

    • apiVersion (string) (required) - apiVersion of the resource (examples of valid apiVersion are: v1, apps/v1, networking.k8s.io/v1)
    • kind (string) (required) - kind of the resource (examples of valid kind are: Pod, Service, Deployment, Ingress)
    • name (string) (required) - Name of the resource
    • namespace (string) - Optional Namespace to delete the namespaced resource from (ignored in case of cluster scoped resources). If not provided, will delete resource from configured namespace
helm
  • helm_install - Install a Helm chart in the current or provided namespace

    • chart (string) (required) - Chart reference to install (for example: stable/grafana, oci://ghcr.io/nginxinc/charts/nginx-ingress)
    • name (string) - Name of the Helm release (Optional, random name if not provided)
    • namespace (string) - Namespace to install the Helm chart in (Optional, current namespace if not provided)
    • values (object) - Values to pass to the Helm chart (Optional)
  • helm_list - List all the Helm releases in the current or provided namespace (or in all namespaces if specified)

    • all_namespaces (boolean) - If true, lists all Helm releases in all namespaces ignoring the namespace argument (Optional)
    • namespace (string) - Namespace to list Helm releases from (Optional, all namespaces if not provided)
  • helm_uninstall - Uninstall a Helm release in the current or provided namespace

    • name (string) (required) - Name of the Helm release to uninstall
    • namespace (string) - Namespace to uninstall the Helm release from (Optional, current namespace if not provided)

🧑‍💻 Development

Running with mcp-inspector

Compile the project and run the Kubernetes MCP server with mcp-inspector to inspect the MCP server.

# Compile the project
make build
# Run the Kubernetes MCP server with mcp-inspector
npx @modelcontextprotocol/inspector@latest $(pwd)/kubernetes-mcp-server
Description
Model Context Protocol (MCP) server for Kubernetes and OpenShift
Readme Apache-2.0 16 MiB
Languages
Go 97.6%
Makefile 1.2%
Python 0.7%
JavaScript 0.4%