mcp-server-kubernetes 2.8.0 → 2.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
@@ -9,7 +9,7 @@
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
13
 
14
14
  MCP Server that can connect to a Kubernetes cluster and manage it. Supports loading kubeconfig from multiple sources in priority order.
15
15
 
@@ -90,6 +90,12 @@ npx mcp-chat --config "%APPDATA%\Claude\claude_desktop_config.json"
90
90
  - Run Helm operations
91
91
  - Install, upgrade, and uninstall charts
92
92
  - Support for custom values, repositories, and versions
93
+ - Template-based installation (`helm_template_apply`) to bypass authentication issues
94
+ - Template-based uninstallation (`helm_template_uninstall`) to bypass authentication issues
95
+ - Pod cleanup operations
96
+ - Clean up problematic pods (`cleanup_pods`) in states: Evicted, ContainerStatusUnknown, Completed, Error, ImagePullBackOff, CrashLoopBackOff
97
+ - Node management operations
98
+ - Cordoning, draining, and uncordoning nodes (`node_management`) for maintenance and scaling operations
93
99
  - [x] Troubleshooting Prompt (`k8s-diagnose`)
94
100
  - Guides through a systematic Kubernetes troubleshooting flow for pods based on a keyword and optional namespace.
95
101
  - [x] Non-destructive mode for read and create/update-only access to clusters
@@ -196,7 +202,7 @@ All read-only and resource creation/update operations remain available:
196
202
 
197
203
  - Resource Information: `kubectl_get`, `kubectl_describe`, `kubectl_logs`, `explain_resource`, `list_api_resources`
198
204
  - Resource Creation/Modification: `kubectl_apply`, `kubectl_create`, `kubectl_scale`, `kubectl_patch`, `kubectl_rollout`
199
- - Helm Operations: `install_helm_chart`, `upgrade_helm_chart`
205
+ - Helm Operations: `install_helm_chart`, `upgrade_helm_chart`, `helm_template_apply`, `helm_template_uninstall`
200
206
  - Connectivity: `port_forward`, `stop_port_forward`
201
207
  - Context Management: `kubectl_context`
202
208
 
@@ -207,8 +213,251 @@ The following destructive operations are disabled:
207
213
  - `kubectl_delete`: Deleting any Kubernetes resources
208
214
  - `uninstall_helm_chart`: Uninstalling Helm charts
209
215
  - `cleanup`: Cleanup of managed resources
216
+ - `cleanup_pods`: Cleaning up problematic pods
217
+ - `node_management`: Node management operations (can drain nodes)
210
218
  - `kubectl_generic`: General kubectl command access (may include destructive operations)
211
219
 
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
+
212
461
  For additional advanced features, see the [ADVANCED_README.md](ADVANCED_README.md).
213
462
 
214
463
  ## 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
  };
@@ -1,4 +1,21 @@
1
- import { HelmInstallOperation, HelmOperation, HelmUpgradeOperation } from "../models/helm-models.js";
1
+ /**
2
+ * Tool: install_helm_chart
3
+ * Install a Helm chart with support for both standard Helm install and template-based installation.
4
+ * Template mode bypasses authentication issues and kubeconfig API version mismatches.
5
+ * Supports local chart paths, remote repositories, and custom values.
6
+ */
7
+ import { HelmInstallOperation, HelmUpgradeOperation, HelmUninstallOperation } from "../models/helm-models.js";
8
+ /**
9
+ * Schema for install_helm_chart tool.
10
+ * - name: Release name
11
+ * - chart: Chart name or path to chart directory
12
+ * - namespace: Target namespace
13
+ * - repo: (Optional) Helm repository URL
14
+ * - values: (Optional) Custom values object
15
+ * - valuesFile: (Optional) Path to values file
16
+ * - useTemplate: (Optional) Use template mode instead of helm install
17
+ * - createNamespace: (Optional) Create namespace if it doesn't exist
18
+ */
2
19
  export declare const installHelmChartSchema: {
3
20
  name: string;
4
21
  description: string;
@@ -13,10 +30,6 @@ export declare const installHelmChartSchema: {
13
30
  type: string;
14
31
  description: string;
15
32
  };
16
- repo: {
17
- type: string;
18
- description: string;
19
- };
20
33
  namespace: {
21
34
  type: "string";
22
35
  description: string;
@@ -27,16 +40,41 @@ export declare const installHelmChartSchema: {
27
40
  description: string;
28
41
  default: string;
29
42
  };
43
+ repo: {
44
+ type: string;
45
+ description: string;
46
+ };
30
47
  values: {
31
48
  type: string;
32
49
  description: string;
33
- properties: {};
34
- additionalProperties: boolean;
50
+ };
51
+ valuesFile: {
52
+ type: string;
53
+ description: string;
54
+ };
55
+ useTemplate: {
56
+ type: string;
57
+ description: string;
58
+ default: boolean;
59
+ };
60
+ createNamespace: {
61
+ type: string;
62
+ description: string;
63
+ default: boolean;
35
64
  };
36
65
  };
37
66
  required: string[];
38
67
  };
