kubectl-mcp-server 1.6.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,133 +5,121 @@ A Model Context Protocol (MCP) server for Kubernetes that enables AI assistants
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
6
  [![Python](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/)
7
7
  [![Kubernetes](https://img.shields.io/badge/kubernetes-%23326ce5.svg?style=flat&logo=kubernetes&logoColor=white)](https://kubernetes.io/)
8
- [![MCP](https://img.shields.io/badge/MCP-compatible-green.svg)](https://github.com/modelcontextprotocol/modelcontextprotocol)
9
- [![PyPI version](https://badge.fury.io/py/kubectl-mcp-tool.svg)](https://pypi.org/project/kubectl-mcp-tool/)
10
- [![npm version](https://badge.fury.io/js/kubectl-mcp-server.svg)](https://www.npmjs.com/package/kubectl-mcp-server)
8
+ [![MCP](https://img.shields.io/badge/MCP-compatible-green.svg)](https://modelcontextprotocol.io)
9
+ [![PyPI](https://img.shields.io/pypi/v/kubectl-mcp-tool?color=blue&label=PyPI)](https://pypi.org/project/kubectl-mcp-tool/)
10
+ [![npm](https://img.shields.io/npm/v/kubectl-mcp-server?color=green&label=npm)](https://www.npmjs.com/package/kubectl-mcp-server)
11
11
  [![Docker](https://img.shields.io/docker/pulls/rohitghumare64/kubectl-mcp-server.svg)](https://hub.docker.com/r/rohitghumare64/kubectl-mcp-server)
12
+ [![Tests](https://img.shields.io/badge/tests-135%20passed-success)](https://github.com/rohitg00/kubectl-mcp-server)
12
13
 
13
- ## 🎥 Live Demo - Watch `kubectl-mcp-tool` in Action with Claude!
14
- ![Claude MCP](./docs/claude/claude-mcp.gif)
15
-
16
- ## 🎥 Live Demo - Watch `kubectl-mcp-tool` in Action with Cursor!
17
- ![Cursor MCP](./docs/cursor/cursor-mcp.gif)
18
-
19
- ## 🎥 Live Demo - Watch `kubectl-mcp-tool` in Action with Windsurf!
20
- ![Windsurf MCP](./docs/windsurf/windsurf-mcp.gif)
21
-
14
+ ## MCP Client Compatibility
22
15
 
23
- ## Features
16
+ Works with all MCP-compatible AI assistants:
24
17
 
25
- ### Core Kubernetes Operations
26
- - [x] Connect to a Kubernetes cluster
27
- - [x] List and manage pods, services, deployments, and nodes
28
- - [x] Create, delete, and describe pods and other resources
29
- - [x] Get pod logs and Kubernetes events
30
- - [x] Support for Helm v3 operations (installation, upgrades, uninstallation)
31
- - [x] kubectl explain and api-resources support
32
- - [x] Choose namespace for next commands (memory persistence)
33
- - [x] Port forward to pods
34
- - [x] Scale deployments and statefulsets
35
- - [x] Execute commands in containers
36
- - [x] Manage ConfigMaps and Secrets
37
- - [x] Rollback deployments to previous versions
38
- - [x] Ingress and NetworkPolicy management
39
- - [x] Context switching between clusters
40
-
41
- ### Natural Language Processing
42
- - [x] Process natural language queries for kubectl operations
43
- - [x] Context-aware commands with memory of previous operations
44
- - [x] Human-friendly explanations of Kubernetes concepts
45
- - [x] Intelligent command construction from intent
46
- - [x] Fallback to kubectl when specialized tools aren't available
47
- - [x] Mock data support for offline/testing scenarios
48
- - [x] Namespace-aware query handling
49
-
50
- ### Monitoring
51
- - [x] Cluster health monitoring
52
- - [x] Resource utilization tracking
53
- - [x] Pod status and health checks
54
- - [x] Event monitoring and alerting
55
- - [x] Node capacity and allocation analysis
56
- - [x] Historical performance tracking
57
- - [x] Resource usage statistics via kubectl top
58
- - [x] Container readiness and liveness tracking
59
-
60
- ### Security
61
- - [x] RBAC validation and verification
62
- - [x] Security context auditing
63
- - [x] Secure connections to Kubernetes API
64
- - [x] Credentials management
65
- - [x] Network policy assessment
66
- - [x] Container security scanning
67
- - [x] Security best practices enforcement
68
- - [x] Role and ClusterRole management
69
- - [x] ServiceAccount creation and binding
70
- - [x] PodSecurityPolicy analysis
71
- - [x] RBAC permissions auditing
72
- - [x] Security context validation
73
-
74
- ### Diagnostics
75
- - [x] Cluster diagnostics and troubleshooting
76
- - [x] Configuration validation
77
- - [x] Error analysis and recovery suggestions
78
- - [x] Connection status monitoring
79
- - [x] Log analysis and pattern detection
80
- - [x] Resource constraint identification
81
- - [x] Pod health check diagnostics
82
- - [x] Common error pattern identification
83
- - [x] Resource validation for misconfigurations
84
- - [x] Detailed liveness and readiness probe validation
85
-
86
- ### Advanced Features
87
- - [x] Multiple transport protocols support (stdio, SSE, HTTP/streamable-http)
88
- - [x] Integration with multiple AI assistants (Claude Desktop, Claude Code, Cursor, Windsurf)
89
- - [x] Multi-cluster support with context switching
90
- - [x] Extensible tool framework
91
- - [x] Custom resource definition support
92
- - [x] Cross-namespace operations
93
- - [x] Batch operations on multiple resources
94
- - [x] Intelligent resource relationship mapping
95
- - [x] Error explanation with recovery suggestions
96
- - [x] Volume management and identification
97
- - [x] Command injection protection with input validation
98
- - [x] Non-destructive mode (`--non-destructive` flag)
99
- - [x] Secrets masking in output
100
- - [x] Helm template rendering and application
101
- - [x] Node management (cordon, drain, uncordon)
102
- - [x] Pod cleanup for failed/evicted pods
103
- - [x] Guided troubleshooting prompts
18
+ | Client | Status | Client | Status |
19
+ |--------|--------|--------|--------|
20
+ | Claude Desktop | Native | Claude Code | ✅ Native |
21
+ | Cursor | Native | Windsurf | Native |
22
+ | GitHub Copilot | Native | OpenAI Codex | ✅ Native |
23
+ | Gemini CLI | Native | Goose | ✅ Native |
24
+ | Roo Code | Native | Kilo Code | ✅ Native |
25
+ | Amp | Native | Trae | ✅ Native |
26
+ | OpenCode | Native | Kiro CLI | ✅ Native |
27
+ | Antigravity | Native | Clawdbot | ✅ Native |
28
+ | Droid (Factory) | Native | Any MCP Client | ✅ Compatible |
104
29
 
105
- ## Architecture
30
+ ## Live Demos
106
31
 
107
- ### Model Context Protocol (MCP) Integration
108
-
109
- The Kubectl MCP Tool implements the [Model Context Protocol (MCP)](https://github.com/modelcontextprotocol/spec), enabling AI assistants to interact with Kubernetes clusters through a standardized interface. The architecture consists of:
110
-
111
- 1. **MCP Server**: A compliant server that handles requests from MCP clients (AI assistants)
112
- 2. **Tools Registry**: Registers Kubernetes operations as MCP tools with schemas
113
- 3. **Transport Layer**: Supports stdio, SSE, and HTTP transport methods
114
- 4. **Core Operations**: Translates tool calls to Kubernetes API operations
115
- 5. **Response Formatter**: Converts Kubernetes responses to MCP-compliant responses
32
+ ### Claude Desktop
33
+ ![Claude MCP](./docs/claude/claude-mcp.gif)
116
34
 
117
- ### Request Flow
35
+ ### Cursor AI
36
+ ![Cursor MCP](./docs/cursor/cursor-mcp.gif)
118
37
 
119
- ![Request Flow](./image.png)
38
+ ### Windsurf
39
+ ![Windsurf MCP](./docs/windsurf/windsurf-mcp.gif)
120
40
 
121
- ### Dual Mode Operation
41
+ ## Features
122
42
 
123
- The tool operates in two modes:
43
+ ### 121 MCP Tools for Complete Kubernetes Management
124
44
 
125
- 1. **CLI Mode**: Direct command-line interface for executing Kubernetes operations
126
- 2. **Server Mode**: Running as an MCP server to handle requests from AI assistants
45
+ | Category | Tools |
46
+ |----------|-------|
47
+ | **Pods** | `get_pods`, `get_logs`, `get_pod_events`, `check_pod_health`, `exec_in_pod`, `cleanup_pods`, `get_pod_conditions`, `get_previous_logs` |
48
+ | **Deployments** | `get_deployments`, `create_deployment`, `scale_deployment`, `kubectl_rollout`, `restart_deployment` |
49
+ | **Workloads** | `get_statefulsets`, `get_daemonsets`, `get_jobs`, `get_replicasets` |
50
+ | **Services & Networking** | `get_services`, `get_ingress`, `get_endpoints`, `diagnose_network_connectivity`, `check_dns_resolution`, `trace_service_chain` |
51
+ | **Storage** | `get_persistent_volumes`, `get_pvcs`, `get_storage_classes` |
52
+ | **Config** | `get_configmaps`, `get_secrets`, `get_resource_quotas`, `get_limit_ranges` |
53
+ | **Cluster** | `get_nodes`, `get_namespaces`, `get_cluster_info`, `get_cluster_version`, `health_check`, `get_node_metrics`, `get_pod_metrics` |
54
+ | **RBAC & Security** | `get_rbac_roles`, `get_cluster_roles`, `get_service_accounts`, `audit_rbac_permissions`, `check_secrets_security`, `get_pod_security_info`, `get_admission_webhooks` |
55
+ | **CRDs** | `get_crds`, `get_priority_classes` |
56
+ | **Helm Releases** | `helm_list`, `helm_status`, `helm_history`, `helm_get_values`, `helm_get_manifest`, `helm_get_notes`, `helm_get_hooks`, `helm_get_all` |
57
+ | **Helm Charts** | `helm_show_chart`, `helm_show_values`, `helm_show_readme`, `helm_show_crds`, `helm_show_all`, `helm_search_repo`, `helm_search_hub` |
58
+ | **Helm Repos** | `helm_repo_list`, `helm_repo_add`, `helm_repo_remove`, `helm_repo_update` |
59
+ | **Helm Operations** | `install_helm_chart`, `upgrade_helm_chart`, `uninstall_helm_chart`, `helm_rollback`, `helm_test`, `helm_template`, `helm_template_apply` |
60
+ | **Helm Development** | `helm_create`, `helm_lint`, `helm_package`, `helm_pull`, `helm_dependency_list`, `helm_dependency_update`, `helm_dependency_build`, `helm_version`, `helm_env` |
61
+ | **Context** | `get_current_context`, `switch_context`, `list_contexts`, `list_kubeconfig_contexts` |
62
+ | **Diagnostics** | `diagnose_pod_crash`, `detect_pending_pods`, `get_evicted_pods`, `compare_namespaces` |
63
+ | **Operations** | `kubectl_apply`, `kubectl_create`, `kubectl_describe`, `kubectl_patch`, `delete_resource`, `kubectl_cp`, `backup_resource`, `label_resource`, `annotate_resource`, `taint_node`, `wait_for_condition` |
64
+ | **Autoscaling** | `get_hpa`, `get_pdb` |
65
+ | **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` |
66
+ | **Advanced** | `kubectl_generic`, `kubectl_explain`, `get_api_resources`, `port_forward`, `get_resource_usage`, `node_management` |
67
+
68
+ ### MCP Resources (FastMCP 3)
69
+
70
+ Access Kubernetes data as browsable resources:
71
+
72
+ | Resource URI | Description |
73
+ |--------------|-------------|
74
+ | `kubeconfig://contexts` | List all available kubectl contexts |
75
+ | `kubeconfig://current-context` | Get current active context |
76
+ | `namespace://current` | Get current namespace |
77
+ | `namespace://list` | List all namespaces |
78
+ | `cluster://info` | Get cluster information |
79
+ | `cluster://nodes` | Get detailed node information |
80
+ | `cluster://version` | Get Kubernetes version |
81
+ | `cluster://api-resources` | List available API resources |
82
+ | `manifest://deployments/{ns}/{name}` | Get deployment YAML |
83
+ | `manifest://services/{ns}/{name}` | Get service YAML |
84
+ | `manifest://pods/{ns}/{name}` | Get pod YAML |
85
+ | `manifest://configmaps/{ns}/{name}` | Get ConfigMap YAML |
86
+ | `manifest://secrets/{ns}/{name}` | Get secret YAML (data masked) |
87
+ | `manifest://ingresses/{ns}/{name}` | Get ingress YAML |
88
+
89
+ ### MCP Prompts (FastMCP 3)
90
+
91
+ Pre-built workflow prompts for common Kubernetes operations:
92
+
93
+ | Prompt | Description |
94
+ |--------|-------------|
95
+ | `troubleshoot_workload` | Comprehensive troubleshooting guide for pods/deployments |
96
+ | `deploy_application` | Step-by-step deployment workflow |
97
+ | `security_audit` | Security scanning and RBAC analysis workflow |
98
+ | `cost_optimization` | Resource optimization and cost analysis workflow |
99
+ | `disaster_recovery` | Backup and recovery planning workflow |
100
+ | `debug_networking` | Network debugging for services and connectivity |
101
+ | `scale_application` | Scaling guide with HPA/VPA best practices |
102
+ | `upgrade_cluster` | Kubernetes cluster upgrade planning |
103
+
104
+ ### Key Capabilities
105
+
106
+ - **Multi-Transport Support**: stdio, SSE, HTTP/streamable-http
107
+ - **AI Assistant Integration**: Claude Desktop, Claude Code, Cursor, Windsurf
108
+ - **Multi-Cluster**: Context switching between clusters
109
+ - **Security**: Non-destructive mode, secrets masking, RBAC validation
110
+ - **Diagnostics**: Pod crash analysis, network connectivity testing, DNS resolution checks
111
+ - **Helm v3**: Full Helm chart lifecycle management
112
+ - **Cost Optimization**: Resource recommendations, idle resource detection, usage analysis
113
+ - **FastMCP 3**: MCP Resources and Prompts for enhanced AI workflows
127
114
 
128
115
  ## Installation
129
116
 
130
- For detailed installation instructions, please see the [Installation Guide](./docs/INSTALLATION.md).
131
-
132
- ### npm / npx (Recommended for Node.js users)
117
+ ### Prerequisites
118
+ - Python 3.9+
119
+ - kubectl CLI installed and configured
120
+ - Access to a Kubernetes cluster
133
121
 
134
- The easiest way to run kubectl-mcp-server is via npx:
122
+ ### npm / npx (Recommended)
135
123
 
136
124
  ```bash
137
125
  # Run directly without installation
@@ -139,289 +127,33 @@ npx kubectl-mcp-server
139
127
 
140
128
  # Or install globally
141
129
  npm install -g kubectl-mcp-server
142
- kubectl-mcp-server
143
130
  ```
144
131
 
145
- The npm package is available at: [https://www.npmjs.com/package/kubectl-mcp-server](https://www.npmjs.com/package/kubectl-mcp-server)
146
-
147
- > **Note:** The npm package requires Python 3.9+ to be installed. It will automatically install the Python dependencies on first run.
148
-
149
132
  ### pip (Python)
150
133
 
151
- You can install kubectl-mcp-tool directly from PyPI:
152
-
153
134
  ```bash
154
135
  pip install kubectl-mcp-tool
155
136
  ```
156
137
 
157
- For a specific version:
158
-
159
- ```bash
160
- pip install kubectl-mcp-tool==1.4.0
161
- ```
162
-
163
- The package is available on PyPI: [https://pypi.org/project/kubectl-mcp-tool/](https://pypi.org/project/kubectl-mcp-tool/)
164
-
165
- ### Prerequisites
166
-
167
- - Python 3.9+
168
- - kubectl CLI installed and configured
169
- - Access to a Kubernetes cluster
170
- - pip (Python package manager)
171
-
172
- ### Global Installation
173
-
174
- ```bash
175
- # Install latest version from PyPI
176
- pip install kubectl-mcp-tool
177
-
178
- # Or install development version from GitHub
179
- pip install git+https://github.com/rohitg00/kubectl-mcp-server.git
180
- ```
181
-
182
- ### Local Development Installation
183
-
184
- ```bash
185
- # Clone the repository
186
- git clone https://github.com/rohitg00/kubectl-mcp-server.git
187
- cd kubectl-mcp-server
188
-
189
- # Install in development mode
190
- pip install -e .
191
- ```
192
-
193
- ### Verifying Installation
194
-
195
- After installation, verify the tool is working correctly:
196
-
197
- ```bash
198
- kubectl-mcp --help
199
- ```
200
-
201
- Note: This tool is designed to work as an MCP server that AI assistants connect to, not as a direct kubectl replacement. The primary command available is `kubectl-mcp serve` which starts the MCP server.
202
-
203
- ## Docker Image
204
-
205
- Pre-built images are available on Docker Hub:
138
+ ### Docker
206
139
 
207
140
  ```bash
208
141
  # Pull the latest image
209
142
  docker pull rohitghumare64/kubectl-mcp-server:latest
210
143
 
211
- # Or use the official MCP catalog image
212
- docker pull mcp/kubectl-mcp-server:latest
213
- ```
214
-
215
- ### Docker MCP Toolkit Integration
216
-
217
- This image is compatible with [Docker MCP Toolkit](https://docs.docker.com/ai/mcp-catalog-and-toolkit/toolkit/). The Toolkit provides a streamlined way to run MCP servers with Claude, Cursor, and other AI assistants.
218
-
219
- **Quick Setup with Docker MCP Toolkit:**
220
-
221
- 1. **Add the server to Docker MCP Toolkit:**
222
- ```bash
223
- docker mcp server add kubectl-mcp-server mcp/kubectl-mcp-server:latest
224
- ```
225
-
226
- 2. **Configure kubeconfig access:**
227
- ```bash
228
- docker mcp server configure kubectl-mcp-server --volume "$HOME/.kube:/root/.kube:ro"
229
- ```
230
-
231
- 3. **Enable the server:**
232
- ```bash
233
- docker mcp server enable kubectl-mcp-server
234
- ```
235
-
236
- 4. **Connect your AI client** (e.g., Claude Desktop):
237
- ```bash
238
- docker mcp client connect claude
239
- ```
240
-
241
- The server uses **stdio transport** by default for Docker MCP Toolkit compatibility.
242
-
243
- ### Running the image (Standalone)
244
-
245
- For SSE/HTTP transport (without Docker MCP Toolkit):
246
-
247
- ```bash
248
- # SSE transport on port 8000
249
- docker run -p 8081:8000 \
250
- -v $HOME/.kube:/root/.kube:ro \
251
- rohitghumare64/kubectl-mcp-server:latest \
252
- --transport sse --host 0.0.0.0 --port 8000
253
- ```
254
-
255
- For stdio transport (for direct MCP client connections):
256
-
257
- ```bash
258
- docker run -i \
259
- -v $HOME/.kube:/root/.kube:ro \
260
- rohitghumare64/kubectl-mcp-server:latest
261
- ```
262
-
263
- * `-i` enables interactive mode for stdio transport
264
- * `-v $HOME/.kube:/root/.kube:ro` mounts kubeconfig as read-only
265
-
266
- ### Building a multi-architecture image (AMD64 & ARM64)
267
-
268
- If you want to build and push a multi-arch image (so it runs on both x86_64 and Apple Silicon), use Docker Buildx:
269
-
270
- ```bash
271
- # Ensure Buildx and QEMU are installed once per machine
272
- # docker buildx create --name multiarch --use
273
- # docker buildx inspect --bootstrap
274
-
275
- # Build and push for linux/amd64 and linux/arm64
276
- # (replace <your_username> if you're publishing to your own registry)
277
-
278
- docker buildx build \
279
- --platform linux/amd64,linux/arm64 \
280
- -t rohitghumare64/kubectl-mcp-server:latest \
281
- --push .
282
- ```
283
-
284
- The published image will contain a manifest list with both architectures, and Docker will automatically pull the correct variant on each machine.
285
-
286
- ### Configuration
287
-
288
- The MCP server is allowed to access these paths to read your Kubernetes configuration:
144
+ # Run with stdio transport
145
+ docker run -i -v $HOME/.kube:/root/.kube:ro rohitghumare64/kubectl-mcp-server:latest
289
146
 
290
- ```yaml
291
- run:
292
- volumes:
293
- - '{{kubectl-mcp-server.kubeconfig}}:/root/.kube'
294
- config:
295
- description: The MCP server is allowed to access this path
296
- parameters:
297
- type: object
298
- properties:
299
- kubeconfig:
300
- type: string
301
- default:
302
- $HOME/.kube
303
- required:
304
- - kubeconfig
305
- ```
306
-
307
- This configuration allows users to add their kubeconfig directory to the container, enabling the MCP server to authenticate with their Kubernetes cluster.
308
-
309
- ## Transport Modes
310
-
311
- The MCP server supports multiple transport protocols:
312
-
313
- ### stdio (default)
314
- Standard input/output transport, used by most MCP clients like Claude Desktop and Cursor:
315
- ```bash
316
- python -m kubectl_mcp_tool.mcp_server --transport stdio
147
+ # Run with SSE transport
148
+ docker run -p 8000:8000 -v $HOME/.kube:/root/.kube:ro rohitghumare64/kubectl-mcp-server:latest --transport sse
317
149
  ```
318
150
 
319
- ### SSE (Server-Sent Events)
320
- HTTP-based transport using Server-Sent Events:
321
- ```bash
322
- python -m kubectl_mcp_tool.mcp_server --transport sse --host 0.0.0.0 --port 8000
323
- ```
324
-
325
- ### HTTP / Streamable HTTP
326
- Standard HTTP transport for clients that prefer JSON-RPC over HTTP:
327
- ```bash
328
- python -m kubectl_mcp_tool.mcp_server --transport http --host 0.0.0.0 --port 8000
329
- # or
330
- python -m kubectl_mcp_tool.mcp_server --transport streamable-http --host 0.0.0.0 --port 8000
331
- ```
332
-
333
- ### Command-Line Options
334
- - `--transport`: Transport mode (`stdio`, `sse`, `http`, `streamable-http`). Default: `stdio`
335
- - `--host`: Host to bind for network transports. Default: `0.0.0.0`
336
- - `--port`: Port for network transports. Default: `8000`
337
- - `--non-destructive`: Block destructive operations (delete, apply, create, etc.)
338
-
339
- ## Multi-Cluster Support
340
-
341
- The MCP server provides full multi-cluster support through context management:
342
-
343
- ```bash
344
- # List all available contexts
345
- list_contexts
346
-
347
- # Switch to a different cluster
348
- switch_context --context_name production
349
-
350
- # Get details about a specific context
351
- get_context_details --context_name staging
352
-
353
- # Set default namespace for a context
354
- set_namespace_for_context --namespace kube-system --context_name production
355
- ```
356
-
357
- For detailed monitoring features documentation, see [Monitoring Guide](./docs/monitoring.md).
358
-
359
- ## Available Tools
360
-
361
- The MCP server provides 40+ tools for Kubernetes management:
362
-
363
- | Category | Tools |
364
- |----------|-------|
365
- | **Pods** | `get_pods`, `get_logs`, `get_pod_events`, `check_pod_health`, `exec_in_pod`, `cleanup_pods` |
366
- | **Deployments** | `get_deployments`, `create_deployment`, `scale_deployment`, `kubectl_rollout` |
367
- | **Resources** | `get_services`, `get_nodes`, `get_namespaces`, `get_configmaps`, `get_secrets`, `get_events` |
368
- | **CRUD** | `kubectl_apply`, `kubectl_create`, `kubectl_describe`, `kubectl_patch`, `delete_resource`, `kubectl_cp` |
369
- | **Helm** | `install_helm_chart`, `upgrade_helm_chart`, `uninstall_helm_chart`, `helm_template`, `helm_template_apply` |
370
- | **Cluster** | `get_current_context`, `switch_context`, `list_contexts`, `list_kubeconfig_contexts`, `get_cluster_info`, `health_check` |
371
- | **Security** | `analyze_pod_security`, `analyze_network_policies`, `audit_rbac_permissions`, `check_secrets_security`, `get_rbac_roles`, `get_cluster_roles` |
372
- | **Node Ops** | `node_management` (cordon, drain, uncordon) |
373
- | **Advanced** | `kubectl_generic`, `kubectl_explain`, `get_api_resources`, `port_forward`, `get_resource_usage` |
374
-
375
- ## Usage with AI Assistants
376
-
377
- ### Using the MCP Server
378
-
379
- The MCP Server (`kubectl_mcp_tool.mcp_server`) is a robust implementation built on the FastMCP SDK that provides enhanced compatibility across different AI assistants:
380
-
381
- > **Note**: If you encounter any errors with the MCP Server implementation, you can fall back to using the minimal wrapper by replacing `kubectl_mcp_tool.mcp_server` with `kubectl_mcp_tool.minimal_wrapper` in your configuration. The minimal wrapper provides basic capabilities with simpler implementation.
382
-
383
- 1. **Direct Configuration**
384
- ```json
385
- {
386
- "mcpServers": {
387
- "kubernetes": {
388
- "command": "python",
389
- "args": ["-m", "kubectl_mcp_tool.mcp_server"],
390
- "env": {
391
- "KUBECONFIG": "/path/to/your/.kube/config",
392
- "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
393
- "MCP_LOG_FILE": "/path/to/logs/debug.log",
394
- "MCP_DEBUG": "1"
395
- }
396
- }
397
- }
398
- }
399
- ```
400
-
401
- 2. **Key Environment Variables**
402
- - `MCP_LOG_FILE`: Path to log file (recommended to avoid stdout pollution)
403
- - `MCP_DEBUG`: Set to "1" for verbose logging
404
- - `MCP_TEST_MOCK_MODE`: Set to "1" to use mock data instead of real cluster
405
- - `KUBECONFIG`: Path to your Kubernetes config file
406
- - `KUBECTL_MCP_LOG_LEVEL`: Set to "DEBUG", "INFO", "WARNING", or "ERROR"
407
-
408
- 3. **Testing the MCP Server**
409
- You can test if the server is working correctly with:
410
- ```bash
411
- python -m kubectl_mcp_tool.simple_ping
412
- ```
413
- This will attempt to connect to the server and execute a ping command.
414
-
415
- Alternatively, you can directly run the server with:
416
- ```bash
417
- python -m kubectl_mcp_tool
418
- ```
151
+ ## Quick Start
419
152
 
420
153
  ### Claude Desktop
421
154
 
422
- Add the following to your Claude Desktop configuration at `~/Library/Application\ Support/Claude/claude_desktop_config.json` (Windows: `%APPDATA%\Claude\mcp.json`):
155
+ Add to `~/Library/Application Support/Claude/claude_desktop_config.json`:
423
156
 
424
- **Using npx (Recommended):**
425
157
  ```json
426
158
  {
427
159
  "mcpServers": {
@@ -433,26 +165,25 @@ Add the following to your Claude Desktop configuration at `~/Library/Application
433
165
  }
434
166
  ```
435
167
 
436
- **Using Python directly:**
168
+ ### Claude Code
169
+
170
+ Add to `~/.config/claude-code/mcp.json`:
171
+
437
172
  ```json
438
173
  {
439
174
  "mcpServers": {
440
175
  "kubernetes": {
441
- "command": "python",
442
- "args": ["-m", "kubectl_mcp_tool.mcp_server"],
443
- "env": {
444
- "KUBECONFIG": "$HOME/.kube/config" // or whatever your path is for the config file
445
- }
176
+ "command": "npx",
177
+ "args": ["-y", "kubectl-mcp-server"]
446
178
  }
447
179
  }
448
180
  }
449
181
  ```
450
182
 
451
- ### Claude Code
183
+ ### Cursor AI
452
184
 
453
- Claude Code is Anthropic's CLI tool for coding with Claude. Add the following to `~/.config/claude-code/mcp.json`:
185
+ Add to `~/.cursor/mcp.json`:
454
186
 
455
- **Using npx (Recommended):**
456
187
  ```json
457
188
  {
458
189
  "mcpServers": {
@@ -464,64 +195,70 @@ Claude Code is Anthropic's CLI tool for coding with Claude. Add the following to
464
195
  }
465
196
  ```
466
197
 
467
- **Using Python directly:**
198
+ ### Windsurf
199
+
200
+ Add to `~/.config/windsurf/mcp.json`:
201
+
468
202
  ```json
469
203
  {
470
204
  "mcpServers": {
471
205
  "kubernetes": {
472
- "command": "python",
473
- "args": ["-m", "kubectl_mcp_tool.mcp_server"],
474
- "env": {
475
- "KUBECONFIG": "/path/to/your/.kube/config"
476
- }
206
+ "command": "npx",
207
+ "args": ["-y", "kubectl-mcp-server"]
477
208
  }
478
209
  }
479
210
  }
480
211
  ```
481
212
 
482
- For detailed Claude Code integration instructions, see [Claude Code Integration Guide](./docs/claude/claude_code_integration.md).
483
-
484
- ### Cursor AI
213
+ ### GitHub Copilot (VS Code)
485
214
 
486
- Add the following to your Cursor AI settings under MCP by adding a new global MCP server:
215
+ Add to VS Code `settings.json`:
487
216
 
488
- **Using npx (Recommended):**
489
217
  ```json
490
218
  {
491
- "mcpServers": {
492
- "kubernetes": {
493
- "command": "npx",
494
- "args": ["-y", "kubectl-mcp-server"]
219
+ "mcp": {
220
+ "servers": {
221
+ "kubernetes": {
222
+ "command": "npx",
223
+ "args": ["-y", "kubectl-mcp-server"]
224
+ }
495
225
  }
496
226
  }
497
227
  }
498
228
  ```
499
229
 
500
- **Using Python directly:**
230
+ ### Goose
231
+
232
+ Add to `~/.config/goose/config.yaml`:
233
+
234
+ ```yaml
235
+ extensions:
236
+ kubernetes:
237
+ command: npx
238
+ args:
239
+ - -y
240
+ - kubectl-mcp-server
241
+ ```
242
+
243
+ ### Gemini CLI
244
+
245
+ Add to `~/.gemini/settings.json`:
246
+
501
247
  ```json
502
248
  {
503
249
  "mcpServers": {
504
250
  "kubernetes": {
505
- "command": "python",
506
- "args": ["-m", "kubectl_mcp_tool.mcp_server"],
507
- "env": {
508
- "KUBECONFIG": "/path/to/your/.kube/config",
509
- "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin"
510
- }
251
+ "command": "npx",
252
+ "args": ["-y", "kubectl-mcp-server"]
511
253
  }
512
254
  }
513
255
  }
514
256
  ```
515
257
 
516
- Save this configuration to `~/.cursor/mcp.json` for global settings.
258
+ ### Roo Code / Kilo Code
517
259
 
518
- > **Note**: Replace `/path/to/your/.kube/config` with the actual path to your kubeconfig file. On most systems, this is `~/.kube/config`.
260
+ Add to `~/.config/roo-code/mcp.json` or `~/.config/kilo-code/mcp.json`:
519
261
 
520
- ### Windsurf
521
-
522
- Add the following to your Windsurf configuration at `~/.config/windsurf/mcp.json` (Windows: `%APPDATA%\WindSurf\mcp.json`):
523
-
524
- **Using npx (Recommended):**
525
262
  ```json
526
263
  {
527
264
  "mcpServers": {
@@ -533,7 +270,10 @@ Add the following to your Windsurf configuration at `~/.config/windsurf/mcp.json
533
270
  }
534
271
  ```
535
272
 
536
- **Using Python directly:**
273
+ ### Using Python Directly
274
+
275
+ If you prefer Python over npx:
276
+
537
277
  ```json
538
278
  {
539
279
  "mcpServers": {
@@ -541,17 +281,176 @@ Add the following to your Windsurf configuration at `~/.config/windsurf/mcp.json
541
281
  "command": "python",
542
282
  "args": ["-m", "kubectl_mcp_tool.mcp_server"],
543
283
  "env": {
544
- "KUBECONFIG": "/path/to/your/.kube/config"
284
+ "KUBECONFIG": "/path/to/.kube/config"
545
285
  }
546
286
  }
547
287
  }
548
288
  }
549
289
  ```
550
290
 
551
- ### Automatic Configuration
291
+ ## Transport Modes
292
+
293
+ ```bash
294
+ # stdio (default) - for Claude Desktop, Cursor, etc.
295
+ python -m kubectl_mcp_tool.mcp_server
296
+
297
+ # SSE - Server-Sent Events
298
+ python -m kubectl_mcp_tool.mcp_server --transport sse --port 8000
299
+
300
+ # HTTP
301
+ python -m kubectl_mcp_tool.mcp_server --transport http --port 8000
302
+ ```
303
+
304
+ ### Options
305
+ - `--transport`: `stdio`, `sse`, `http`, `streamable-http` (default: `stdio`)
306
+ - `--host`: Host to bind (default: `0.0.0.0`)
307
+ - `--port`: Port for network transports (default: `8000`)
308
+ - `--non-destructive`: Block destructive operations (delete, apply, create)
309
+
310
+ ## Environment Variables
311
+
312
+ | Variable | Description |
313
+ |----------|-------------|
314
+ | `KUBECONFIG` | Path to kubeconfig file (default: `~/.kube/config`) |
315
+ | `MCP_DEBUG` | Set to `1` for verbose logging |
316
+ | `MCP_LOG_FILE` | Path to log file |
317
+
318
+ ## Docker MCP Toolkit
319
+
320
+ Compatible with [Docker MCP Toolkit](https://docs.docker.com/ai/mcp-catalog-and-toolkit/toolkit/):
321
+
322
+ ```bash
323
+ # Add server
324
+ docker mcp server add kubectl-mcp-server mcp/kubectl-mcp-server:latest
325
+
326
+ # Configure kubeconfig
327
+ docker mcp server configure kubectl-mcp-server --volume "$HOME/.kube:/root/.kube:ro"
328
+
329
+ # Enable and connect
330
+ docker mcp server enable kubectl-mcp-server
331
+ docker mcp client connect claude
332
+ ```
333
+
334
+ ## Architecture
335
+
336
+ ```
337
+ ┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
338
+ │ AI Assistant │────▶│ MCP Server │────▶│ Kubernetes API │
339
+ │ (Claude/Cursor) │◀────│ (kubectl-mcp) │◀────│ (kubectl) │
340
+ └─────────────────┘ └──────────────────┘ └─────────────────┘
341
+ ```
342
+
343
+ The MCP server implements the [Model Context Protocol](https://github.com/modelcontextprotocol/spec), translating natural language requests into kubectl operations.
344
+
345
+ ### Modular Structure
346
+
347
+ ```
348
+ kubectl_mcp_tool/
349
+ ├── mcp_server.py # Main server (FastMCP, transports)
350
+ ├── tools/ # 121 MCP tools organized by category
351
+ │ ├── pods.py # Pod management & diagnostics
352
+ │ ├── deployments.py # Deployments, StatefulSets, DaemonSets
353
+ │ ├── core.py # Namespaces, ConfigMaps, Secrets
354
+ │ ├── cluster.py # Context/cluster management
355
+ │ ├── networking.py # Services, Ingress, NetworkPolicies
356
+ │ ├── storage.py # PVCs, StorageClasses, PVs
357
+ │ ├── security.py # RBAC, ServiceAccounts, PodSecurity
358
+ │ ├── helm.py # Complete Helm v3 operations
359
+ │ ├── operations.py # kubectl apply/patch/describe/etc
360
+ │ ├── diagnostics.py # Metrics, namespace comparison
361
+ │ └── cost.py # Resource optimization & cost analysis
362
+ ├── resources/ # 8 MCP Resources for data exposure
363
+ ├── prompts/ # 8 MCP Prompts for workflows
364
+ └── cli/ # CLI interface
365
+ ```
366
+
367
+ ## Multi-Cluster Support
368
+
369
+ ```bash
370
+ # List contexts
371
+ list_contexts
372
+
373
+ # Switch cluster
374
+ switch_context --context_name production
375
+
376
+ # Get context details
377
+ get_context_details --context_name staging
378
+ ```
379
+
380
+ ## Development & Testing
381
+
382
+ ### Setup Development Environment
383
+
384
+ ```bash
385
+ # Clone the repository
386
+ git clone https://github.com/rohitg00/kubectl-mcp-server.git
387
+ cd kubectl-mcp-server
388
+
389
+ # Create virtual environment
390
+ python -m venv venv
391
+ source venv/bin/activate # On Windows: venv\Scripts\activate
392
+
393
+ # Install development dependencies
394
+ pip install -r requirements-dev.txt
395
+ ```
396
+
397
+ ### Running Tests
552
398
 
553
- For automatic configuration of all supported AI assistants, run the provided installation script:
399
+ ```bash
400
+ # Run all tests
401
+ pytest tests/ -v
402
+
403
+ # Run specific test file
404
+ pytest tests/test_tools.py -v
405
+
406
+ # Run with coverage
407
+ pytest tests/ --cov=kubectl_mcp_tool --cov-report=html
408
+
409
+ # Run only unit tests
410
+ pytest tests/ -v -m unit
411
+ ```
412
+
413
+ ### Test Structure
414
+
415
+ ```
416
+ tests/
417
+ ├── __init__.py # Test package
418
+ ├── conftest.py # Shared fixtures and mocks
419
+ ├── test_tools.py # Unit tests for 121 MCP tools
420
+ ├── test_resources.py # Tests for 8 MCP Resources
421
+ ├── test_prompts.py # Tests for 8 MCP Prompts
422
+ └── test_server.py # Server initialization tests
423
+ ```
424
+
425
+ **135 tests covering**: tool registration, resource exposure, prompt generation, server initialization, non-destructive mode, secret masking, error handling, and transport methods.
426
+
427
+ ### Code Quality
554
428
 
555
429
  ```bash
556
- bash install.sh
557
- ```
430
+ # Format code
431
+ black kubectl_mcp_tool tests
432
+
433
+ # Sort imports
434
+ isort kubectl_mcp_tool tests
435
+
436
+ # Lint
437
+ flake8 kubectl_mcp_tool tests
438
+
439
+ # Type checking
440
+ mypy kubectl_mcp_tool
441
+ ```
442
+
443
+ ## Contributing
444
+
445
+ Contributions are welcome! Please feel free to submit a Pull Request.
446
+
447
+ ## License
448
+
449
+ MIT License - see [LICENSE](LICENSE) for details.
450
+
451
+ ## Links
452
+
453
+ - [PyPI Package](https://pypi.org/project/kubectl-mcp-tool/)
454
+ - [npm Package](https://www.npmjs.com/package/kubectl-mcp-server)
455
+ - [Docker Hub](https://hub.docker.com/r/rohitghumare64/kubectl-mcp-server)
456
+ - [GitHub Issues](https://github.com/rohitg00/kubectl-mcp-server/issues)
package/bin/cli.js CHANGED
@@ -1,53 +1,23 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const { spawn } = require('child_process');
4
- const { existsSync } = require('fs');
5
- const path = require('path');
6
- const os = require('os');
3
+ const { spawn, spawnSync } = require('child_process');
7
4
 
8
- // ANSI color codes
9
- const colors = {
10
- red: '\x1b[31m',
11
- green: '\x1b[32m',
12
- yellow: '\x1b[33m',
13
- blue: '\x1b[34m',
14
- reset: '\x1b[0m'
15
- };
16
-
17
- function log(message, color = 'reset') {
18
- console.error(`${colors[color]}${message}${colors.reset}`);
19
- }
5
+ const colors = { red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m', reset: '\x1b[0m' };
6
+ const log = (msg, color = 'reset') => console.error(`${colors[color]}${msg}${colors.reset}`);
20
7
 
21
8
  function getPythonCommand() {
22
- // Try different Python commands
23
- const commands = process.platform === 'win32'
24
- ? ['python', 'python3', 'py']
25
- : ['python3', 'python'];
26
-
9
+ const commands = process.platform === 'win32' ? ['python', 'python3', 'py'] : ['python3', 'python'];
27
10
  for (const cmd of commands) {
28
11
  try {
29
- const result = require('child_process').spawnSync(cmd, ['--version'], {
30
- encoding: 'utf8',
31
- stdio: ['pipe', 'pipe', 'pipe']
32
- });
33
- if (result.status === 0) {
34
- return cmd;
35
- }
36
- } catch (e) {
37
- // Continue to next command
38
- }
12
+ if (spawnSync(cmd, ['--version'], { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }).status === 0) return cmd;
13
+ } catch (e) {}
39
14
  }
40
15
  return null;
41
16
  }
42
17
 
43
18
  function checkPythonPackage(pythonCmd) {
44
19
  try {
45
- const result = require('child_process').spawnSync(
46
- pythonCmd,
47
- ['-c', 'import kubectl_mcp_tool; print(kubectl_mcp_tool.__file__)'],
48
- { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }
49
- );
50
- return result.status === 0;
20
+ return spawnSync(pythonCmd, ['-c', 'import kubectl_mcp_tool'], { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }).status === 0;
51
21
  } catch (e) {
52
22
  return false;
53
23
  }
@@ -56,7 +26,6 @@ function checkPythonPackage(pythonCmd) {
56
26
  function main() {
57
27
  const args = process.argv.slice(2);
58
28
 
59
- // Handle help flag
60
29
  if (args.includes('--help') || args.includes('-h')) {
61
30
  console.log(`
62
31
  kubectl-mcp-server - MCP Server for Kubernetes
@@ -64,90 +33,47 @@ kubectl-mcp-server - MCP Server for Kubernetes
64
33
  Usage: kubectl-mcp-server [options]
65
34
 
66
35
  Options:
67
- --transport <mode> Transport mode: stdio, sse, http, streamable-http (default: stdio)
68
- --host <host> Host to bind for network transports (default: 0.0.0.0)
69
- --port <port> Port for network transports (default: 8000)
70
- --non-destructive Block destructive operations (delete, apply, create, etc.)
71
- --help, -h Show this help message
72
- --version, -v Show version
73
-
74
- Examples:
75
- kubectl-mcp-server # Start with stdio transport
76
- kubectl-mcp-server --transport sse # Start with SSE transport
77
- kubectl-mcp-server --transport http --port 3000
78
-
79
- Environment Variables:
80
- KUBECONFIG Path to kubeconfig file (default: ~/.kube/config)
81
- MCP_DEBUG Set to "1" for verbose logging
82
- MCP_LOG_FILE Path to log file
83
-
84
- For more information, visit: https://github.com/rohitg00/kubectl-mcp-server
36
+ --transport <mode> Transport: stdio, sse, http, streamable-http (default: stdio)
37
+ --host <host> Host for network transports (default: 0.0.0.0)
38
+ --port <port> Port for network transports (default: 8000)
39
+ --non-destructive Block destructive operations
40
+ --help, -h Show this help message
41
+ --version, -v Show version
42
+
43
+ For more info: https://github.com/rohitg00/kubectl-mcp-server
85
44
  `);
86
45
  process.exit(0);
87
46
  }
88
47
 
89
- // Handle version flag
90
48
  if (args.includes('--version') || args.includes('-v')) {
91
- const pkg = require('../package.json');
92
- console.log(`kubectl-mcp-server v${pkg.version}`);
49
+ console.log(`kubectl-mcp-server v${require('../package.json').version}`);
93
50
  process.exit(0);
94
51
  }
95
52
 
96
- // Check for Python
97
53
  const pythonCmd = getPythonCommand();
98
54
  if (!pythonCmd) {
99
- log('Error: Python 3.9+ is required but not found.', 'red');
100
- log('Please install Python from https://www.python.org/downloads/', 'yellow');
55
+ log('Error: Python 3.9+ is required. Install from https://python.org', 'red');
101
56
  process.exit(1);
102
57
  }
103
58
 
104
- // Check if kubectl-mcp-tool is installed
105
59
  if (!checkPythonPackage(pythonCmd)) {
106
- log('kubectl-mcp-tool Python package not found. Installing...', 'yellow');
107
-
108
- const installResult = require('child_process').spawnSync(
109
- pythonCmd,
110
- ['-m', 'pip', 'install', 'kubectl-mcp-tool'],
111
- { stdio: 'inherit' }
112
- );
113
-
114
- if (installResult.status !== 0) {
115
- log('Error: Failed to install kubectl-mcp-tool package.', 'red');
116
- log('Try installing manually: pip install kubectl-mcp-tool', 'yellow');
60
+ log('Installing kubectl-mcp-tool...', 'yellow');
61
+ if (spawnSync(pythonCmd, ['-m', 'pip', 'install', 'kubectl-mcp-tool'], { stdio: 'inherit' }).status !== 0) {
62
+ log('Failed to install. Try: pip install kubectl-mcp-tool', 'red');
117
63
  process.exit(1);
118
64
  }
119
-
120
- log('kubectl-mcp-tool installed successfully!', 'green');
65
+ log('Installed successfully!', 'green');
121
66
  }
122
67
 
123
- // Run the Python MCP server
124
- const serverArgs = ['-m', 'kubectl_mcp_tool.mcp_server', ...args];
125
-
126
- const server = spawn(pythonCmd, serverArgs, {
68
+ const server = spawn(pythonCmd, ['-m', 'kubectl_mcp_tool.mcp_server', ...args], {
127
69
  stdio: 'inherit',
128
- env: {
129
- ...process.env,
130
- PYTHONUNBUFFERED: '1'
131
- }
132
- });
133
-
134
- server.on('error', (err) => {
135
- log(`Error starting MCP server: ${err.message}`, 'red');
136
- process.exit(1);
70
+ env: { ...process.env, PYTHONUNBUFFERED: '1' }
137
71
  });
138
72
 
139
- server.on('close', (code) => {
140
- process.exit(code || 0);
141
- });
142
-
143
- // Handle signals
144
- process.on('SIGINT', () => {
145
- server.kill('SIGINT');
146
- });
147
-
148
- process.on('SIGTERM', () => {
149
- server.kill('SIGTERM');
150
- });
73
+ server.on('error', (err) => { log(`Error: ${err.message}`, 'red'); process.exit(1); });
74
+ server.on('close', (code) => process.exit(code || 0));
75
+ process.on('SIGINT', () => server.kill('SIGINT'));
76
+ process.on('SIGTERM', () => server.kill('SIGTERM'));
151
77
  }
152
78
 
153
79
  main();
@@ -1,147 +1,47 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- /**
4
- * Post-install script for kubectl-mcp-server npm package
5
- * Checks for Python and optionally installs the Python package
6
- */
7
-
8
3
  const { spawnSync } = require('child_process');
9
4
 
10
- // ANSI color codes
11
- const colors = {
12
- red: '\x1b[31m',
13
- green: '\x1b[32m',
14
- yellow: '\x1b[33m',
15
- blue: '\x1b[34m',
16
- cyan: '\x1b[36m',
17
- reset: '\x1b[0m',
18
- bold: '\x1b[1m'
19
- };
20
-
21
- function log(message, color = 'reset') {
22
- console.log(`${colors[color]}${message}${colors.reset}`);
23
- }
5
+ const colors = { green: '\x1b[32m', yellow: '\x1b[33m', cyan: '\x1b[36m', reset: '\x1b[0m', bold: '\x1b[1m' };
6
+ const log = (msg, color = 'reset') => console.log(`${colors[color]}${msg}${colors.reset}`);
24
7
 
25
8
  function getPythonCommand() {
26
- const commands = process.platform === 'win32'
27
- ? ['python', 'python3', 'py']
28
- : ['python3', 'python'];
29
-
9
+ const commands = process.platform === 'win32' ? ['python', 'python3', 'py'] : ['python3', 'python'];
30
10
  for (const cmd of commands) {
31
11
  try {
32
- const result = spawnSync(cmd, ['--version'], {
33
- encoding: 'utf8',
34
- stdio: ['pipe', 'pipe', 'pipe']
35
- });
36
- if (result.status === 0) {
37
- const version = result.stdout.trim() || result.stderr.trim();
38
- return { cmd, version };
39
- }
40
- } catch (e) {
41
- // Continue
42
- }
12
+ const result = spawnSync(cmd, ['--version'], { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] });
13
+ if (result.status === 0) return { cmd, version: (result.stdout || result.stderr).trim() };
14
+ } catch (e) {}
43
15
  }
44
16
  return null;
45
17
  }
46
18
 
47
- function checkPythonPackage(pythonCmd) {
48
- try {
49
- const result = spawnSync(
50
- pythonCmd,
51
- ['-c', 'import kubectl_mcp_tool; print(kubectl_mcp_tool.__version__ if hasattr(kubectl_mcp_tool, "__version__") else "installed")'],
52
- { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }
53
- );
54
- if (result.status === 0) {
55
- return result.stdout.trim();
56
- }
57
- return null;
58
- } catch (e) {
59
- return null;
60
- }
61
- }
62
-
63
- function checkKubectl() {
64
- try {
65
- const result = spawnSync('kubectl', ['version', '--client', '--short'], {
66
- encoding: 'utf8',
67
- stdio: ['pipe', 'pipe', 'pipe']
68
- });
69
- return result.status === 0;
70
- } catch (e) {
71
- return false;
72
- }
73
- }
74
-
75
19
  function main() {
76
20
  console.log('');
77
- log('='.repeat(60), 'cyan');
78
- log(' kubectl-mcp-server - Post-Installation Check', 'bold');
79
- log('='.repeat(60), 'cyan');
21
+ log('kubectl-mcp-server installed!', 'bold');
80
22
  console.log('');
81
23
 
82
- // Check Python
83
24
  const python = getPythonCommand();
84
- if (!python) {
85
- log('WARNING: Python 3.9+ is required but not found.', 'yellow');
86
- log('Please install Python from https://www.python.org/downloads/', 'yellow');
87
- log('The MCP server will attempt to install dependencies on first run.', 'yellow');
88
- console.log('');
89
- } else {
90
- log(`Found ${python.version}`, 'green');
91
-
92
- // Check if kubectl-mcp-tool is installed
93
- const pkgVersion = checkPythonPackage(python.cmd);
94
- if (pkgVersion) {
95
- log(`kubectl-mcp-tool Python package: v${pkgVersion}`, 'green');
96
- } else {
97
- log('kubectl-mcp-tool Python package: Not installed', 'yellow');
98
- log('It will be installed automatically on first run.', 'yellow');
99
-
100
- // Optionally install now
101
- if (process.env.KUBECTL_MCP_INSTALL_NOW === '1') {
102
- log('Installing kubectl-mcp-tool...', 'cyan');
103
- const result = spawnSync(python.cmd, ['-m', 'pip', 'install', 'kubectl-mcp-tool'], {
104
- stdio: 'inherit'
105
- });
106
- if (result.status === 0) {
107
- log('kubectl-mcp-tool installed successfully!', 'green');
108
- } else {
109
- log('Failed to install kubectl-mcp-tool. It will retry on first run.', 'yellow');
110
- }
111
- }
112
- }
113
- }
114
-
115
- // Check kubectl
116
- if (checkKubectl()) {
117
- log('kubectl CLI: Found', 'green');
25
+ if (python) {
26
+ log(`Python: ${python.version}`, 'green');
118
27
  } else {
119
- log('kubectl CLI: Not found', 'yellow');
120
- log('Please install kubectl: https://kubernetes.io/docs/tasks/tools/', 'yellow');
28
+ log('Python 3.9+ required: https://python.org', 'yellow');
121
29
  }
122
30
 
123
31
  console.log('');
124
- log('-'.repeat(60), 'cyan');
125
- log(' Quick Start', 'bold');
126
- log('-'.repeat(60), 'cyan');
127
- console.log('');
128
- log(' Run the MCP server:', 'reset');
129
- log(' npx kubectl-mcp-server', 'cyan');
32
+ log('Usage:', 'cyan');
33
+ log(' npx kubectl-mcp-server', 'reset');
34
+ log(' npx kubectl-mcp-server --transport sse --port 8000', 'reset');
130
35
  console.log('');
131
- log(' Or with options:', 'reset');
132
- log(' npx kubectl-mcp-server --transport sse --port 8000', 'cyan');
133
- console.log('');
134
- log(' Add to Claude Desktop config (claude_desktop_config.json):', 'reset');
135
- log(` {
136
- "mcpServers": {
137
- "kubernetes": {
138
- "command": "npx",
139
- "args": ["-y", "kubectl-mcp-server"]
140
- }
36
+ log('Claude Desktop config:', 'cyan');
37
+ console.log(` {
38
+ "mcpServers": {
39
+ "kubernetes": {
40
+ "command": "npx",
41
+ "args": ["-y", "kubectl-mcp-server"]
141
42
  }
142
- }`, 'cyan');
143
- console.log('');
144
- log('='.repeat(60), 'cyan');
43
+ }
44
+ }`);
145
45
  console.log('');
146
46
  }
147
47
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kubectl-mcp-server",
3
- "version": "1.6.0",
3
+ "version": "1.9.0",
4
4
  "description": "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",
5
5
  "keywords": [
6
6
  "kubernetes",