Kubernetes MCP server

Integrates with Kubernetes clusters to manage resources, retrieve pod logs, execute commands in containers, and apply YAML manifests with configurable timeouts and rate limiting for DevOps automation and cluster monitoring.
Back to servers
Setup instructions
Provider
Stacklok
Release date
Jun 06, 2025
Language
Java
Stats
43 stars

MKP is a Model Context Protocol (MCP) server for Kubernetes that enables LLM-powered applications to interact with Kubernetes clusters. It provides tools for listing, getting, applying, and managing Kubernetes resources through the MCP protocol, with native Go implementation for optimal performance and direct API integration.

Installation

Prerequisites

  • Go 1.24 or later
  • Kubernetes cluster and kubeconfig
  • Task for running tasks

Setup Steps

  1. Clone the repository:

    git clone https://github.com/StacklokLabs/mkp.git
    cd mkp
    
  2. Install dependencies:

    task install
    
  3. Build the server:

    task build
    

Running the Server

Basic Usage

Run the server with the default kubeconfig:

task run

With a specific kubeconfig:

KUBECONFIG=/path/to/kubeconfig task run-with-kubeconfig

On a specific port:

MCP_PORT=9091 task run

Configuration Options

Controlling Resource Discovery

You can disable resource discovery to save LLM context space:

# Without serving cluster resources
./build/mkp-server --serve-resources=false

# With specific kubeconfig
./build/mkp-server --kubeconfig=/path/to/kubeconfig --serve-resources=false

Enabling Write Operations

By default, MKP operates in read-only mode. Enable write operations with:

# Enable write operations
./build/mkp-server --read-write=true

# With specific kubeconfig
./build/mkp-server --kubeconfig=/path/to/kubeconfig --read-write=true

Rate Limiting

MKP includes built-in rate limiting with these defaults:

  • Read operations: 120 requests per minute
  • Write operations: 30 requests per minute
  • Other operations: 60 requests per minute

Configure rate limiting:

# With rate limiting (default)
./build/mkp-server

# Without rate limiting
./build/mkp-server --enable-rate-limiting=false

MCP Tools

get_resource

Retrieves a Kubernetes resource or its subresource.

Parameters:

  • resource_type (required): Type of resource (clustered or namespaced)
  • group: API group (e.g., apps, networking.k8s.io)
  • version (required): API version (e.g., v1, v1beta1)
  • resource (required): Resource name (e.g., deployments, services)
  • namespace: Namespace (required for namespaced resources)
  • name (required): Name of the resource
  • subresource: Subresource to get (e.g., status, scale, logs)
  • parameters: Optional parameters for the request

Example for getting a deployment status:

{
  "name": "get_resource",
  "arguments": {
    "resource_type": "namespaced",
    "group": "apps",
    "version": "v1",
    "resource": "deployments",
    "namespace": "default",
    "name": "nginx-deployment",
    "subresource": "status"
  }
}

Example for getting pod logs:

{
  "name": "get_resource",
  "arguments": {
    "resource_type": "namespaced",
    "group": "",
    "version": "v1",
    "resource": "pods",
    "namespace": "default",
    "name": "my-pod",
    "subresource": "logs",
    "parameters": {
      "container": "my-container",
      "sinceSeconds": "3600",
      "timestamps": "true",
      "limitBytes": "102400"
    }
  }
}

list_resources

Lists Kubernetes resources of a specific type.

Parameters:

  • resource_type (required): Type of resource (clustered or namespaced)
  • group: API group (e.g., apps, networking.k8s.io)
  • version (required): API version (e.g., v1, v1beta1)
  • resource (required): Resource name (e.g., deployments, services)
  • namespace: Namespace (required for namespaced resources)

Example:

{
  "name": "list_resources",
  "arguments": {
    "resource_type": "namespaced",
    "group": "apps",
    "version": "v1",
    "resource": "deployments",
    "namespace": "default"
  }
}

apply_resource

Creates or updates a Kubernetes resource.

Parameters:

  • resource_type (required): Type of resource (clustered or namespaced)
  • group: API group (e.g., apps, networking.k8s.io)
  • version (required): API version (e.g., v1, v1beta1)
  • resource (required): Resource name (e.g., deployments, services)
  • namespace: Namespace (required for namespaced resources)
  • manifest (required): Resource manifest

Example:

{
  "name": "apply_resource",
  "arguments": {
    "resource_type": "namespaced",
    "group": "apps",
    "version": "v1",
    "resource": "deployments",
    "namespace": "default",
    "manifest": {
      "apiVersion": "apps/v1",
      "kind": "Deployment",
      "metadata": {
        "name": "nginx-deployment",
        "namespace": "default"
      },
      "spec": {
        "replicas": 3,
        "selector": {
          "matchLabels": {
            "app": "nginx"
          }
        },
        "template": {
          "metadata": {
            "labels": {
              "app": "nginx"
            }
          },
          "spec": {
            "containers": [
              {
                "name": "nginx",
                "image": "nginx:latest",
                "ports": [
                  {
                    "containerPort": 80
                  }
                ]
              }
            ]
          }
        }
      }
    }
  }
}

post_resource

Posts to a Kubernetes resource or its subresource, useful for executing commands in pods.

Parameters:

  • resource_type (required): Type of resource (clustered or namespaced)
  • group: API group (e.g., apps, networking.k8s.io)
  • version (required): API version (e.g., v1, v1beta1)
  • resource (required): Resource name (e.g., deployments, services)
  • namespace: Namespace (required for namespaced resources)
  • name (required): Name of the resource
  • subresource: Subresource to post to (e.g., exec)
  • body (required): Body to post to the resource
  • parameters: Optional parameters for the request

Example for executing a command in a pod:

{
  "name": "post_resource",
  "arguments": {
    "resource_type": "namespaced",
    "group": "",
    "version": "v1",
    "resource": "pods",
    "namespace": "default",
    "name": "my-pod",
    "subresource": "exec",
    "body": {
      "command": ["ls", "-la", "/"],
      "container": "my-container",
      "timeout": 30
    }
  }
}

Running with ToolHive

MKP can be run as an MCP server using ToolHive.

Prerequisites

  1. Install ToolHive following the installation instructions
  2. Install Docker or Podman
  3. Configure your Kubernetes credentials (kubeconfig)

Running MKP with ToolHive

Using the packaged version:

# Register a client
thv client setup

# Run the MKP server
thv run --volume $HOME/.kube:/home/nonroot/.kube:ro k8s

# List running servers
thv list

# Get server info
thv registry info k8s

Using custom configuration:

# Run with custom configuration
thv run --name mkp --transport sse --target-port 8080 --volume $HOME/.kube:/home/nonroot/.kube:ro ghcr.io/stackloklabs/mkp/server:latest

Managing the Server

List running servers:

thv list

Stop the server:

# For packaged version
thv stop k8s

# For custom named version
thv stop mkp

Remove the server instance:

# For packaged version
thv rm k8s

# For custom named version
thv rm mkp

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":"thv","args":["run","--volume","$HOME/.kube:/home/nonroot/.kube:ro","k8s"]}'

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": "thv",
            "args": [
                "run",
                "--volume",
                "$HOME/.kube:/home/nonroot/.kube:ro",
                "k8s"
            ]
        }
    }
}

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": "thv",
            "args": [
                "run",
                "--volume",
                "$HOME/.kube:/home/nonroot/.kube:ro",
                "k8s"
            ]
        }
    }
}

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