39
68
  };
69
+ /**
70
+ * Schema for upgrade_helm_chart tool.
71
+ * - name: Release name
72
+ * - chart: Chart name or path
73
+ * - namespace: Target namespace
74
+ * - repo: (Optional) Helm repository URL
75
+ * - values: (Optional) Custom values object
76
+ * - valuesFile: (Optional) Path to values file
77
+ */
40
78
  export declare const upgradeHelmChartSchema: {
41
79
  name: string;
42
80
  description: string;
@@ -51,10 +89,6 @@ export declare const upgradeHelmChartSchema: {
51
89
  type: string;
52
90
  description: string;
53
91
  };
54
- repo: {
55
- type: string;
56
- description: string;
57
- };
58
92
  namespace: {
59
93
  type: "string";
60
94
  description: string;
@@ -65,16 +99,27 @@ export declare const upgradeHelmChartSchema: {
65
99
  description: string;
66
100
  default: string;
67
101
  };
102
+ repo: {
103
+ type: string;
104
+ description: string;
105
+ };
68
106
  values: {
69
107
  type: string;
70
108
  description: string;
71
- properties: {};
72
- additionalProperties: boolean;
109
+ };
110
+ valuesFile: {
111
+ type: string;
112
+ description: string;
73
113
  };
74
114
  };
75
115
  required: string[];
76
116
  };
77
117
  };
118
+ /**
119
+ * Schema for uninstall_helm_chart tool.
120
+ * - name: Release name
121
+ * - namespace: Target namespace
122
+ */
78
123
  export declare const uninstallHelmChartSchema: {
79
124
  name: string;
80
125
  description: string;
@@ -99,19 +144,34 @@ export declare const uninstallHelmChartSchema: {
99
144
  required: string[];
100
145
  };
101
146
  };
147
+ /**
148
+ * Install a Helm chart using standard helm install command.
149
+ * @param params - Installation parameters
150
+ * @returns Promise with installation result
151
+ */
102
152
  export declare function installHelmChart(params: HelmInstallOperation): Promise<{
103
153
  content: {
104
154
  type: string;
105
155
  text: string;
106
156
  }[];
107
157
  }>;
158
+ /**
159
+ * Upgrade an existing Helm chart release.
160
+ * @param params - Upgrade parameters
161
+ * @returns Promise with upgrade result
162
+ */
108
163
  export declare function upgradeHelmChart(params: HelmUpgradeOperation): Promise<{
109
164
  content: {
110
165
  type: string;
111
166
  text: string;
112
167
  }[];
113
168
  }>;
114
- export declare function uninstallHelmChart(params: HelmOperation): Promise<{
169
+ /**
170
+ * Uninstall a Helm chart release.
171
+ * @param params - Uninstall parameters
172
+ * @returns Promise with uninstall result
173
+ */
174
+ export declare function uninstallHelmChart(params: HelmUninstallOperation): Promise<{
115
175
  content: {
116
176
  type: string;
117
177
  text: string;