mcp-server-kubernetes 2.4.7 → 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.
- package/dist/config/max-buffer.d.ts +1 -0
- package/dist/config/max-buffer.js +3 -0
- package/dist/index.js +27 -5
- package/dist/tools/exec_in_pod.d.ts +0 -3
- package/dist/tools/exec_in_pod.js +0 -3
- package/dist/tools/helm-operations.js +39 -17
- package/dist/tools/kubectl-apply.js +20 -14
- package/dist/tools/kubectl-context.js +53 -24
- package/dist/tools/kubectl-create.js +78 -59
- package/dist/tools/kubectl-delete.js +44 -28
- package/dist/tools/kubectl-describe.js +29 -19
- package/dist/tools/kubectl-generic.js +22 -17
- package/dist/tools/kubectl-get.js +22 -21
- package/dist/tools/kubectl-logs.js +99 -43
- package/dist/tools/kubectl-operations.js +22 -15
- package/dist/tools/kubectl-patch.js +25 -20
- package/dist/tools/kubectl-rollout.js +35 -22
- package/dist/tools/kubectl-scale.js +31 -20
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
56
|
-
|
|
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
|
-
|
|
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
|
-
|
|
70
|
+
args.push(`--revision=${input.toRevision}`);
|
|
64
71
|
}
|
|
65
72
|
// Add timeout if specified
|
|
66
73
|
if (input.timeout) {
|
|
67
|
-
|
|
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
|
-
|
|
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 =
|
|
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 +
|
|
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 =
|
|
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 {
|
|
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
|
-
|
|
36
|
-
|
|
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 =
|
|
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
|
}
|