A Model Context Protocol (MCP) server for Kubernetes that provides comprehensive cluster management capabilities without requiring kubectl to be installed locally. This server can be used in both STDIO and HTTP modes, making it perfect for integration with AI assistants like Claude in Cursor/VS Code.
- List Operations: List pods, namespaces, service accounts, deployments, replicasets, secrets, ingresses, services, and custom resource definitions
- Describe Operations: Get detailed information about specific resources
- Action Operations: Delete pods, restart deployments, scale deployments, create resources, and more
list_pods
- List all pods in a namespace or all namespaceslist_namespaces
- List all namespaceslist_service_accounts
- List service accountslist_deployments
- List deploymentslist_replicasets
- List replica setslist_secrets
- List secrets (without exposing secret data)list_ingresses
- List ingresseslist_services
- List serviceslist_crds
- List custom resource definitionsdescribe_pod
- Get detailed pod informationdescribe_namespace
- Get detailed namespace informationdescribe_service_account
- Get detailed service account informationdescribe_deployment
- Get detailed deployment informationdescribe_replicaset
- Get detailed replica set informationdescribe_secret
- Get secret metadata (without exposing secret data)describe_ingress
- Get detailed ingress informationdescribe_service
- Get detailed service informationdelete_pod
- Delete a podrestart_deployment
- Restart a deployment by triggering a rolloutscale_deployment
- Scale a deployment to a specific number of replicascreate_deployment
- Create a new deploymentcreate_namespace
- Create a new namespaceget_pod_logs
- Get logs from a podget_events
- Get cluster eventsport_forward_service
- Get instructions for port forwarding to a serviceport_forward_pod
- Get instructions for port forwarding to a pod
- Node.js 18 or higher
- Access to a Kubernetes cluster (local or remote)
- Valid kubeconfig file (typically at
~/.kube/config
)
- Clone the repository:
git clone <repository-url>
cd kubernetes-mcp-server
- Install dependencies:
npm install
- Build the project:
npm run build
The server uses your kubeconfig file to connect to Kubernetes clusters. By default, it looks for the kubeconfig at the standard location (~/.kube/config
).
To use a custom kubeconfig location, set the KUBECONFIG
environment variable:
export KUBECONFIG=/path/to/your/kubeconfig
The server supports both local and remote Kubernetes clusters:
- Local clusters (minikube, kind, Docker Desktop): Use the default kubeconfig
- Remote clusters (EKS, GKE, AKS, etc.): Configure your kubeconfig with the appropriate cluster credentials
You can switch between contexts using standard kubectl commands:
kubectl config use-context <context-name>
STDIO mode is the default mode for MCP servers integrated with AI assistants.
npm run dev
npm run build
npm start
HTTP mode exposes the MCP server over HTTP using Server-Sent Events (SSE).
npm run dev:http
npm run build
npm run start:http
By default, the server runs on port 3000. You can change this by setting the PORT
environment variable:
PORT=8080 npm run start:http
- Open your Cursor/VS Code settings
- Navigate to the MCP settings
- Add this server configuration:
For Cursor:
Edit your Cursor settings file (~/.cursor/config/settings.json
or through UI):
{
"mcp": {
"servers": {
"kubernetes": {
"command": "node",
"args": ["/absolute/path/to/kubernetes-mcp-server/dist/index.js"],
"env": {
"KUBECONFIG": "/Users/yourusername/.kube/config"
}
}
}
}
}
For VS Code with Claude: Edit your MCP settings file:
{
"mcpServers": {
"kubernetes": {
"command": "node",
"args": ["/absolute/path/to/kubernetes-mcp-server/dist/index.js"],
"env": {
"KUBECONFIG": "/Users/yourusername/.kube/config"
}
}
}
}
For HTTP mode, configure the MCP client to connect to the HTTP endpoint:
{
"mcpServers": {
"kubernetes": {
"url": "http://localhost:3000/message"
}
}
}
Once integrated, you can ask your AI assistant natural language questions like:
- "List all pods in the default namespace"
- "Show me the deployments in production"
- "Scale the web-app deployment to 3 replicas"
- "Get the logs from the api-server pod in the backend namespace"
- "Create a new namespace called staging"
- "Describe the nginx deployment in kube-system"
- "Restart the frontend deployment"
- "Show me all the events in the cluster"
kubernetes-mcp-server/
├── src/
│ ├── __tests__/ # Test files
│ ├── tools/ # Tool implementations
│ │ ├── list-tools.ts # List operations
│ │ ├── describe-tools.ts # Describe operations
│ │ └── action-tools.ts # Action operations
│ ├── k8s-client.ts # Kubernetes client wrapper
│ ├── server.ts # Main MCP server implementation
│ ├── index.ts # STDIO entry point
│ └── index-http.ts # HTTP entry point
├── dist/ # Compiled JavaScript
├── package.json
├── tsconfig.json
└── README.md
npm test
npm run test:watch
npm run lint
-
Kubeconfig Access: The server needs access to your kubeconfig file. Ensure it's properly secured with appropriate file permissions.
-
Secret Handling: The
describe_secret
andlist_secrets
tools intentionally do not expose secret data values, only metadata. -
RBAC: The server operates with the permissions of the kubeconfig context being used. Ensure appropriate RBAC policies are in place in your cluster.
-
HTTP Mode: When using HTTP mode, consider implementing authentication and running the server behind a reverse proxy with TLS in production.
- Verify your kubeconfig is valid:
kubectl cluster-info
- Check the KUBECONFIG environment variable is set correctly
- Ensure you have network access to the cluster
- Rebuild the project:
npm run build
- Restart the MCP server
- Check the Cursor/VS Code logs for detailed error messages
- Verify your kubeconfig user has appropriate RBAC permissions
- Check the service account permissions if using a service account token
Port forwarding operations return instructions rather than maintaining active connections, as MCP tools are designed to be stateless. For active port forwarding, use the returned kubectl command.
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass:
npm test
- Submit a pull request
MIT License - see LICENSE file for details
- Built with the Model Context Protocol SDK
- Uses the official Kubernetes JavaScript Client
For issues, questions, or contributions, please open an issue on GitHub.