mcp-server-kubernetes 2.8.0 → 2.9.1

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
@@ -9,7 +9,8 @@
9
9
  [![Issues](https://img.shields.io/github/issues/Flux159/mcp-server-kubernetes)](https://github.com/Flux159/mcp-server-kubernetes/issues)
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
- [![smithery badge](https://smithery.ai/badge/mcp-server-kubernetes)](https://smithery.ai/protocol/mcp-server-kubernetes)
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:
66
+
67
+ 1. Install a compatible MCP extension (such as Claude Dev or similar MCP clients)
68
+ 2. Configure the extension to use this server:
69
+
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
+ ```
41
81
 
42
- You can verify your connection by asking Claude to list your pods or create a test deployment.
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
+ ```
43
96
 
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.
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
 
@@ -90,6 +143,12 @@ npx mcp-chat --config "%APPDATA%\Claude\claude_desktop_config.json"
90
143
  - Run Helm operations
91
144
  - Install, upgrade, and uninstall charts
92
145
  - Support for custom values, repositories, and versions
146
+ - Template-based installation (`helm_template_apply`) to bypass authentication issues
147
+ - Template-based uninstallation (`helm_template_uninstall`) to bypass authentication issues
148
+ - Pod cleanup operations
149
+ - Clean up problematic pods (`cleanup_pods`) in states: Evicted, ContainerStatusUnknown, Completed, Error, ImagePullBackOff, CrashLoopBackOff
150
+ - Node management operations
151
+ - Cordoning, draining, and uncordoning nodes (`node_management`) for maintenance and scaling operations
93
152
  - [x] Troubleshooting Prompt (`k8s-diagnose`)
94
153
  - Guides through a systematic Kubernetes troubleshooting flow for pods based on a keyword and optional namespace.
95
154
  - [x] Non-destructive mode for read and create/update-only access to clusters
@@ -99,7 +158,7 @@ npx mcp-chat --config "%APPDATA%\Claude\claude_desktop_config.json"
99
158
 
100
159
  The MCP Kubernetes server includes specialized prompts to assist with common diagnostic operations.
101
160
 
102
- ### k8s-diagnose Prompt
161
+ ### /k8s-diagnose Prompt
103
162
 
104
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.
105
164
  The prompt's output will guide you through an autonomous troubleshooting flow, providing instructions for identifying issues, collecting evidence, and suggesting remediation steps.
@@ -196,7 +255,7 @@ All read-only and resource creation/update operations remain available:
196
255
 
197
256
  - Resource Information: `kubectl_get`, `kubectl_describe`, `kubectl_logs`, `explain_resource`, `list_api_resources`
198
257
  - Resource Creation/Modification: `kubectl_apply`, `kubectl_create`, `kubectl_scale`, `kubectl_patch`, `kubectl_rollout`
199
- - Helm Operations: `install_helm_chart`, `upgrade_helm_chart`
258
+ - Helm Operations: `install_helm_chart`, `upgrade_helm_chart`, `helm_template_apply`, `helm_template_uninstall`
200
259
  - Connectivity: `port_forward`, `stop_port_forward`
201
260
  - Context Management: `kubectl_context`
202
261
 
@@ -207,8 +266,262 @@ The following destructive operations are disabled:
207
266
  - `kubectl_delete`: Deleting any Kubernetes resources
208
267
  - `uninstall_helm_chart`: Uninstalling Helm charts
209
268
  - `cleanup`: Cleanup of managed resources
269
+ - `cleanup_pods`: Cleaning up problematic pods
270
+ - `node_management`: Node management operations (can drain nodes)
210
271
  - `kubectl_generic`: General kubectl command access (may include destructive operations)
211
272
 
273
+ ### Helm Template Apply Tool
274
+
275
+ 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:
276
+
277
+ ```
278
+ WARNING: Kubernetes configuration file is group-readable. This is insecure.
279
+ Error: INSTALLATION FAILED: Kubernetes cluster unreachable: exec plugin: invalid apiVersion "client.authentication.k8s.io/v1alpha1"
280
+ ```
281
+
282
+ Instead of using `helm install` directly, this tool:
283
+
284
+ 1. Uses `helm template` to generate YAML manifests from the Helm chart
285
+ 2. Applies the generated YAML using `kubectl apply`
286
+ 3. Handles namespace creation and cleanup automatically
287
+
288
+ #### Usage Example
289
+
290
+ ```json
291
+ {
292
+ "name": "helm_template_apply",
293
+ "arguments": {
294
+ "name": "events-exporter",
295
+ "chart": ".",
296
+ "namespace": "kube-event-exporter",
297
+ "valuesFile": "values.yaml",
298
+ "createNamespace": true
299
+ }
300
+ }
301
+ ```
302
+
303
+ This is equivalent to running:
304
+
305
+ ```bash
306
+ helm template events-exporter . -f values.yaml > events-exporter.yaml
307
+ kubectl create namespace kube-event-exporter
308
+ kubectl apply -f events-exporter.yaml -n kube-event-exporter
309
+ ```
310
+
311
+ #### Parameters
312
+
313
+ - `name`: Release name for the Helm chart
314
+ - `chart`: Chart name or path to chart directory
315
+ - `repo`: Chart repository URL (optional if using local chart path)
316
+ - `namespace`: Kubernetes namespace to deploy to
317
+ - `values`: Chart values as an object (optional)
318
+ - `valuesFile`: Path to values.yaml file (optional, alternative to values object)
319
+ - `createNamespace`: Whether to create the namespace if it doesn't exist (default: true)
320
+
321
+ ### Pod Cleanup with Existing Tools
322
+
323
+ 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.
324
+
325
+ #### Identifying Problematic Pods
326
+
327
+ Use `kubectl_get` with field selectors to identify pods in problematic states:
328
+
329
+ **Get failed pods:**
330
+
331
+ ```json
332
+ {
333
+ "name": "kubectl_get",
334
+ "arguments": {
335
+ "resourceType": "pods",
336
+ "namespace": "default",
337
+ "fieldSelector": "status.phase=Failed"
338
+ }
339
+ }
340
+ ```
341
+
342
+ **Get completed pods:**
343
+
344
+ ```json
345
+ {
346
+ "name": "kubectl_get",
347
+ "arguments": {
348
+ "resourceType": "pods",
349
+ "namespace": "default",
350
+ "fieldSelector": "status.phase=Succeeded"
351
+ }
352
+ }
353
+ ```
354
+
355
+ **Get pods with specific conditions:**
356
+
357
+ ```json
358
+ {
359
+ "name": "kubectl_get",
360
+ "arguments": {
361
+ "resourceType": "pods",
362
+ "namespace": "default",
363
+ "fieldSelector": "status.conditions[?(@.type=='Ready')].status=False"
364
+ }
365
+ }
366
+ ```
367
+
368
+ #### Deleting Problematic Pods
369
+
370
+ Use `kubectl_delete` with field selectors to delete pods in problematic states:
371
+
372
+ **Delete failed pods:**
373
+
374
+ ```json
375
+ {
376
+ "name": "kubectl_delete",
377
+ "arguments": {
378
+ "resourceType": "pods",
379
+ "namespace": "default",
380
+ "fieldSelector": "status.phase=Failed",
381
+ "force": true,
382
+ "gracePeriodSeconds": 0
383
+ }
384
+ }
385
+ ```
386
+
387
+ **Delete completed pods:**
388
+
389
+ ```json
390
+ {
391
+ "name": "kubectl_delete",
392
+ "arguments": {
393
+ "resourceType": "pods",
394
+ "namespace": "default",
395
+ "fieldSelector": "status.phase=Succeeded",
396
+ "force": true,
397
+ "gracePeriodSeconds": 0
398
+ }
399
+ }
400
+ ```
401
+
402
+ #### Workflow
403
+
404
+ 1. **First, identify problematic pods** using `kubectl_get` with appropriate field selectors
405
+ 2. **Review the list** of pods in the response
406
+ 3. **Delete the pods** using `kubectl_delete` with the same field selectors
407
+
408
+ #### Available Field Selectors
409
+
410
+ - `status.phase=Failed` - Pods that have failed
411
+ - `status.phase=Succeeded` - Pods that have completed successfully
412
+ - `status.phase=Pending` - Pods that are pending
413
+ - `status.conditions[?(@.type=='Ready')].status=False` - Pods that are not ready
414
+
415
+ #### Safety Features
416
+
417
+ - **Field selectors**: Target specific pod states precisely
418
+ - **Force deletion**: Use `force=true` and `gracePeriodSeconds=0` for immediate deletion
419
+ - **Namespace isolation**: Target specific namespaces or use `allNamespaces=true`
420
+ - **Standard kubectl**: Uses well-established Kubernetes patterns
421
+
422
+ ### Node Management Tool
423
+
424
+ 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.
425
+
426
+ #### Operations Available
427
+
428
+ - **`list`**: List all nodes with their status and schedulability
429
+ - **`cordon`**: Mark a node as unschedulable (no new pods will be scheduled)
430
+ - **`drain`**: Safely evict all pods from a node and mark it as unschedulable
431
+ - **`uncordon`**: Mark a node as schedulable again
432
+
433
+ #### Usage Examples
434
+
435
+ **1. List all nodes:**
436
+
437
+ ```json
438
+ {
439
+ "name": "node_management",
440
+ "arguments": {
441
+ "operation": "list"
442
+ }
443
+ }
444
+ ```
445
+
446
+ **2. Cordon a node (mark as unschedulable):**
447
+
448
+ ```json
449
+ {
450
+ "name": "node_management",
451
+ "arguments": {
452
+ "operation": "cordon",
453
+ "nodeName": "worker-node-1"
454
+ }
455
+ }
456
+ ```
457
+
458
+ **3. Drain a node (dry run first):**
459
+
460
+ ```json
461
+ {
462
+ "name": "node_management",
463
+ "arguments": {
464
+ "operation": "drain",
465
+ "nodeName": "worker-node-1",
466
+ "dryRun": true
467
+ }
468
+ }
469
+ ```
470
+
471
+ **4. Drain a node (with confirmation):**
472
+
473
+ ```json
474
+ {
475
+ "name": "node_management",
476
+ "arguments": {
477
+ "operation": "drain",
478
+ "nodeName": "worker-node-1",
479
+ "dryRun": false,
480
+ "confirmDrain": true,
481
+ "force": true,
482
+ "ignoreDaemonsets": true,
483
+ "timeout": "5m"
484
+ }
485
+ }
486
+ ```
487
+
488
+ **5. Uncordon a node:**
489
+
490
+ ```json
491
+ {
492
+ "name": "node_management",
493
+ "arguments": {
494
+ "operation": "uncordon",
495
+ "nodeName": "worker-node-1"
496
+ }
497
+ }
498
+ ```
499
+
500
+ #### Drain Operation Parameters
501
+
502
+ - `force`: Force the operation even if there are pods not managed by controllers
503
+ - `gracePeriod`: Period of time in seconds given to each pod to terminate gracefully
504
+ - `deleteLocalData`: Delete local data even if emptyDir volumes are used
505
+ - `ignoreDaemonsets`: Ignore DaemonSet-managed pods (default: true)
506
+ - `timeout`: The length of time to wait before giving up (e.g., '5m', '1h')
507
+ - `dryRun`: Show what would be done without actually doing it
508
+ - `confirmDrain`: Explicit confirmation to drain the node (required for actual draining)
509
+
510
+ #### Safety Features
511
+
512
+ - **Dry run by default**: Drain operations default to dry run to show what would be done
513
+ - **Explicit confirmation**: Drain operations require `confirmDrain=true` to proceed
514
+ - **Status tracking**: Shows node status before and after operations
515
+ - **Timeout protection**: Configurable timeouts to prevent hanging operations
516
+ - **Graceful termination**: Configurable grace periods for pod termination
517
+
518
+ #### Common Use Cases
519
+
520
+ 1. **Cluster Maintenance**: Cordon nodes before maintenance, drain them, perform maintenance, then uncordon
521
+ 2. **Node Scaling**: Drain nodes before removing them from the cluster
522
+ 3. **Troubleshooting**: Isolate problematic nodes by cordoning them
523
+ 4. **Resource Management**: Drain nodes to redistribute workload
524
+
212
525
  For additional advanced features, see the [ADVANCED_README.md](ADVANCED_README.md).
213
526
 
214
527
  ## Architecture
package/dist/index.d.ts CHANGED
@@ -22,6 +22,59 @@ declare const destructiveTools: ({
22
22
  };
23
23
  required: string[];
24
24
  };
25
+ } | {
26
+ name: string;
27
+ description: string;
28
+ inputSchema: {
29
+ type: string;
30
+ properties: {
31
+ operation: {
32
+ type: string;
33
+ description: string;
34
+ enum: string[];
35
+ };
36
+ nodeName: {
37
+ type: string;
38
+ description: string;
39
+ };
40
+ force: {
41
+ type: string;
42
+ description: string;
43
+ default: boolean;
44
+ };
45
+ gracePeriod: {
46
+ type: string;
47
+ description: string;
48
+ default: number;
49
+ };
50
+ deleteLocalData: {
51
+ type: string;
52
+ description: string;
53
+ default: boolean;
54
+ };
55
+ ignoreDaemonsets: {
56
+ type: string;
57
+ description: string;
58
+ default: boolean;
59
+ };
60
+ timeout: {
61
+ type: string;
62
+ description: string;
63
+ default: string;
64
+ };
65
+ dryRun: {
66
+ type: string;
67
+ description: string;
68
+ default: boolean;
69
+ };
70
+ confirmDrain: {
71
+ type: string;
72
+ description: string;
73
+ default: boolean;
74
+ };
75
+ };
76
+ required: string[];
77
+ };
25
78
  } | {
26
79
  readonly name: "cleanup";
27
80
  readonly description: "Cleanup all managed resources";
@@ -106,6 +159,59 @@ declare const allTools: ({
106
159
  };
107
160
  required: string[];
108
161
  };
162
+ } | {
163
+ name: string;
164
+ description: string;
165
+ inputSchema: {
166
+ type: string;
167
+ properties: {
168
+ operation: {
169
+ type: string;
170
+ description: string;
171
+ enum: string[];
172
+ };
173
+ nodeName: {
174
+ type: string;
175
+ description: string;
176
+ };
177
+ force: {
178
+ type: string;
179
+ description: string;
180
+ default: boolean;
181
+ };
182
+ gracePeriod: {
183
+ type: string;
184
+ description: string;
185
+ default: number;
186
+ };
187
+ deleteLocalData: {
188
+ type: string;
189
+ description: string;
190
+ default: boolean;
191
+ };
192
+ ignoreDaemonsets: {
193
+ type: string;
194
+ description: string;
195
+ default: boolean;
196
+ };
197
+ timeout: {
198
+ type: string;
199
+ description: string;
200
+ default: string;
201
+ };
202
+ dryRun: {
203
+ type: string;
204
+ description: string;
205
+ default: boolean;
206
+ };
207
+ confirmDrain: {
208
+ type: string;
209
+ description: string;
210
+ default: boolean;
211
+ };
212
+ };
213
+ required: string[];
214
+ };
109
215
  } | {
110
216
  name: string;
111
217
  description: string;
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
3
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
4
  import { installHelmChart, installHelmChartSchema, upgradeHelmChart, upgradeHelmChartSchema, uninstallHelmChart, uninstallHelmChartSchema, } from "./tools/helm-operations.js";
5
+ import { nodeManagement, nodeManagementSchema, } from "./tools/node-management.js";
5
6
  import { explainResource, explainResourceSchema, listApiResources, listApiResourcesSchema, } from "./tools/kubectl-operations.js";
6
7
  import { execInPod, execInPodSchema } from "./tools/exec_in_pod.js";
7
8
  import { getResourceHandlers } from "./resources/handlers.js";
@@ -45,6 +46,7 @@ const destructiveTools = [
45
46
  uninstallHelmChartSchema,
46
47
  cleanupSchema, // Cleanup is also destructive as it deletes resources
47
48
  kubectlGenericSchema, // Generic kubectl command can perform destructive operations
49
+ nodeManagementSchema, // Node management can drain nodes (destructive)
48
50
  ];
49
51
  // Get all available tools
50
52
  const allTools = [
@@ -68,6 +70,7 @@ const allTools = [
68
70
  installHelmChartSchema,
69
71
  upgradeHelmChartSchema,
70
72
  uninstallHelmChartSchema,
73
+ nodeManagementSchema,
71
74
  // Port forwarding
72
75
  PortForwardSchema,
73
76
  StopPortForwardSchema,
@@ -186,6 +189,9 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
186
189
  case "upgrade_helm_chart": {
187
190
  return await upgradeHelmChart(input);
188
191
  }
192
+ case "node_management": {
193
+ return await nodeManagement(input);
194
+ }
189
195
  case "list_api_resources": {
190
196
  return await listApiResources(input);
191
197
  }
@@ -22,18 +22,31 @@ export declare const HelmResponseSchema: z.ZodObject<{
22
22
  }[];
23
23
  }>;
24
24
  export declare const HelmValuesSchema: z.ZodRecord<z.ZodString, z.ZodAny>;
25
- export interface HelmOperation {
25
+ export interface HelmUninstallOperation {
26
26
  name: string;
27
27
  namespace: string;
28
28
  }
29
- export interface HelmInstallOperation extends HelmOperation {
29
+ export interface HelmInstallOperation {
30
+ name: string;
30
31
  chart: string;
31
- repo: string;
32
+ namespace: string;
33
+ repo?: string;
32
34
  values?: Record<string, any>;
35
+ valuesFile?: string;
36
+ createNamespace?: boolean;
37
+ useTemplate?: boolean;
33
38
  }
34
- export interface HelmUpgradeOperation extends HelmInstallOperation {
39
+ export interface HelmUpgradeOperation {
40
+ name: string;
41
+ chart: string;
42
+ namespace: string;
43
+ repo?: string;
44
+ values?: Record<string, any>;
45
+ valuesFile?: string;
35
46
  }
36
47
  export type HelmResponse = {
37
- status: "installed" | "upgraded" | "uninstalled";
48
+ status: "installed" | "upgraded" | "uninstalled" | "failed";
38
49
  message?: string;
50
+ error?: string;
51
+ steps?: string[];
39
52
  };