mcp-server-kubernetes 2.4.9 → 2.5.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.
@@ -1,5 +1,6 @@
1
- import { execSync } from "child_process";
1
+ import { execFileSync } from "child_process";
2
2
  import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
3
+ import { getSpawnMaxBuffer } from "../config/max-buffer.js";
3
4
  export const kubectlRolloutSchema = {
4
5
  name: "kubectl_rollout",
5
6
  description: "Manage the rollout of a resource (e.g., deployment, daemonset, statefulset)",
@@ -10,86 +11,98 @@ export const kubectlRolloutSchema = {
10
11
  type: "string",
11
12
  description: "Rollout subcommand to execute",
12
13
  enum: ["history", "pause", "restart", "resume", "status", "undo"],
13
- default: "status"
14
+ default: "status",
14
15
  },
15
16
  resourceType: {
16
17
  type: "string",
17
18
  description: "Type of resource to manage rollout for",
18
19
  enum: ["deployment", "daemonset", "statefulset"],
19
- default: "deployment"
20
+ default: "deployment",
20
21
  },
21
22
  name: {
22
23
  type: "string",
23
- description: "Name of the resource"
24
+ description: "Name of the resource",
24
25
  },
25
26
  namespace: {
26
27
  type: "string",
27
28
  description: "Namespace of the resource",
28
- default: "default"
29
+ default: "default",
29
30
  },
30
31
  revision: {
31
32
  type: "number",
32
- description: "Revision to rollback to (for undo subcommand)"
33
+ description: "Revision to rollback to (for undo subcommand)",
33
34
  },
34
35
  toRevision: {
35
36
  type: "number",
36
- description: "Revision to roll back to (for history subcommand)"
37
+ description: "Revision to roll back to (for history subcommand)",
37
38
  },
38
39
  timeout: {
39
40
  type: "string",
40
- description: "The length of time to wait before giving up (e.g., '30s', '1m', '2m30s')"
41
+ description: "The length of time to wait before giving up (e.g., '30s', '1m', '2m30s')",
41
42
  },
42
43
  watch: {
43
44
  type: "boolean",
44
45
  description: "Watch the rollout status in real-time until completion",
45
- default: false
46
- }
46
+ default: false,
47
+ },
47
48
  },
48
- required: ["subCommand", "resourceType", "name", "namespace"]
49
- }
49
+ required: ["subCommand", "resourceType", "name", "namespace"],
50
+ },
50
51
  };
