mcp-server-kubernetes 2.7.0 → 2.8.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/dist/index.d.ts CHANGED
@@ -10,8 +10,14 @@ declare const destructiveTools: ({
10
10
  description: string;
11
11
  };
12
12
  namespace: {
13
- type: string;
13
+ type: "string";
14
14
  description: string;
15
+ default: string;
16
+ };
17
+ context: {
18
+ type: "string";
19
+ description: string;
20
+ default: string;
15
21
  };
16
22
  };
17
23
  required: string[];
@@ -38,9 +44,9 @@ declare const destructiveTools: ({
38
44
  readonly description: "Name of the resource to delete";
39
45
  };
40
46
  readonly namespace: {
41
- readonly type: "string";
42
- readonly description: "Namespace of the resource (optional - defaults to 'default' for namespaced resources)";
43
- readonly default: "default";
47
+ type: "string";
48
+ description: string;
49
+ default: string;
44
50
  };
45
51
  readonly labelSelector: {
46
52
  readonly type: "string";
@@ -68,6 +74,11 @@ declare const destructiveTools: ({
68
74
  readonly type: "number";
69
75
  readonly description: "Period of time in seconds given to the resource to terminate gracefully";
70
76
  };
77
+ readonly context: {
78
+ type: "string";
79
+ description: string;
80
+ default: string;
81
+ };
71
82
  };
72
83
  readonly required: readonly ["resourceType", "name", "namespace"];
73
84
  };
@@ -83,8 +94,14 @@ declare const allTools: ({
83
94
  description: string;
84
95
  };
85
96
  namespace: {
86
- type: string;
97
+ type: "string";
98
+ description: string;
99
+ default: string;
100
+ };
101
+ context: {
102
+ type: "string";
87
103
  description: string;
104
+ default: string;
88
105
  };
89
106
  };
90
107
  required: string[];
@@ -108,6 +125,11 @@ declare const allTools: ({
108
125
  description: string;
109
126
  default: boolean;
110
127
  };
128
+ context: {
129
+ type: "string";
130
+ description: string;
131
+ default: string;
132
+ };
111
133
  output: {
112
134
  type: string;
113
135
  description: string;
@@ -131,6 +153,11 @@ declare const allTools: ({
131
153
  type: string;
132
154
  description: string;
133
155
  };
156
+ context: {
157
+ type: string;
158
+ description: string;
159
+ default: string;
160
+ };
134
161
  verbs: {
135
162
  type: string;
136
163
  items: {
@@ -239,9 +266,9 @@ declare const allTools: ({
239
266
  readonly description: "Name of the resource (optional - if not provided, lists all resources of the specified type)";
240
267
  };
241
268
  readonly namespace: {
242
- readonly type: "string";
243
- readonly description: "Namespace of the resource (optional - defaults to 'default' for namespaced resources)";
244
- readonly default: "default";
269
+ type: "string";
270
+ description: string;
271
+ default: string;
245
272
  };
246
273
  readonly output: {
247
274
  readonly type: "string";
@@ -266,6 +293,11 @@ declare const allTools: ({
266
293
  readonly type: "string";
267
294
  readonly description: "Sort events by a field (default: lastTimestamp). Only applicable for events.";
268
295
  };
296
+ readonly context: {
297
+ type: "string";
298
+ description: string;
299
+ default: string;
300
+ };
269
301
  };
270
302
  readonly required: readonly ["resourceType", "name", "namespace"];
271
303
  };
@@ -284,9 +316,14 @@ declare const allTools: ({
284
316
  readonly description: "Name of the resource to describe";
285
317
  };
286
318
  readonly namespace: {
287
- readonly type: "string";
288
- readonly description: "Namespace of the resource (optional - defaults to 'default' for namespaced resources)";
289
- readonly default: "default";
319
+ type: "string";
320
+ description: string;
321
+ default: string;
322
+ };
323
+ readonly context: {
324
+ type: "string";
325
+ description: string;
326
+ default: string;
290
327
  };
291
328
  readonly allNamespaces: {
292
329
  readonly type: "boolean";
@@ -311,20 +348,25 @@ declare const allTools: ({
311
348
  readonly description: "Path to a YAML file to apply (optional - use either manifest or filename)";
312
349
  };
313
350
  readonly namespace: {
314
- readonly type: "string";
315
- readonly description: "Namespace to apply the resource to (optional)";
316
- readonly default: "default";
351
+ type: "string";
352
+ description: string;
353
+ default: string;
317
354
  };
318
355
  readonly dryRun: {
319
- readonly type: "boolean";
320
- readonly description: "If true, only validate the resource, don't apply it";
321
- readonly default: false;
356
+ type: "boolean";
357
+ description: string;
358
+ default: boolean;
322
359
  };
323
360
  readonly force: {
324
361
  readonly type: "boolean";
325
362
  readonly description: "If true, immediately remove resources from API and bypass graceful deletion";
326
363
  readonly default: false;
327
364
  };
365
+ readonly context: {
366
+ type: "string";
367
+ description: string;
368
+ default: string;
369
+ };
328
370
  };
329
371
  readonly required: readonly [];
330
372
  };
@@ -343,9 +385,9 @@ declare const allTools: ({
343
385
  readonly description: "Name of the resource to delete";
344
386
  };
345
387
  readonly namespace: {
346
- readonly type: "string";
347
- readonly description: "Namespace of the resource (optional - defaults to 'default' for namespaced resources)";
348
- readonly default: "default";
388
+ type: "string";
389
+ description: string;
390
+ default: string;
349
391
  };
350
392
  readonly labelSelector: {
351
393
  readonly type: "string";
@@ -373,6 +415,11 @@ declare const allTools: ({
373
415
  readonly type: "number";
374
416
  readonly description: "Period of time in seconds given to the resource to terminate gracefully";
375
417
  };
418
+ readonly context: {
419
+ type: "string";
420
+ description: string;
421
+ default: string;
422
+ };
376
423
  };
377
424
  readonly required: readonly ["resourceType", "name", "namespace"];
378
425
  };
@@ -383,9 +430,9 @@ declare const allTools: ({
383
430
  readonly type: "object";
384
431
  readonly properties: {
385
432
  readonly dryRun: {
386
- readonly type: "boolean";
387
- readonly description: "If true, only validate the resource, don't actually create it";
388
- readonly default: false;
433
+ type: "boolean";
434
+ description: string;
435
+ default: boolean;
389
436
  };
390
437
  readonly output: {
391
438
  readonly type: "string";
@@ -415,9 +462,9 @@ declare const allTools: ({
415
462
  readonly description: "Name of the resource to create";
416
463
  };
417
464
  readonly namespace: {
418
- readonly type: "string";
419
- readonly description: "Namespace to create the resource in";
420
- readonly default: "default";
465
+ type: "string";
466
+ description: string;
467
+ default: string;
421
468
  };
422
469
  readonly fromLiteral: {
423
470
  readonly type: "array";
@@ -493,6 +540,11 @@ declare const allTools: ({
493
540
  };
494
541
  readonly description: "Annotations to apply to the resource (e.g. [\"key1=value1\", \"key2=value2\"])";
495
542
  };
543
+ readonly context: {
544
+ type: "string";
545
+ description: string;
546
+ default: string;
547
+ };
496
548
  };
497
549
  readonly required: readonly [];
498
550
  };
@@ -512,9 +564,9 @@ declare const allTools: ({
512
564
  readonly description: "Name of the resource";
513
565
  };
514
566
  readonly namespace: {
515
- readonly type: "string";
516
- readonly description: "Namespace of the resource";
517
- readonly default: "default";
567
+ type: "string";
568
+ description: string;
569
+ default: string;
518
570
  };
519
571
  readonly container: {
520
572
  readonly type: "string";
@@ -551,6 +603,11 @@ declare const allTools: ({
551
603
  readonly type: "string";
552
604
  readonly description: "Filter resources by label selector";
553
605
  };
606
+ readonly context: {
607
+ type: "string";
608
+ description: string;
609
+ default: string;
610
+ };
554
611
  };
555
612
  readonly required: readonly ["resourceType", "name", "namespace"];
556
613
  };
package/dist/index.js CHANGED
@@ -156,6 +156,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
156
156
  labelSelector: input.labelSelector,
157
157
  sortBy: input.sortBy,
158
158
  output: input.output,
159
+ context: input.context,
159
160
  });
160
161
  }
161
162
  // Handle specific non-kubectl operations
@@ -0,0 +1,15 @@
1
+ export declare const contextParameter: {
2
+ type: "string";
3
+ description: string;
4
+ default: string;
5
+ };
6
+ export declare const namespaceParameter: {
7
+ type: "string";
8
+ description: string;
9
+ default: string;
10
+ };
11
+ export declare const dryRunParameter: {
12
+ type: "boolean";
13
+ description: string;
14
+ default: boolean;
15
+ };
@@ -0,0 +1,15 @@
1
+ export const contextParameter = {
2
+ type: "string",
3
+ description: "Kubeconfig Context to use for the command (optional - defaults to null)",
4
+ default: "",
5
+ };
6
+ export const namespaceParameter = {
7
+ type: "string",
8
+ description: "Kubernetes namespace",
9
+ default: "default",
10
+ };
11
+ export const dryRunParameter = {
12
+ type: "boolean",
13
+ description: "If true, only validate the resource, don't actually execute the operation",
14
+ default: false,
15
+ };
@@ -26,10 +26,12 @@ export interface ExplainResourceParams {
26
26
  apiVersion?: string;
27
27
  recursive?: boolean;
28
28
  output?: "plaintext" | "plaintext-openapiv2";
29
+ context?: string;
29
30
  }
30
31
  export interface ListApiResourcesParams {
31
32
  apiGroup?: string;
32
33
  namespaced?: boolean;
33
34
  verbs?: string[];
34
35
  output?: "wide" | "name" | "no-headers";
36
+ context?: string;
35
37
  }
@@ -23,7 +23,7 @@ export declare const execInPodSchema: {
23
23
  description: string;
24
24
  };
25
25
  namespace: {
26
- type: string;
26
+ type: "string";
27
27
  description: string;
28
28
  default: string;
29
29
  };
@@ -51,6 +51,11 @@ export declare const execInPodSchema: {
51
51
  type: string;
52
52
  description: string;
53
53
  };
54
+ context: {
55
+ type: "string";
56
+ description: string;
57
+ default: string;
58
+ };
54
59
  };
55
60
  required: string[];
56
61
  };
@@ -67,6 +72,7 @@ export declare function execInPod(k8sManager: KubernetesManager, input: {
67
72
  container?: string;
68
73
  shell?: string;
69
74
  timeout?: number;
75
+ context?: string;
70
76
  }): Promise<{
71
77
  content: {
72
78
  type: string;
@@ -7,6 +7,7 @@
7
7
  import * as k8s from "@kubernetes/client-node";
8
8
  import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
9
9
  import { Writable } from "stream";
10
+ import { contextParameter, namespaceParameter } from "../models/common-parameters.js";
10
11
  /**
11
12
  * Schema for exec_in_pod tool.
12
13
  * - name: Pod name
@@ -24,11 +25,7 @@ export const execInPodSchema = {
24
25
  type: "string",
25
26
  description: "Name of the pod to execute the command in",
26
27
  },
27
- namespace: {
28
- type: "string",
29
- description: "Kubernetes namespace where the pod is located",
30
- default: "default",
31
- },
28
+ namespace: namespaceParameter,
32
29
  command: {
33
30
  anyOf: [
34
31
  { type: "string" },
@@ -48,6 +45,7 @@ export const execInPodSchema = {
48
45
  type: "number",
49
46
  description: "Timeout for command - 60000 milliseconds if not specified",
50
47
  },
48
+ context: contextParameter,
51
49
  },
52
50
  required: ["name", "command"],
53
51
  },
@@ -93,6 +91,10 @@ export async function execInPod(k8sManager, input) {
93
91
  }
94
92
  });
95
93
  try {
94
+ // Set context if provided
95
+ if (input.context) {
96
+ k8sManager.setCurrentContext(input.context);
97
+ }
96
98
  // Use the Kubernetes client-node Exec API for native exec
97
99
  const kc = k8sManager.getKubeConfig();
98
100
  const exec = new k8s.Exec(kc);
@@ -18,8 +18,14 @@ export declare const installHelmChartSchema: {
18
18
  description: string;
19
19
  };
20
20
  namespace: {
21
- type: string;
21
+ type: "string";
22
+ description: string;
23
+ default: string;
24
+ };
25
+ context: {
26
+ type: "string";
22
27
  description: string;
28
+ default: string;
23
29
  };
24
30
  values: {
25
31
  type: string;
@@ -50,8 +56,14 @@ export declare const upgradeHelmChartSchema: {
50
56
  description: string;
51
57
  };
52
58
  namespace: {
53
- type: string;
59
+ type: "string";
54
60
  description: string;
61
+ default: string;
62
+ };
63
+ context: {
64
+ type: "string";
65
+ description: string;
66
+ default: string;
55
67
  };
56
68
  values: {
57
69
  type: string;
@@ -74,8 +86,14 @@ export declare const uninstallHelmChartSchema: {
74
86
  description: string;
75
87
  };
76
88
  namespace: {
77
- type: string;
89
+ type: "string";
90
+ description: string;
91
+ default: string;
92
+ };
93
+ context: {
94
+ type: "string";
78
95
  description: string;
96
+ default: string;
79
97
  };
80
98
  };
81
99
  required: string[];
@@ -2,6 +2,7 @@ import { execFileSync } from "child_process";
2
2
  import { writeFileSync, unlinkSync } from "fs";
3
3
  import yaml from "yaml";
4
4
  import { getSpawnMaxBuffer } from "../config/max-buffer.js";
5
+ import { contextParameter, namespaceParameter } from "../models/common-parameters.js";
5
6
  export const installHelmChartSchema = {
6
7
  name: "install_helm_chart",
7
8
  description: "Install a Helm chart",
@@ -20,10 +21,8 @@ export const installHelmChartSchema = {
20
21
  type: "string",
21
22
  description: "Chart repository URL",
22
23
  },
23
- namespace: {
24
- type: "string",
25
- description: "Kubernetes namespace",
26
- },
24
+ namespace: namespaceParameter,
25
+ context: contextParameter,
27
26
  values: {
28
27
  type: "object",
29
28
  description: "Chart values",
@@ -52,10 +51,8 @@ export const upgradeHelmChartSchema = {
52
51
  type: "string",
53
52
  description: "Chart repository URL",
54
53
  },
55
- namespace: {
56
- type: "string",
57
- description: "Kubernetes namespace",
58
- },
54
+ namespace: namespaceParameter,
55
+ context: contextParameter,
59
56
  values: {
60
57
  type: "object",
61
58
  description: "Chart values",
@@ -76,10 +73,8 @@ export const uninstallHelmChartSchema = {
76
73
  type: "string",
77
74
  description: "Release name",
78
75
  },
79
- namespace: {
80
- type: "string",
81
- description: "Kubernetes namespace",
82
- },
76
+ namespace: namespaceParameter,
77
+ context: contextParameter,
83
78
  },
84
79
  required: ["name", "namespace"],
85
80
  },
@@ -14,20 +14,25 @@ export declare const kubectlApplySchema: {
14
14
  readonly description: "Path to a YAML file to apply (optional - use either manifest or filename)";
15
15
  };
16
16
  readonly namespace: {
17
- readonly type: "string";
18
- readonly description: "Namespace to apply the resource to (optional)";
19
- readonly default: "default";
17
+ type: "string";
18
+ description: string;
19
+ default: string;
20
20
  };
21
21
  readonly dryRun: {
22
- readonly type: "boolean";
23
- readonly description: "If true, only validate the resource, don't apply it";
24
- readonly default: false;
22
+ type: "boolean";
23
+ description: string;
24
+ default: boolean;
25
25
  };
26
26
  readonly force: {
27
27
  readonly type: "boolean";
28
28
  readonly description: "If true, immediately remove resources from API and bypass graceful deletion";
29
29
  readonly default: false;
30
30
  };
31
+ readonly context: {
32
+ type: "string";
33
+ description: string;
34
+ default: string;
35
+ };
31
36
  };
32
37
  readonly required: readonly [];
33
38
  };
@@ -38,6 +43,7 @@ export declare function kubectlApply(k8sManager: KubernetesManager, input: {
38
43
  namespace?: string;
39
44
  dryRun?: boolean;
40
45
  force?: boolean;
46
+ context?: string;
41
47
  }): Promise<{
42
48
  content: {
43
49
  type: string;
@@ -4,6 +4,7 @@ import * as fs from "fs";
4
4
  import * as path from "path";
5
5
  import * as os from "os";
6
6
  import { getSpawnMaxBuffer } from "../config/max-buffer.js";
7
+ import { contextParameter, namespaceParameter, dryRunParameter } from "../models/common-parameters.js";
7
8
  export const kubectlApplySchema = {
8
9
  name: "kubectl_apply",
9
10
  description: "Apply a Kubernetes YAML manifest from a string or file",
@@ -18,21 +19,14 @@ export const kubectlApplySchema = {
18
19
  type: "string",
19
20
  description: "Path to a YAML file to apply (optional - use either manifest or filename)",
20
21
  },
21
- namespace: {
22
- type: "string",
23
- description: "Namespace to apply the resource to (optional)",
24
- default: "default",
25
- },
26
- dryRun: {
27
- type: "boolean",
28
- description: "If true, only validate the resource, don't apply it",
29
- default: false,
30
- },
22
+ namespace: namespaceParameter,
23
+ dryRun: dryRunParameter,
31
24
  force: {
32
25
  type: "boolean",
33
26
  description: "If true, immediately remove resources from API and bypass graceful deletion",
34
27
  default: false,
35
28
  },
29
+ context: contextParameter,
36
30
  },
37
31
  required: [],
38
32
  },
@@ -45,6 +39,7 @@ export async function kubectlApply(k8sManager, input) {
45
39
  const namespace = input.namespace || "default";
46
40
  const dryRun = input.dryRun || false;
47
41
  const force = input.force || false;
42
+ const context = input.context || "";
48
43
  let command = "kubectl";
49
44
  let args = ["apply"];
50
45
  let tempFile = null;
@@ -69,6 +64,10 @@ export async function kubectlApply(k8sManager, input) {
69
64
  if (force) {
70
65
  args.push("--force");
71
66
  }
67
+ // Add context if provided
68
+ if (context) {
69
+ args.push("--context", context);
70
+ }
72
71
  // Execute the command
73
72
  try {
74
73
  const result = execFileSync(command, args, {
@@ -6,9 +6,9 @@ export declare const kubectlCreateSchema: {
6
6
  readonly type: "object";
7
7
  readonly properties: {
8
8
  readonly dryRun: {
9
- readonly type: "boolean";
10
- readonly description: "If true, only validate the resource, don't actually create it";
11
- readonly default: false;
9
+ type: "boolean";
10
+ description: string;
11
+ default: boolean;
12
12
  };
13
13
  readonly output: {
14
14
  readonly type: "string";
@@ -38,9 +38,9 @@ export declare const kubectlCreateSchema: {
38
38
  readonly description: "Name of the resource to create";
39
39
  };
40
40
  readonly namespace: {
41
- readonly type: "string";
42
- readonly description: "Namespace to create the resource in";
43
- readonly default: "default";
41
+ type: "string";
42
+ description: string;
43
+ default: string;
44
44
  };
45
45
  readonly fromLiteral: {
46
46
  readonly type: "array";
@@ -116,6 +116,11 @@ export declare const kubectlCreateSchema: {
116
116
  };
117
117
  readonly description: "Annotations to apply to the resource (e.g. [\"key1=value1\", \"key2=value2\"])";
118
118
  };
119
+ readonly context: {
120
+ type: "string";
121
+ description: string;
122
+ default: string;
123
+ };
119
124
  };
120
125
  readonly required: readonly [];
121
126
  };
@@ -142,6 +147,7 @@ export declare function kubectlCreate(k8sManager: KubernetesManager, input: {
142
147
  annotations?: string[];
143
148
  schedule?: string;
144
149
  suspend?: boolean;
150
+ context?: string;
145
151
  }): Promise<{
146
152
  content: {
147
153
  type: string;
@@ -4,6 +4,7 @@ import * as fs from "fs";
4
4
  import * as path from "path";
5
5
  import * as os from "os";
6
6
  import { getSpawnMaxBuffer } from "../config/max-buffer.js";
7
+ import { contextParameter, namespaceParameter, dryRunParameter } from "../models/common-parameters.js";
7
8
  export const kubectlCreateSchema = {
8
9
  name: "kubectl_create",
9
10
  description: "Create Kubernetes resources using various methods (from file or using subcommands)",
@@ -11,11 +12,7 @@ export const kubectlCreateSchema = {
11
12
  type: "object",
12
13
  properties: {
13
14
  // General options
14
- dryRun: {
15
- type: "boolean",
16
- description: "If true, only validate the resource, don't actually create it",
17
- default: false,
18
- },
15
+ dryRun: dryRunParameter,
19
16
  output: {
20
17
  type: "string",
21
18
  enum: [
@@ -57,11 +54,7 @@ export const kubectlCreateSchema = {
57
54
  type: "string",
58
55
  description: "Name of the resource to create",
59
56
  },
60
- namespace: {
61
- type: "string",
62
- description: "Namespace to create the resource in",
63
- default: "default",
64
- },
57
+ namespace: namespaceParameter,
65
58
  // ConfigMap specific parameters
66
59
  fromLiteral: {
67
60
  type: "array",
@@ -133,6 +126,7 @@ export const kubectlCreateSchema = {
133
126
  items: { type: "string" },
134
127
  description: 'Annotations to apply to the resource (e.g. ["key1=value1", "key2=value2"])',
135
128
  },
129
+ context: contextParameter,
136
130
  },
137
131
  required: [],
138
132
  },
@@ -154,6 +148,7 @@ export async function kubectlCreate(k8sManager, input) {
154
148
  const dryRun = input.dryRun || false;
155
149
  const validate = input.validate ?? true;
156
150
  const output = input.output || "yaml";
151
+ const context = input.context || "";
157
152
  const command = "kubectl";
158
153
  const args = ["create"];
159
154
  let tempFile = null;
@@ -293,6 +288,10 @@ export async function kubectlCreate(k8sManager, input) {
293
288
  }
294
289
  // Add output format
295
290
  args.push("-o", output);
291
+ // Add context if provided
292
+ if (context) {
293
+ args.push("--context", context);
294
+ }
296
295
  // Execute the command
297
296
  try {
298
297
  const result = execFileSync(command, args, {