mcp-server-kubernetes 2.9.0 → 2.9.2

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
@@ -10,6 +10,7 @@
10
10
  [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/Flux159/mcp-server-kubernetes/pulls)
11
11
  [![Last Commit](https://img.shields.io/github/last-commit/Flux159/mcp-server-kubernetes)](https://github.com/Flux159/mcp-server-kubernetes/commits/main)
12
12
  [![Trust Score](https://archestra.ai/mcp-catalog/api/badge/quality/Flux159/mcp-server-kubernetes)](https://archestra.ai/mcp-catalog/flux159__mcp-server-kubernetes)
13
+ [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/Flux159/mcp-server-kubernetes)
13
14
 
14
15
  MCP Server that can connect to a Kubernetes cluster and manage it. Supports loading kubeconfig from multiple sources in priority order.
15
16
 
@@ -17,7 +18,34 @@ https://github.com/user-attachments/assets/f25f8f4e-4d04-479b-9ae0-5dac452dd2ed
17
18
 
18
19
  <a href="https://glama.ai/mcp/servers/w71ieamqrt"><img width="380" height="200" src="https://glama.ai/mcp/servers/w71ieamqrt/badge" /></a>
19
20
 
20
- ## Usage with Claude Desktop
21
+ ## Installation & Usage
22
+
23
+ ### Prerequisites
24
+
25
+ Before using this MCP server with any tool, make sure you have:
26
+
27
+ 1. kubectl installed and in your PATH
28
+ 2. A valid kubeconfig file with contexts configured
29
+ 3. Access to a Kubernetes cluster configured for kubectl (e.g. minikube, Rancher Desktop, GKE, etc.)
30
+ 4. Helm v3 installed and in your PATH (no Tiller required). Optional if you don't plan to use Helm.
31
+
32
+ You can verify your connection by running `kubectl get pods` in a terminal to ensure you can connect to your cluster without credential issues.
33
+
34
+ By default, the server loads kubeconfig from `~/.kube/config`. For additional authentication options (environment variables, custom paths, etc.), see [ADVANCED_README.md](ADVANCED_README.md).
35
+
36
+ ### Claude Code
37
+
38
+ Add the MCP server to Claude Code using the built-in command:
39
+
40
+ ```bash
41
+ claude mcp add kubernetes -- npx mcp-server-kubernetes
42
+ ```
43
+
44
+ This will automatically configure the server in your Claude Code MCP settings.
45
+
46
+ ### Claude Desktop
47
+
48
+ Add the following configuration to your Claude Desktop config file:
21
49
 
22
50
  ```json
23
51
  {
@@ -30,18 +58,43 @@ https://github.com/user-attachments/assets/f25f8f4e-4d04-479b-9ae0-5dac452dd2ed
30
58
  }
31
59
  ```
32
60
 
33
- By default, the server loads kubeconfig from `~/.kube/config`. For additional authentication options (environment variables, custom paths, etc.), see [ADVANCED_README.md](ADVANCED_README.md).
61
+ ### VS Code
34
62
 
35
- The server will automatically connect to your current kubectl context. Make sure you have:
63
+ [![Install Kubernetes MCP in VS Code](https://img.shields.io/badge/Install%20Kubernetes%20MCP%20in%20VS%20Code-blue?logo=visualstudiocode)](vscode:mcp/install?%7B%22name%22%3A%20%22kubernetes%22%2C%20%22type%22%3A%20%22stdio%22%2C%20%22command%22%3A%20%22npx%22%2C%20%22args%22%3A%20%5B%22mcp-server-kubernetes%22%5D%7D)
36
64
 
37
- 1. kubectl installed and in your PATH
38
- 2. A valid kubeconfig file with contexts configured
39
- 3. Access to a Kubernetes cluster configured for kubectl (e.g. minikube, Rancher Desktop, GKE, etc.)
40
- 4. Helm v3 installed and in your PATH (no Tiller required). Optional if you don't plan to use Helm.
65
+ For VS Code integration, you can use the MCP server with extensions that support the Model Context Protocol:
41
66
 
42
- You can verify your connection by asking Claude to list your pods or create a test deployment.
67
+ 1. Install a compatible MCP extension (such as Claude Dev or similar MCP clients)
68
+ 2. Configure the extension to use this server:
43
69
 
44
- If you have errors open up a standard terminal and run `kubectl get pods` to see if you can connect to your cluster without credentials issues.
70
+ ```json
71
+ {
72
+ "mcpServers": {
73
+ "kubernetes": {
74
+ "command": "npx",
75
+ "args": ["mcp-server-kubernetes"],
76
+ "description": "Kubernetes cluster management and operations"
77
+ }
78
+ }
79
+ }
80
+ ```
81
+
82
+ ### Cursor
83
+
84
+ Cursor supports MCP servers through its AI integration. Add the server to your Cursor MCP configuration:
85
+
86
+ ```json
87
+ {
88
+ "mcpServers": {
89
+ "kubernetes": {
90
+ "command": "npx",
91
+ "args": ["mcp-server-kubernetes"]
92
+ }
93
+ }
94
+ }
95
+ ```
96
+
97
+ The server will automatically connect to your current kubectl context. You can verify the connection by asking the AI assistant to list your pods or create a test deployment.
45
98
 
46
99
  ## Usage with mcp-chat
47
100
 
@@ -105,7 +158,7 @@ npx mcp-chat --config "%APPDATA%\Claude\claude_desktop_config.json"
105
158
 
106
159
  The MCP Kubernetes server includes specialized prompts to assist with common diagnostic operations.
107
160
 
108
- ### k8s-diagnose Prompt
161
+ ### /k8s-diagnose Prompt
109
162
 
110
163
  This prompt provides a systematic troubleshooting flow for Kubernetes pods. It accepts a `keyword` to identify relevant pods and an optional `namespace` to narrow the search.
111
164
  The prompt's output will guide you through an autonomous troubleshooting flow, providing instructions for identifying issues, collecting evidence, and suggesting remediation steps.
@@ -217,248 +270,7 @@ The following destructive operations are disabled:
217
270
  - `node_management`: Node management operations (can drain nodes)
218
271
  - `kubectl_generic`: General kubectl command access (may include destructive operations)
219
272
 
220
- ### Helm Template Apply Tool
221
-
222
- The `helm_template_apply` tool provides an alternative way to install Helm charts that bypasses authentication issues commonly encountered with certain Kubernetes configurations. This tool is particularly useful when you encounter errors like:
223
-
224
- ```
225
- WARNING: Kubernetes configuration file is group-readable. This is insecure.
226
- Error: INSTALLATION FAILED: Kubernetes cluster unreachable: exec plugin: invalid apiVersion "client.authentication.k8s.io/v1alpha1"
227
- ```
228
-
229
- Instead of using `helm install` directly, this tool:
230
-
231
- 1. Uses `helm template` to generate YAML manifests from the Helm chart
232
- 2. Applies the generated YAML using `kubectl apply`
233
- 3. Handles namespace creation and cleanup automatically
234
-
235
- #### Usage Example
236
-
237
- ```json
238
- {
239
- "name": "helm_template_apply",
240
- "arguments": {
241
- "name": "events-exporter",
242
- "chart": ".",
243
- "namespace": "kube-event-exporter",
244
- "valuesFile": "values.yaml",
245
- "createNamespace": true
246
- }
247
- }
248
- ```
249
-
250
- This is equivalent to running:
251
- ```bash
252
- helm template events-exporter . -f values.yaml > events-exporter.yaml
253
- kubectl create namespace kube-event-exporter
254
- kubectl apply -f events-exporter.yaml -n kube-event-exporter
255
- ```
256
-
257
- #### Parameters
258
-
259
- - `name`: Release name for the Helm chart
260
- - `chart`: Chart name or path to chart directory
261
- - `repo`: Chart repository URL (optional if using local chart path)
262
- - `namespace`: Kubernetes namespace to deploy to
263
- - `values`: Chart values as an object (optional)
264
- - `valuesFile`: Path to values.yaml file (optional, alternative to values object)
265
- - `createNamespace`: Whether to create the namespace if it doesn't exist (default: true)
266
-
267
- ### Pod Cleanup with Existing Tools
268
-
269
- Pod cleanup can be achieved using the existing `kubectl_get` and `kubectl_delete` tools with field selectors. This approach leverages standard Kubernetes functionality without requiring dedicated cleanup tools.
270
-
271
- #### Identifying Problematic Pods
272
-
273
- Use `kubectl_get` with field selectors to identify pods in problematic states:
274
-
275
- **Get failed pods:**
276
- ```json
277
- {
278
- "name": "kubectl_get",
279
- "arguments": {
280
- "resourceType": "pods",
281
- "namespace": "default",
282
- "fieldSelector": "status.phase=Failed"
283
- }
284
- }
285
- ```
286
-
287
- **Get completed pods:**
288
- ```json
289
- {
290
- "name": "kubectl_get",
291
- "arguments": {
292
- "resourceType": "pods",
293
- "namespace": "default",
294
- "fieldSelector": "status.phase=Succeeded"
295
- }
296
- }
297
- ```
298
-
299
- **Get pods with specific conditions:**
300
- ```json
301
- {
302
- "name": "kubectl_get",
303
- "arguments": {
304
- "resourceType": "pods",
305
- "namespace": "default",
306
- "fieldSelector": "status.conditions[?(@.type=='Ready')].status=False"
307
- }
308
- }
309
- ```
310
-
311
- #### Deleting Problematic Pods
312
-
313
- Use `kubectl_delete` with field selectors to delete pods in problematic states:
314
-
315
- **Delete failed pods:**
316
- ```json
317
- {
318
- "name": "kubectl_delete",
319
- "arguments": {
320
- "resourceType": "pods",
321
- "namespace": "default",
322
- "fieldSelector": "status.phase=Failed",
323
- "force": true,
324
- "gracePeriodSeconds": 0
325
- }
326
- }
327
- ```
328
-
329
- **Delete completed pods:**
330
- ```json
331
- {
332
- "name": "kubectl_delete",
333
- "arguments": {
334
- "resourceType": "pods",
335
- "namespace": "default",
336
- "fieldSelector": "status.phase=Succeeded",
337
- "force": true,
338
- "gracePeriodSeconds": 0
339
- }
340
- }
341
- ```
342
-
343
- #### Workflow
344
-
345
- 1. **First, identify problematic pods** using `kubectl_get` with appropriate field selectors
346
- 2. **Review the list** of pods in the response
347
- 3. **Delete the pods** using `kubectl_delete` with the same field selectors
348
-
349
- #### Available Field Selectors
350
-
351
- - `status.phase=Failed` - Pods that have failed
352
- - `status.phase=Succeeded` - Pods that have completed successfully
353
- - `status.phase=Pending` - Pods that are pending
354
- - `status.conditions[?(@.type=='Ready')].status=False` - Pods that are not ready
355
-
356
- #### Safety Features
357
-
358
- - **Field selectors**: Target specific pod states precisely
359
- - **Force deletion**: Use `force=true` and `gracePeriodSeconds=0` for immediate deletion
360
- - **Namespace isolation**: Target specific namespaces or use `allNamespaces=true`
361
- - **Standard kubectl**: Uses well-established Kubernetes patterns
362
-
363
- ### Node Management Tool
364
-
365
- The `node_management` tool provides comprehensive node management capabilities for Kubernetes clusters, including cordoning, draining, and uncordoning operations. This is essential for cluster maintenance, scaling, and troubleshooting.
366
-
367
- #### Operations Available
368
-
369
- - **`list`**: List all nodes with their status and schedulability
370
- - **`cordon`**: Mark a node as unschedulable (no new pods will be scheduled)
371
- - **`drain`**: Safely evict all pods from a node and mark it as unschedulable
372
- - **`uncordon`**: Mark a node as schedulable again
373
-
374
- #### Usage Examples
375
-
376
- **1. List all nodes:**
377
- ```json
378
- {
379
- "name": "node_management",
380
- "arguments": {
381
- "operation": "list"
382
- }
383
- }
384
- ```
385
-
386
- **2. Cordon a node (mark as unschedulable):**
387
- ```json
388
- {
389
- "name": "node_management",
390
- "arguments": {
391
- "operation": "cordon",
392
- "nodeName": "worker-node-1"
393
- }
394
- }
395
- ```
396
-
397
- **3. Drain a node (dry run first):**
398
- ```json
399
- {
400
- "name": "node_management",
401
- "arguments": {
402
- "operation": "drain",
403
- "nodeName": "worker-node-1",
404
- "dryRun": true
405
- }
406
- }
407
- ```
408
-
409
- **4. Drain a node (with confirmation):**
410
- ```json
411
- {
412
- "name": "node_management",
413
- "arguments": {
414
- "operation": "drain",
415
- "nodeName": "worker-node-1",
416
- "dryRun": false,
417
- "confirmDrain": true,
418
- "force": true,
419
- "ignoreDaemonsets": true,
420
- "timeout": "5m"
421
- }
422
- }
423
- ```
424
-
425
- **5. Uncordon a node:**
426
- ```json
427
- {
428
- "name": "node_management",
429
- "arguments": {
430
- "operation": "uncordon",
431
- "nodeName": "worker-node-1"
432
- }
433
- }
434
- ```
435
-
436
- #### Drain Operation Parameters
437
-
438
- - `force`: Force the operation even if there are pods not managed by controllers
439
- - `gracePeriod`: Period of time in seconds given to each pod to terminate gracefully
440
- - `deleteLocalData`: Delete local data even if emptyDir volumes are used
441
- - `ignoreDaemonsets`: Ignore DaemonSet-managed pods (default: true)
442
- - `timeout`: The length of time to wait before giving up (e.g., '5m', '1h')
443
- - `dryRun`: Show what would be done without actually doing it
444
- - `confirmDrain`: Explicit confirmation to drain the node (required for actual draining)
445
-
446
- #### Safety Features
447
-
448
- - **Dry run by default**: Drain operations default to dry run to show what would be done
449
- - **Explicit confirmation**: Drain operations require `confirmDrain=true` to proceed
450
- - **Status tracking**: Shows node status before and after operations
451
- - **Timeout protection**: Configurable timeouts to prevent hanging operations
452
- - **Graceful termination**: Configurable grace periods for pod termination
453
-
454
- #### Common Use Cases
455
-
456
- 1. **Cluster Maintenance**: Cordon nodes before maintenance, drain them, perform maintenance, then uncordon
457
- 2. **Node Scaling**: Drain nodes before removing them from the cluster
458
- 3. **Troubleshooting**: Isolate problematic nodes by cordoning them
459
- 4. **Resource Management**: Drain nodes to redistribute workload
460
-
461
- For additional advanced features, see the [ADVANCED_README.md](ADVANCED_README.md).
273
+ For additional advanced features, see the [ADVANCED_README.md](ADVANCED_README.md) and also the [docs](https://github.com/Flux159/mcp-server-kubernetes/tree/main/docs) folder for specific information on `helm_install`, `helm_template_apply`, node management & pod cleanup.
462
274
 
463
275
  ## Architecture
464
276
 
@@ -60,21 +60,36 @@ export async function kubectlContext(k8sManager, input) {
60
60
  });
61
61
  // Parse the tabular output from kubectl
62
62
  const lines = rawResult.trim().split("\n");
63
- const headers = lines[0].trim().split(/\s+/);
64
- const currentIndex = headers.indexOf("CURRENT");
65
- const nameIndex = headers.indexOf("NAME");
66
- const clusterIndex = headers.indexOf("CLUSTER");
67
- const authInfoIndex = headers.indexOf("AUTHINFO");
68
- const namespaceIndex = headers.indexOf("NAMESPACE");
63
+ const headerLine = lines[0];
64
+ // Find column positions based on header positions
65
+ const currentPos = headerLine.indexOf("CURRENT");
66
+ const namePos = headerLine.indexOf("NAME");
67
+ const clusterPos = headerLine.indexOf("CLUSTER");
68
+ const authInfoPos = headerLine.indexOf("AUTHINFO");
69
+ const namespacePos = headerLine.indexOf("NAMESPACE");
70
+ if (currentPos === -1 || namePos === -1 || clusterPos === -1 || authInfoPos === -1 || namespacePos === -1) {
71
+ throw new McpError(ErrorCode.InvalidParams, "Invalid kubectl output format");
72
+ }
69
73
  const contexts = [];
70
74
  for (let i = 1; i < lines.length; i++) {
71
- const columns = lines[i].trim().split(/\s+/);
72
- const isCurrent = columns[currentIndex]?.trim() === "*";
75
+ const line = lines[i];
76
+ if (line.trim() === "")
77
+ continue; // Skip empty lines
78
+ // Extract fields based on column positions
79
+ const isCurrent = line.substring(currentPos, namePos).trim() === "*";
80
+ const name = line.substring(namePos, clusterPos).trim();
81
+ const cluster = line.substring(clusterPos, authInfoPos).trim();
82
+ const authInfo = namespacePos > 0
83
+ ? line.substring(authInfoPos, namespacePos).trim()
84
+ : line.substring(authInfoPos).trim();
85
+ const namespace = namespacePos > 0
86
+ ? line.substring(namespacePos).trim() || "default"
87
+ : "default";
73
88
  contexts.push({
74
- name: columns[nameIndex]?.trim(),
75
- cluster: columns[clusterIndex]?.trim(),
76
- user: columns[authInfoIndex]?.trim(),
77
- namespace: columns[namespaceIndex]?.trim() || "default",
89
+ name: name,
90
+ cluster: cluster,
91
+ user: authInfo,
92
+ namespace: namespace,
78
93
  isCurrent: isCurrent,
79
94
  });
80
95
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-server-kubernetes",
3
- "version": "2.9.0",
3
+ "version": "2.9.2",
4
4
  "description": "MCP server for interacting with Kubernetes clusters via kubectl",
5
5
  "license": "MIT",
6
6
  "type": "module",