51
52
  export async function kubectlRollout(k8sManager, input) {
52
53
  try {
53
54
  const namespace = input.namespace || "default";
54
55
  const watch = input.watch || false;
55
- // Build the kubectl rollout command
56
- let command = `kubectl rollout ${input.subCommand} ${input.resourceType}/${input.name} -n ${namespace}`;
56
+ const command = "kubectl";
57
+ const args = [
58
+ "rollout",
59
+ input.subCommand,
60
+ `${input.resourceType}/${input.name}`,
61
+ "-n",
62
+ namespace,
63
+ ];
57
64
  // Add revision for undo
58
65
  if (input.subCommand === "undo" && input.revision !== undefined) {
59
- command += ` --to-revision=${input.revision}`;
66
+ args.push(`--to-revision=${input.revision}`);
60
67
  }
61
68
  // Add revision for history
62
69
  if (input.subCommand === "history" && input.toRevision !== undefined) {
63
- command += ` --revision=${input.toRevision}`;
70
+ args.push(`--revision=${input.toRevision}`);
64
71
  }
65
72
  // Add timeout if specified
66
73
  if (input.timeout) {
67
- command += ` --timeout=${input.timeout}`;
74
+ args.push(`--timeout=${input.timeout}`);
68
75
  }
69
76
  // Execute the command
70
77
  try {
71
78
  // For status command with watch flag, we need to handle it differently
72
79
  // since it's meant to be interactive and follow the progress
73
80
  if (input.subCommand === "status" && watch) {
74
- command += " --watch";
81
+ args.push("--watch");
75
82
  // For watch we are limited in what we can do - we'll execute it with a reasonable timeout
76
83
  // and capture the output until that point
77
- const result = execSync(command, {
84
+ const result = execFileSync(command, args, {
78
85
  encoding: "utf8",
86
+ maxBuffer: getSpawnMaxBuffer(),
79
87
  timeout: 15000, // Reduced from 30 seconds to 15 seconds
80
- env: { ...process.env, KUBECONFIG: process.env.KUBECONFIG }
88
+ env: { ...process.env, KUBECONFIG: process.env.KUBECONFIG },
81
89
  });
82
90
  return {
83
91
  content: [
84
92
  {
85
93
  type: "text",
86
- text: result + "\n\nNote: Watch operation was limited to 15 seconds. The rollout may still be in progress.",
94
+ text: result +
95
+ "\n\nNote: Watch operation was limited to 15 seconds. The rollout may still be in progress.",
87
96
  },
88
97
  ],
89
98
  };
90
99
  }
91
100
  else {
92
- const result = execSync(command, { encoding: "utf8", env: { ...process.env, KUBECONFIG: process.env.KUBECONFIG } });
101
+ const result = execFileSync(command, args, {
102
+ encoding: "utf8",
103
+ maxBuffer: getSpawnMaxBuffer(),
104
+ env: { ...process.env, KUBECONFIG: process.env.KUBECONFIG },
105
+ });
93
106
  return {
94
107
  content: [
95
108
  {
@@ -1,5 +1,6 @@
1
- import { execSync } from "child_process";
1
+ import { execFileSync } from "child_process";
2
2
  import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
3
+ import { getSpawnMaxBuffer } from "../config/max-buffer.js";
3
4
  export const kubectlScaleSchema = {
4
5
  name: "kubectl_scale",
5
6
  description: "Scale a Kubernetes deployment",
@@ -8,42 +9,52 @@ export const kubectlScaleSchema = {
8
9
  properties: {
9
10
  name: {
10
11
  type: "string",
11
- description: "Name of the deployment to scale"
12
+ description: "Name of the deployment to scale",
12
13
  },
13
14
  namespace: {
14
15
  type: "string",
15
16
  description: "Namespace of the deployment",
16
- default: "default"
17
+ default: "default",
17
18
  },
18
19
  replicas: {
19
20
  type: "number",
20
- description: "Number of replicas to scale to"
21
+ description: "Number of replicas to scale to",
21
22
  },
22
23
  resourceType: {
23
24
  type: "string",
24
25
  description: "Resource type to scale (deployment, replicaset, statefulset)",
25
- default: "deployment"
26
- }
26
+ default: "deployment",
27
+ },
27
28
  },
28
- required: ["name", "replicas"]
29
- }
29
+ required: ["name", "replicas"],
30
+ },
30
31
  };
31
32
  export async function kubectlScale(k8sManager, input) {
32
33
  try {
33
34
  const namespace = input.namespace || "default";
34
35
  const resourceType = input.resourceType || "deployment";
35
- // Build the kubectl scale command
36
- let command = `kubectl scale ${resourceType} ${input.name} --replicas=${input.replicas} --namespace=${namespace}`;
36
+ const command = "kubectl";
37
+ const args = [
38
+ "scale",
39
+ resourceType,
40
+ input.name,
41
+ `--replicas=${input.replicas}`,
42
+ `--namespace=${namespace}`,
43
+ ];
37
44
  // Execute the command
38
45
  try {
39
- const result = execSync(command, { encoding: "utf8", env: { ...process.env, KUBECONFIG: process.env.KUBECONFIG } });
46
+ const result = execFileSync(command, args, {
47
+ encoding: "utf8",
48
+ maxBuffer: getSpawnMaxBuffer(),
49
+ env: { ...process.env, KUBECONFIG: process.env.KUBECONFIG },
50
+ });
40
51
  return {
41
52
  content: [
42
53
  {
43
54
  success: true,
44
- message: `Scaled ${resourceType} ${input.name} to ${input.replicas} replicas`
45
- }
46
- ]
55
+ message: `Scaled ${resourceType} ${input.name} to ${input.replicas} replicas`,
56
+ },
57
+ ],
47
58
  };
48
59
  }
49
60
  catch (error) {
@@ -56,18 +67,18 @@ export async function kubectlScale(k8sManager, input) {
56
67
  content: [
57
68
  {
58
69
  success: false,
59
- message: error.message
60
- }
61
- ]
70
+ message: error.message,
71
+ },
72
+ ],
62
73
  };
63
74
  }
64
75
  return {
65
76
  content: [
66
77
  {
67
78
  success: false,
68
- message: `Failed to scale resource: ${error.message}`
69
- }
70
- ]
79
+ message: `Failed to scale resource: ${error.message}`,
80
+ },
81
+ ],
71
82
  };
72
83
  }
73
84
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-server-kubernetes",
3
- "version": "2.4.9",
3
+ "version": "2.5.0",
4
4
  "description": "MCP server for interacting with Kubernetes clusters via kubectl",
5
5
  "license": "MIT",
6
6
  "type": "module",