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.
Clone the repository:
git clone https://github.com/StacklokLabs/mkp.git
cd mkp
Install dependencies:
task install
Build the server:
task build
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
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
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
MKP includes built-in rate limiting with these defaults:
Configure rate limiting:
# With rate limiting (default)
./build/mkp-server
# Without rate limiting
./build/mkp-server --enable-rate-limiting=false
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 resourcesubresource
: Subresource to get (e.g., status, scale, logs)parameters
: Optional parameters for the requestExample 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"
}
}
}
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"
}
}
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 manifestExample:
{
"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
}
]
}
]
}
}
}
}
}
}
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 resourcesubresource
: Subresource to post to (e.g., exec)body
(required): Body to post to the resourceparameters
: Optional parameters for the requestExample 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
}
}
}
MKP can be run as an MCP server using 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
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
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.
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.
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"
]
}
}
}
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.
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.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.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