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.
pip install kubectl-mcp-tool
To install a specific version:
pip install kubectl-mcp-tool==1.1.1
pip install git+https://github.com/rohitg00/kubectl-mcp-server.git
After installation, verify the tool is working correctly:
kubectl-mcp --help
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
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"
}
}
}
}
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"
}
}
}
}
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.
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"
}
}
}
}
For automatic configuration of all supported AI assistants:
bash install.sh
You can customize the server behavior with environment variables:
MCP_LOG_FILE
: Path to log fileMCP_DEBUG
: Set to "1" for verbose loggingMCP_TEST_MOCK_MODE
: Set to "1" to use mock data instead of real clusterKUBECONFIG
: Path to your Kubernetes config fileKUBECTL_MCP_LOG_LEVEL
: Set to "DEBUG", "INFO", "WARNING", or "ERROR"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
Once configured, you can interact with your Kubernetes cluster by asking natural language questions in your AI assistant. Examples include:
The tool will translate these requests into the appropriate kubectl commands and return the results.
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.
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": "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"
}
}
}
}
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": "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