https://github.com/rohitg00/kubectl-mcp-server
A Model Context Protocol (MCP) server for Kubernetes. Install: npx kubectl-mcp-server or pip install kubectl-mcp-tool
https://github.com/rohitg00/kubectl-mcp-server
ai deployment devops genai kubernetes kubernetes-cluster kubernetes-tools llms mcp mcp-server npm pypi
Last synced: 4 months ago
JSON representation
A Model Context Protocol (MCP) server for Kubernetes. Install: npx kubectl-mcp-server or pip install kubectl-mcp-tool
- Host: GitHub
- URL: https://github.com/rohitg00/kubectl-mcp-server
- Owner: rohitg00
- License: mit
- Created: 2025-03-23T17:49:07.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2026-01-22T01:05:50.000Z (4 months ago)
- Last Synced: 2026-01-22T08:58:19.162Z (4 months ago)
- Topics: ai, deployment, devops, genai, kubernetes, kubernetes-cluster, kubernetes-tools, llms, mcp, mcp-server, npm, pypi
- Language: Python
- Homepage: https://www.npmjs.com/package/kubectl-mcp-server
- Size: 95 MB
- Stars: 755
- Watchers: 10
- Forks: 147
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-mcp - rohitg00/kubectl-mcp-server
- awesome-mcp-servers - rohitg00/kubectl-mcp-server - A Model Context Protocol (MCP) server for Kubernetes, enabling AI assistants to interact with clusters through natural language via the MCP protocol. ([Read more](/details/rohitg00kubectl-mcp-server.md)) `mcp` `kubernetes` `cloud-native` `ai-integration` (Cloud & DevOps MCP Servers)
- awesome-devops-mcp-servers - rohitg00/kubectl-mcp-server - A Model Context Protocol (MCP) server for Kubernetes that enables AI assistants like Claude, Cursor, and others to interact with Kubernetes clusters through natural language. (Cloud Infrastructure / ๐ณ Container Orchestration)
- best-of-mcp-servers - GitHub - 6% open ยท โฑ๏ธ 08.04.2026) (Cloud Platforms)
- awesome-mcp-zh - rohitg00/kubectl-mcp-server
- awesome-mcp-servers - **kubectl-mcp-server** - Chat with your Kubernetes Cluster using AI tools and IDEs like Claude and Cursor! `python` `ai` `deployment` `devops` `genai` `pip install git+https://github.com/rohitg00/kubectl-mcp-server` (๐ค AI/ML)
- awesome-mcp - rohitg00/kubectl-mcp-server - kubectl-mcp-server is an MCP server for Kubernetes that enables AI assistants to manage Kubernetes clusters through natural language commands, providing comprehensive cluster operations, monitoring, security, and diagnostics. (MCP Servers / Cloud & DevOps)
- awesome-mcp-servers - rohitg00/kubectl-mcp-server - ClaudeใCursorใใใฎไปใฎAIใขใทในใฟใณใใ่ช็ถ่จ่ชใ้ใใฆKubernetesใฏใฉในใฟใผใจๅฏพ่ฉฑใงใใใใใซใใKubernetes็จModel Context Protocol๏ผMCP๏ผใตใผใใผใ (ใตใผใใผๅฎ่ฃ / โ๏ธ <a name="cloud-platforms"></a>ใฏใฉใฆใใใฉใใใใฉใผใ )
- metorial-index - Kubectl MCP Tool - Connect to Kubernetes clusters and manage resources using natural language commands. Enables AI assistants to interact with Kubernetes for efficient cluster management through intelligent command construction. (Task and Project Management)
- awesome-mcp-servers - kubectl MCP - language kubectl operations (CNCF listed) | Python | (Servers / Developer Tools)
- toolsdk-mcp-registry - โ kubectl-mcp-tool
- awesome-devops-mcp - rohitg00/kubectl-mcp-server - Enables AI assistants to interact with Kubernetes clusters through natural language (โ๏ธ Cloud Platforms)
- awesome-mcp-lists - GitHub
- awesome-mcp-servers - KubeMCP - A Model Context Protocol (MCP) server for Kubernetes that enables AI assistants like Claude, Cursor, and others to interact with Kubernetes clusters through natural language. (Table of Contents / AI Services)
- awesome-mcp-servers - rohitg00/kubectl-mcp-server - ClaudeใCursorใใใฎไปใฎAIใขใทในใฟใณใใ่ช็ถ่จ่ชใ้ใใฆKubernetesใฏใฉในใฟใผใจๅฏพ่ฉฑใงใใใใใซใใKubernetes็จModel Context Protocol๏ผMCP๏ผใตใผใใผใ (ใตใผใใผๅฎ่ฃ / โ๏ธ <a name="cloud-platforms"></a>ใฏใฉใฆใใใฉใใใใฉใผใ )
- awesome-mcp-security - rohitg00/kubectl-mcp-server - A Model Context Protocol (MCP) server for Kubernetes that enables AI assistants like Claude, Cursor, and others to interact with Kubernetes clusters through natural language. (Cloud Infrastructure / ๐ณ Container Orchestration)
- awesome-openclaw-skills - rohitg00/kubectl-mcp-server - mcp-server or pip install... | 858 | (MCP Servers & Protocol)
README
# Kubectl MCP Server
A Model Context Protocol (MCP) server for Kubernetes that enables AI assistants like Claude, Cursor, and others to interact with Kubernetes clusters through natural language.
[](https://github.com/rohitg00/kubectl-mcp-server)
[](https://opensource.org/licenses/MIT)
[](https://www.python.org/)
[](https://kubernetes.io/)
[](https://modelcontextprotocol.io)
[](https://pypi.org/project/kubectl-mcp-server/)
[](https://www.npmjs.com/package/kubectl-mcp-server)
[](https://hub.docker.com/r/rohitghumare64/kubectl-mcp-server)
[](https://github.com/rohitg00/kubectl-mcp-server)
[](https://aregistry.ai)
## MCP Client Compatibility
Works with all MCP-compatible AI assistants:
| Client | Status | Client | Status |
|--------|--------|--------|--------|
| Claude Desktop | โ
Native | Claude Code | โ
Native |
| Cursor | โ
Native | Windsurf | โ
Native |
| GitHub Copilot | โ
Native | OpenAI Codex | โ
Native |
| Gemini CLI | โ
Native | Goose | โ
Native |
| Roo Code | โ
Native | Kilo Code | โ
Native |
| Amp | โ
Native | Trae | โ
Native |
| OpenCode | โ
Native | Kiro CLI | โ
Native |
| Antigravity | โ
Native | Clawdbot | โ
Native |
| Droid (Factory) | โ
Native | Any MCP Client | โ
Compatible |
## Live Demos
### Claude Desktop

### Cursor AI

### Windsurf

## Features
### 127 MCP Tools for Complete Kubernetes Management
| Category | Tools |
|----------|-------|
| **Pods** | `get_pods`, `get_logs`, `get_pod_events`, `check_pod_health`, `exec_in_pod`, `cleanup_pods`, `get_pod_conditions`, `get_previous_logs` |
| **Deployments** | `get_deployments`, `create_deployment`, `scale_deployment`, `kubectl_rollout`, `restart_deployment` |
| **Workloads** | `get_statefulsets`, `get_daemonsets`, `get_jobs`, `get_replicasets` |
| **Services & Networking** | `get_services`, `get_ingress`, `get_endpoints`, `diagnose_network_connectivity`, `check_dns_resolution`, `trace_service_chain` |
| **Storage** | `get_persistent_volumes`, `get_pvcs`, `get_storage_classes` |
| **Config** | `get_configmaps`, `get_secrets`, `get_resource_quotas`, `get_limit_ranges` |
| **Cluster** | `get_nodes`, `get_namespaces`, `get_cluster_info`, `get_cluster_version`, `health_check`, `get_node_metrics`, `get_pod_metrics` |
| **RBAC & Security** | `get_rbac_roles`, `get_cluster_roles`, `get_service_accounts`, `audit_rbac_permissions`, `check_secrets_security`, `get_pod_security_info`, `get_admission_webhooks` |
| **CRDs** | `get_crds`, `get_priority_classes` |
| **Helm Releases** | `helm_list`, `helm_status`, `helm_history`, `helm_get_values`, `helm_get_manifest`, `helm_get_notes`, `helm_get_hooks`, `helm_get_all` |
| **Helm Charts** | `helm_show_chart`, `helm_show_values`, `helm_show_readme`, `helm_show_crds`, `helm_show_all`, `helm_search_repo`, `helm_search_hub` |
| **Helm Repos** | `helm_repo_list`, `helm_repo_add`, `helm_repo_remove`, `helm_repo_update` |
| **Helm Operations** | `install_helm_chart`, `upgrade_helm_chart`, `uninstall_helm_chart`, `helm_rollback`, `helm_test`, `helm_template`, `helm_template_apply` |
| **Helm Development** | `helm_create`, `helm_lint`, `helm_package`, `helm_pull`, `helm_dependency_list`, `helm_dependency_update`, `helm_dependency_build`, `helm_version`, `helm_env` |
| **Context** | `get_current_context`, `switch_context`, `list_contexts`, `list_kubeconfig_contexts` |
| **Diagnostics** | `diagnose_pod_crash`, `detect_pending_pods`, `get_evicted_pods`, `compare_namespaces` |
| **Operations** | `kubectl_apply`, `kubectl_create`, `kubectl_describe`, `kubectl_patch`, `delete_resource`, `kubectl_cp`, `backup_resource`, `label_resource`, `annotate_resource`, `taint_node`, `wait_for_condition` |
| **Autoscaling** | `get_hpa`, `get_pdb` |
| **Cost Optimization** | `get_resource_recommendations`, `get_idle_resources`, `get_resource_quotas_usage`, `get_cost_analysis`, `get_overprovisioned_resources`, `get_resource_trends`, `get_namespace_cost_allocation`, `optimize_resource_requests` |
| **Advanced** | `kubectl_generic`, `kubectl_explain`, `get_api_resources`, `port_forward`, `get_resource_usage`, `node_management` |
| **UI Dashboards** | `show_pod_logs_ui`, `show_pods_dashboard_ui`, `show_resource_yaml_ui`, `show_cluster_overview_ui`, `show_events_timeline_ui`, `render_k8s_dashboard_screenshot` |
### MCP Resources (FastMCP 3)
Access Kubernetes data as browsable resources:
| Resource URI | Description |
|--------------|-------------|
| `kubeconfig://contexts` | List all available kubectl contexts |
| `kubeconfig://current-context` | Get current active context |
| `namespace://current` | Get current namespace |
| `namespace://list` | List all namespaces |
| `cluster://info` | Get cluster information |
| `cluster://nodes` | Get detailed node information |
| `cluster://version` | Get Kubernetes version |
| `cluster://api-resources` | List available API resources |
| `manifest://deployments/{ns}/{name}` | Get deployment YAML |
| `manifest://services/{ns}/{name}` | Get service YAML |
| `manifest://pods/{ns}/{name}` | Get pod YAML |
| `manifest://configmaps/{ns}/{name}` | Get ConfigMap YAML |
| `manifest://secrets/{ns}/{name}` | Get secret YAML (data masked) |
| `manifest://ingresses/{ns}/{name}` | Get ingress YAML |
### MCP Prompts (FastMCP 3)
Pre-built workflow prompts for common Kubernetes operations:
| Prompt | Description |
|--------|-------------|
| `troubleshoot_workload` | Comprehensive troubleshooting guide for pods/deployments |
| `deploy_application` | Step-by-step deployment workflow |
| `security_audit` | Security scanning and RBAC analysis workflow |
| `cost_optimization` | Resource optimization and cost analysis workflow |
| `disaster_recovery` | Backup and recovery planning workflow |
| `debug_networking` | Network debugging for services and connectivity |
| `scale_application` | Scaling guide with HPA/VPA best practices |
| `upgrade_cluster` | Kubernetes cluster upgrade planning |
### Key Capabilities
- **Enhanced CLI**: 8 new subcommands for tool discovery, direct calling, and diagnostics
- **Multi-Transport Support**: stdio, SSE, HTTP/streamable-http
- **AI Assistant Integration**: Claude Desktop, Claude Code, Cursor, Windsurf
- **Multi-Cluster**: Context switching between clusters
- **Security**: Non-destructive mode, secrets masking, RBAC validation
- **Diagnostics**: Pod crash analysis, network connectivity testing, DNS resolution checks
- **Helm v3**: Full Helm chart lifecycle management
- **Cost Optimization**: Resource recommendations, idle resource detection, usage analysis
- **FastMCP 3**: MCP Resources and Prompts for enhanced AI workflows
- **MCP-UI Support**: Interactive HTML dashboards for compatible hosts (Goose, LibreChat)
- **Browser Automation**: 26 tools with cloud provider support (Browserbase, Browser Use)
## CLI Usage
kubectl-mcp-server now includes a powerful CLI for shell-friendly operation:
```bash
# List all tools with descriptions
kubectl-mcp-server tools -d
# Search for pod-related tools
kubectl-mcp-server grep "*pod*"
# Show specific tool schema
kubectl-mcp-server tools get_pods
# Call a tool directly
kubectl-mcp-server call get_pods '{"namespace": "kube-system"}'
# Pipe JSON from stdin
echo '{"namespace": "default"}' | kubectl-mcp-server call get_pods
# Check dependencies
kubectl-mcp-server doctor
# Show/switch Kubernetes context
kubectl-mcp-server context
kubectl-mcp-server context minikube
# List resources and prompts
kubectl-mcp-server resources
kubectl-mcp-server prompts
# Show server info
kubectl-mcp-server info
```
### CLI Features
- **Structured errors**: Actionable error messages with suggestions
- **Colorized output**: Human-readable with JSON mode for scripting (`--json`)
- **NO_COLOR support**: Respects `NO_COLOR` environment variable
- **Stdin support**: Pipe JSON arguments to commands
## Installation
### Prerequisites
- Python 3.9+
- kubectl CLI installed and configured
- Access to a Kubernetes cluster
### npm / npx (Recommended)
```bash
# Run directly without installation
npx kubectl-mcp-server
# Or install globally
npm install -g kubectl-mcp-server
```
### pip (Python)
```bash
pip install kubectl-mcp-server
# With MCP-UI support (interactive dashboards)
pip install kubectl-mcp-server[ui]
# Legacy alias (still works for backward compatibility)
pip install kubectl-mcp-tool
```
### Docker
```bash
# Pull the latest image
docker pull rohitghumare64/kubectl-mcp-server:latest
# Run with stdio transport
docker run -i -v $HOME/.kube:/root/.kube:ro rohitghumare64/kubectl-mcp-server:latest
# Run with SSE transport
docker run -p 8000:8000 -v $HOME/.kube:/root/.kube:ro rohitghumare64/kubectl-mcp-server:latest --transport sse
```
## Quick Start
### Claude Desktop
Add to `~/Library/Application Support/Claude/claude_desktop_config.json`:
```json
{
"mcpServers": {
"kubernetes": {
"command": "npx",
"args": ["-y", "kubectl-mcp-server"]
}
}
}
```
### Claude Code
Add to `~/.config/claude-code/mcp.json`:
```json
{
"mcpServers": {
"kubernetes": {
"command": "npx",
"args": ["-y", "kubectl-mcp-server"]
}
}
}
```
### Cursor AI
Add to `~/.cursor/mcp.json`:
```json
{
"mcpServers": {
"kubernetes": {
"command": "npx",
"args": ["-y", "kubectl-mcp-server"]
}
}
}
```
### Windsurf
Add to `~/.config/windsurf/mcp.json`:
```json
{
"mcpServers": {
"kubernetes": {
"command": "npx",
"args": ["-y", "kubectl-mcp-server"]
}
}
}
```
### GitHub Copilot (VS Code)
Add to VS Code `settings.json`:
```json
{
"mcp": {
"servers": {
"kubernetes": {
"command": "npx",
"args": ["-y", "kubectl-mcp-server"]
}
}
}
}
```
### Goose
Add to `~/.config/goose/config.yaml`:
```yaml
extensions:
kubernetes:
command: npx
args:
- -y
- kubectl-mcp-server
```
### Gemini CLI
Add to `~/.gemini/settings.json`:
```json
{
"mcpServers": {
"kubernetes": {
"command": "npx",
"args": ["-y", "kubectl-mcp-server"]
}
}
}
```
### Roo Code / Kilo Code
Add to `~/.config/roo-code/mcp.json` or `~/.config/kilo-code/mcp.json`:
```json
{
"mcpServers": {
"kubernetes": {
"command": "npx",
"args": ["-y", "kubectl-mcp-server"]
}
}
}
```
### Using Python Directly
If you prefer Python over npx:
```json
{
"mcpServers": {
"kubernetes": {
"command": "python",
"args": ["-m", "kubectl_mcp_tool.mcp_server"],
"env": {
"KUBECONFIG": "/path/to/.kube/config"
}
}
}
}
```
## Transport Modes
```bash
# stdio (default) - for Claude Desktop, Cursor, etc.
python -m kubectl_mcp_tool.mcp_server
# SSE - Server-Sent Events
python -m kubectl_mcp_tool.mcp_server --transport sse --port 8000
# HTTP
python -m kubectl_mcp_tool.mcp_server --transport http --port 8000
```
### Options
- `--transport`: `stdio`, `sse`, `http`, `streamable-http` (default: `stdio`)
- `--host`: Host to bind (default: `0.0.0.0`)
- `--port`: Port for network transports (default: `8000`)
- `--non-destructive`: Block destructive operations (delete, apply, create)
## Environment Variables
| Variable | Description |
|----------|-------------|
| `KUBECONFIG` | Path to kubeconfig file (default: `~/.kube/config`) |
| `MCP_DEBUG` | Set to `1` for verbose logging |
| `MCP_LOG_FILE` | Path to log file |
### Authentication (Enterprise)
| Variable | Description |
|----------|-------------|
| `MCP_AUTH_ENABLED` | Enable OAuth 2.1 authentication (default: `false`) |
| `MCP_AUTH_ISSUER` | OAuth 2.0 Authorization Server URL |
| `MCP_AUTH_JWKS_URI` | JWKS endpoint (optional, derived from issuer) |
| `MCP_AUTH_AUDIENCE` | Expected token audience (default: `kubectl-mcp-server`) |
| `MCP_AUTH_REQUIRED_SCOPES` | Required scopes (default: `mcp:tools`) |
### Browser Automation (Optional)
| Variable | Description |
|----------|-------------|
| `MCP_BROWSER_ENABLED` | Enable browser automation tools (default: `false`) |
## MCP-UI Tools (Interactive Dashboards)
Enable rich HTML dashboards in MCP-UI compatible hosts (Goose, LibreChat, Nanobot).
### Installation
```bash
# Install with MCP-UI support
pip install kubectl-mcp-server[ui]
```
### 6 UI Dashboard Tools
| Tool | Description |
|------|-------------|
| `show_pod_logs_ui` | Interactive log viewer with search and filtering |
| `show_pods_dashboard_ui` | Pods table with status, restarts, and filtering |
| `show_resource_yaml_ui` | YAML viewer with syntax highlighting |
| `show_cluster_overview_ui` | Cluster dashboard with nodes, namespaces, workloads |
| `show_events_timeline_ui` | Events timeline with severity filtering |
| `render_k8s_dashboard_screenshot` | Render any dashboard as PNG screenshot |
### Features
- **Dark theme**: Catppuccin-style dark UI optimized for terminals
- **Graceful fallback**: Returns JSON data if MCP-UI not supported
- **Screenshot rendering**: Works with agent-browser for universal compatibility
- **No external dependencies**: Pure HTML/CSS/JS dashboards
### Compatibility
| Host | MCP-UI Support | Fallback |
|------|----------------|----------|
| Goose | โ
Full | - |
| LibreChat | โ
Full | - |
| Nanobot | โ
Full | - |
| Claude Desktop | โ | JSON + Screenshot |
| Cursor | โ | JSON + Screenshot |
| Other MCP Clients | โ | JSON + Screenshot |
## Browser Tools (Optional Module)
Enable browser automation for web-based K8s operations using [agent-browser](https://github.com/vercel-labs/agent-browser).
### Setup
```bash
# Install agent-browser
npm install -g agent-browser
agent-browser install # Download Chromium
# Enable browser tools
export MCP_BROWSER_ENABLED=true
kubectl-mcp-server
```
### 26 Browser Tools (agent-browser v0.7+)
| Tool | Description |
|------|-------------|
| `browser_open` | Open URL in browser (with headers/session support) |
| `browser_snapshot` | Get page accessibility tree |
| `browser_click` | Click element by ref |
| `browser_fill` | Fill form field |
| `browser_screenshot` | Take screenshot |
| `browser_get_text` | Get element text |
| `browser_get_url` | Get current URL |
| `browser_wait` | Wait for element/text/timeout |
| `browser_close` | Close browser |
| `browser_connect_cdp` | **NEW**: Connect to remote browser via CDP |
| `browser_install` | **NEW**: Install Chromium browser |
| `browser_set_provider` | **NEW**: Configure cloud provider (Browserbase/Browser Use) |
| `browser_session_list` | **NEW**: List active browser sessions |
| `browser_session_switch` | **NEW**: Switch to different session |
| `browser_open_with_headers` | **NEW**: Open URL with auth headers |
| `browser_set_viewport` | **NEW**: Set viewport or emulate device |
| `browser_test_ingress` | Test K8s service via Ingress |
| `browser_screenshot_service` | Screenshot K8s service UI |
| `browser_screenshot_grafana` | Screenshot Grafana dashboard |
| `browser_screenshot_argocd` | Screenshot ArgoCD app |
| `browser_health_check` | Health check web app |
| `browser_form_submit` | Fill and submit form |
| `browser_session_save` | Save browser session |
| `browser_session_load` | Load browser session |
| `browser_open_cloud_console` | Open EKS/GKE/AKS console |
| `browser_pdf_export` | Export page as PDF |
### Browser v0.7 Features
- **Cloud providers**: Browserbase, Browser Use
- **Persistent profiles**: Keep cookies/storage across restarts
- **Remote CDP**: Connect to existing browser instances
- **Retry with exponential backoff**: Auto-retry transient errors
#### Environment Variables
| Variable | Description | Example |
|----------|-------------|---------|
| `MCP_BROWSER_ENABLED` | Enable browser tools | `true` |
| `MCP_BROWSER_PROVIDER` | Cloud provider | `browserbase` / `browseruse` |
| `MCP_BROWSER_PROFILE` | Persistent profile path | `~/.k8s-browser` |
| `MCP_BROWSER_CDP_URL` | Remote CDP WebSocket | `wss://...` |
| `MCP_BROWSER_PROXY` | Proxy server URL | `http://proxy:8080` |
| `MCP_BROWSER_USER_AGENT` | Custom user agent | `Mozilla/5.0...` |
| `MCP_BROWSER_SESSION` | Session name | `k8s-session` |
| `MCP_BROWSER_HEADED` | Show browser window | `true` |
### Use Cases
- **Test deployed apps** via Ingress URLs
- **Screenshot Grafana/ArgoCD** dashboards
- **Automate cloud console** operations (EKS, GKE, AKS)
- **Health check** web applications
- **Export monitoring dashboards** as PDF
## MCP Authorization (RFC 9728)
For enterprise deployments, kubectl-mcp-server supports OAuth 2.1 authentication.
```bash
export MCP_AUTH_ENABLED=true
export MCP_AUTH_ISSUER=https://your-idp.example.com
export MCP_AUTH_AUDIENCE=kubectl-mcp-server
kubectl-mcp-server --transport http --port 8000
```
Supported identity providers: **Okta**, **Auth0**, **Keycloak**, **Microsoft Entra ID**, **Google OAuth**, and any OIDC-compliant provider.
## Docker MCP Toolkit
Compatible with [Docker MCP Toolkit](https://docs.docker.com/ai/mcp-catalog-and-toolkit/toolkit/):
```bash
# Add server
docker mcp server add kubectl-mcp-server mcp/kubectl-mcp-server:latest
# Configure kubeconfig
docker mcp server configure kubectl-mcp-server --volume "$HOME/.kube:/root/.kube:ro"
# Enable and connect
docker mcp server enable kubectl-mcp-server
docker mcp client connect claude
```
## agentregistry
kubectl-mcp-server is published to [agentregistry](https://github.com/agentregistry-dev/agentregistry), a centralized registry for MCP servers.
### Install with arctl
```bash
# Install arctl CLI
curl -fsSL https://raw.githubusercontent.com/agentregistry-dev/agentregistry/main/scripts/install.sh | bash
# Search for kubectl-mcp-server
arctl mcp search kubectl
# Install the server
arctl mcp install io.github.rohitg00/kubectl-mcp-server
```
### Available Packages
| Registry | Identifier |
|----------|------------|
| **PyPI** | `kubectl-mcp-server` (uvx) |
| **npm** | `kubectl-mcp-server` (npx) |
| **OCI** | `docker.io/rohitghumare64/kubectl-mcp-server` |
### agentgateway Integration
Use with [agentgateway](https://github.com/agentgateway/agentgateway) for unified MCP routing to multiple MCP servers.
```bash
# Start kubectl-mcp-server with streamable-http transport
kubectl-mcp-server --transport streamable-http --port 8000
```
Create `gateway.yaml`:
```yaml
binds:
- port: 3000
listeners:
- routes:
- backends:
- mcp:
targets:
- name: kubectl-mcp-server
mcp:
host: http://localhost:8000/mcp
```
```bash
# Run agentgateway
agentgateway --config gateway.yaml
```
Connect MCP clients to `http://localhost:3000/mcp`. All 127 tools are discoverable through the gateway.
## Kubernetes Deployment
Deploy kubectl-mcp-server directly in your Kubernetes cluster for centralized access.
### kMCP Deployment (Recommended)
[kMCP](https://github.com/kagent-dev/kmcp) is a development platform and control plane for MCP servers. See [kMCP quickstart](https://kagent.dev/docs/kmcp/quickstart).
```bash
# Install kmcp CLI
curl -fsSL https://raw.githubusercontent.com/kagent-dev/kmcp/refs/heads/main/scripts/get-kmcp.sh | bash
# Install kmcp controller in your cluster
helm install kmcp-crds oci://ghcr.io/kagent-dev/kmcp/helm/kmcp-crds \
--namespace kmcp-system --create-namespace
kmcp install
# Deploy kubectl-mcp-server using npx (easiest)
kmcp deploy package --deployment-name kubectl-mcp-server \
--manager npx --args kubectl-mcp-server
# Or deploy using our Docker image with the MCPServer manifest
kmcp deploy --file deploy/kmcp/kmcp.yaml --image rohitghumare64/kubectl-mcp-server:latest
```
### Standard Kubernetes Deployment
Deploy using kubectl/kustomize without kMCP:
```bash
# Using kustomize (recommended)
kubectl apply -k deploy/kubernetes/
# Or apply individual manifests
kubectl apply -f deploy/kubernetes/namespace.yaml
kubectl apply -f deploy/kubernetes/rbac.yaml
kubectl apply -f deploy/kubernetes/deployment.yaml
kubectl apply -f deploy/kubernetes/service.yaml
# Access via port-forward
kubectl port-forward -n kubectl-mcp svc/kubectl-mcp-server 8000:8000
```
### MCPServer Custom Resource
For kMCP deployments, apply this MCPServer resource:
```yaml
apiVersion: kagent.dev/v1alpha1
kind: MCPServer
metadata:
name: kubectl-mcp-server
spec:
deployment:
image: "rohitghumare64/kubectl-mcp-server:latest"
port: 8000
transportType: http
httpTransport:
targetPort: 8000
path: /mcp
```
See [deploy/](deploy/) for full manifests and configuration options.
### kagent Integration (AI Agents)
[kagent](https://github.com/kagent-dev/kagent) is a Kubernetes-native AI agent framework (CNCF project). Register kubectl-mcp-server as a ToolServer to give your agents 127 K8s management tools.
```bash
# Install kagent
brew install kagent
kagent install --profile demo
# Register kubectl-mcp-server as a ToolServer
kubectl apply -f deploy/kagent/toolserver-stdio.yaml
# Open kagent dashboard and chat with your K8s agent
kagent dashboard
```
See [kagent quickstart](https://kagent.dev/docs/kagent/getting-started/quickstart) for full documentation.
## Architecture
```
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ AI Assistant โโโโโโถโ MCP Server โโโโโโถโ Kubernetes API โ
โ (Claude/Cursor) โโโโโโโ (kubectl-mcp) โโโโโโโ (kubectl) โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
```
The MCP server implements the [Model Context Protocol](https://github.com/modelcontextprotocol/spec), translating natural language requests into kubectl operations.
### Modular Structure
```
kubectl_mcp_tool/
โโโ mcp_server.py # Main server (FastMCP, transports)
โโโ tools/ # 127 MCP tools organized by category
โ โโโ pods.py # Pod management & diagnostics
โ โโโ deployments.py # Deployments, StatefulSets, DaemonSets
โ โโโ core.py # Namespaces, ConfigMaps, Secrets
โ โโโ cluster.py # Context/cluster management
โ โโโ networking.py # Services, Ingress, NetworkPolicies
โ โโโ storage.py # PVCs, StorageClasses, PVs
โ โโโ security.py # RBAC, ServiceAccounts, PodSecurity
โ โโโ helm.py # Complete Helm v3 operations
โ โโโ operations.py # kubectl apply/patch/describe/etc
โ โโโ diagnostics.py # Metrics, namespace comparison
โ โโโ cost.py # Resource optimization & cost analysis
โ โโโ ui.py # MCP-UI interactive dashboards
โโโ resources/ # 8 MCP Resources for data exposure
โโโ prompts/ # 8 MCP Prompts for workflows
โโโ cli/ # CLI interface
```
## Multi-Cluster Support
```bash
# List contexts
list_contexts
# Switch cluster
switch_context --context_name production
# Get context details
get_context_details --context_name staging
```
## Development & Testing
### Setup Development Environment
```bash
# Clone the repository
git clone https://github.com/rohitg00/kubectl-mcp-server.git
cd kubectl-mcp-server
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install development dependencies
pip install -r requirements-dev.txt
```
### Running Tests
```bash
# Run all tests
pytest tests/ -v
# Run specific test file
pytest tests/test_tools.py -v
# Run with coverage
pytest tests/ --cov=kubectl_mcp_tool --cov-report=html
# Run only unit tests
pytest tests/ -v -m unit
```
### Test Structure
```
tests/
โโโ __init__.py # Test package
โโโ conftest.py # Shared fixtures and mocks
โโโ test_tools.py # Unit tests for 121 MCP tools
โโโ test_resources.py # Tests for 8 MCP Resources
โโโ test_prompts.py # Tests for 8 MCP Prompts
โโโ test_server.py # Server initialization tests
```
**138 tests covering**: tool registration, resource exposure, prompt generation, server initialization, non-destructive mode, secret masking, error handling, and transport methods.
### Code Quality
```bash
# Format code
black kubectl_mcp_tool tests
# Sort imports
isort kubectl_mcp_tool tests
# Lint
flake8 kubectl_mcp_tool tests
# Type checking
mypy kubectl_mcp_tool
```
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## License
MIT License - see [LICENSE](LICENSE) for details.
## Links
- [PyPI Package](https://pypi.org/project/kubectl-mcp-server/)
- [npm Package](https://www.npmjs.com/package/kubectl-mcp-server)
- [Docker Hub](https://hub.docker.com/r/rohitghumare64/kubectl-mcp-server)
- [GitHub Issues](https://github.com/rohitg00/kubectl-mcp-server/issues)