mcp-server-kubernetes 1.1.0 → 1.3.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.js +17 -1
- package/dist/models/response-schemas.d.ts +66 -0
- package/dist/models/response-schemas.js +15 -0
- package/dist/tools/create_configmap.d.ts +33 -0
- package/dist/tools/create_configmap.js +66 -0
- package/dist/tools/delete_cronjob.d.ts +26 -0
- package/dist/tools/delete_cronjob.js +48 -0
- package/dist/tools/delete_namespace.d.ts +27 -0
- package/dist/tools/delete_namespace.js +44 -0
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -14,6 +14,7 @@ import { explainResource, explainResourceSchema, listApiResources, listApiResour
|
|
|
14
14
|
import { createNamespace, createNamespaceSchema, } from "./tools/create_namespace.js";
|
|
15
15
|
import { createPod, createPodSchema } from "./tools/create_pod.js";
|
|
16
16
|
import { createCronJob, createCronJobSchema } from "./tools/create_cronjob.js";
|
|
17
|
+
import { DeleteCronJob, DeleteCronJobSchema } from "./tools/delete_cronjob.js";
|
|
17
18
|
import { deletePod, deletePodSchema } from "./tools/delete_pod.js";
|
|
18
19
|
import { describePod, describePodSchema } from "./tools/describe_pod.js";
|
|
19
20
|
import { getLogs, getLogsSchema } from "./tools/get_logs.js";
|
|
@@ -24,13 +25,15 @@ import { KubernetesManager } from "./types.js";
|
|
|
24
25
|
import { serverConfig } from "./config/server-config.js";
|
|
25
26
|
import { createDeploymentSchema } from "./config/deployment-config.js";
|
|
26
27
|
import { listNamespacesSchema } from "./config/namespace-config.js";
|
|
28
|
+
import { deleteNamespace, deleteNamespaceSchema } from "./tools/delete_namespace.js";
|
|
27
29
|
import { cleanupSchema } from "./config/cleanup-config.js";
|
|
28
30
|
import { startSSEServer } from "./utils/sse.js";
|
|
29
31
|
import { startPortForward, PortForwardSchema, stopPortForward, StopPortForwardSchema, } from "./tools/port_forward.js";
|
|
30
|
-
import { deleteDeployment } from "./tools/delete_deployment.js";
|
|
32
|
+
import { deleteDeployment, deleteDeploymentSchema } from "./tools/delete_deployment.js";
|
|
31
33
|
import { createDeployment } from "./tools/create_deployment.js";
|
|
32
34
|
import { scaleDeployment, scaleDeploymentSchema } from "./tools/scale_deployment.js";
|
|
33
35
|
import { describeDeployment, describeDeploymentSchema, } from "./tools/describe_deployment.js";
|
|
36
|
+
import { createConfigMap, CreateConfigMapSchema } from "./tools/create_configmap.js";
|
|
34
37
|
const k8sManager = new KubernetesManager();
|
|
35
38
|
const server = new Server({
|
|
36
39
|
name: serverConfig.name,
|
|
@@ -46,6 +49,8 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
|
46
49
|
createPodSchema,
|
|
47
50
|
createCronJobSchema,
|
|
48
51
|
deletePodSchema,
|
|
52
|
+
deleteDeploymentSchema,
|
|
53
|
+
deleteNamespaceSchema,
|
|
49
54
|
describeCronJobSchema,
|
|
50
55
|
describePodSchema,
|
|
51
56
|
describeDeploymentSchema,
|
|
@@ -67,6 +72,8 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
|
67
72
|
PortForwardSchema,
|
|
68
73
|
StopPortForwardSchema,
|
|
69
74
|
scaleDeploymentSchema,
|
|
75
|
+
DeleteCronJobSchema,
|
|
76
|
+
CreateConfigMapSchema,
|
|
70
77
|
],
|
|
71
78
|
};
|
|
72
79
|
});
|
|
@@ -96,6 +103,9 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
96
103
|
case "create_cronjob": {
|
|
97
104
|
return await createCronJob(k8sManager, input);
|
|
98
105
|
}
|
|
106
|
+
case "delete_cronjob": {
|
|
107
|
+
return await DeleteCronJob(k8sManager, input);
|
|
108
|
+
}
|
|
99
109
|
case "delete_pod": {
|
|
100
110
|
return await deletePod(k8sManager, input);
|
|
101
111
|
}
|
|
@@ -169,6 +179,9 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
169
179
|
case "stop_port_forward": {
|
|
170
180
|
return await stopPortForward(k8sManager, input);
|
|
171
181
|
}
|
|
182
|
+
case "delete_namespace": {
|
|
183
|
+
return await deleteNamespace(k8sManager, input);
|
|
184
|
+
}
|
|
172
185
|
case "delete_deployment": {
|
|
173
186
|
return await deleteDeployment(k8sManager, input);
|
|
174
187
|
}
|
|
@@ -181,6 +194,9 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
181
194
|
case "scale_deployment": {
|
|
182
195
|
return await scaleDeployment(k8sManager, input);
|
|
183
196
|
}
|
|
197
|
+
case "create_configmap": {
|
|
198
|
+
return await createConfigMap(k8sManager, input);
|
|
199
|
+
}
|
|
184
200
|
default:
|
|
185
201
|
throw new McpError(ErrorCode.InvalidRequest, `Unknown tool: ${name}`);
|
|
186
202
|
}
|
|
@@ -21,6 +21,28 @@ export declare const CreateNamespaceResponseSchema: z.ZodObject<{
|
|
|
21
21
|
text: string;
|
|
22
22
|
}[];
|
|
23
23
|
}>;
|
|
24
|
+
export declare const DeleteNamespaceResponseSchema: z.ZodObject<{
|
|
25
|
+
content: z.ZodArray<z.ZodObject<{
|
|
26
|
+
type: z.ZodLiteral<"text">;
|
|
27
|
+
text: z.ZodString;
|
|
28
|
+
}, "strip", z.ZodTypeAny, {
|
|
29
|
+
type: "text";
|
|
30
|
+
text: string;
|
|
31
|
+
}, {
|
|
32
|
+
type: "text";
|
|
33
|
+
text: string;
|
|
34
|
+
}>, "many">;
|
|
35
|
+
}, "strip", z.ZodTypeAny, {
|
|
36
|
+
content: {
|
|
37
|
+
type: "text";
|
|
38
|
+
text: string;
|
|
39
|
+
}[];
|
|
40
|
+
}, {
|
|
41
|
+
content: {
|
|
42
|
+
type: "text";
|
|
43
|
+
text: string;
|
|
44
|
+
}[];
|
|
45
|
+
}>;
|
|
24
46
|
export declare const CreatePodResponseSchema: z.ZodObject<{
|
|
25
47
|
content: z.ZodArray<z.ZodObject<{
|
|
26
48
|
type: z.ZodLiteral<"text">;
|
|
@@ -439,3 +461,47 @@ export declare const ScaleDeploymentResponseSchema: z.ZodObject<{
|
|
|
439
461
|
success: boolean;
|
|
440
462
|
}[];
|
|
441
463
|
}>;
|
|
464
|
+
export declare const DeleteCronJobResponseSchema: z.ZodObject<{
|
|
465
|
+
content: z.ZodArray<z.ZodObject<{
|
|
466
|
+
success: z.ZodBoolean;
|
|
467
|
+
message: z.ZodString;
|
|
468
|
+
}, "strip", z.ZodTypeAny, {
|
|
469
|
+
message: string;
|
|
470
|
+
success: boolean;
|
|
471
|
+
}, {
|
|
472
|
+
message: string;
|
|
473
|
+
success: boolean;
|
|
474
|
+
}>, "many">;
|
|
475
|
+
}, "strip", z.ZodTypeAny, {
|
|
476
|
+
content: {
|
|
477
|
+
message: string;
|
|
478
|
+
success: boolean;
|
|
479
|
+
}[];
|
|
480
|
+
}, {
|
|
481
|
+
content: {
|
|
482
|
+
message: string;
|
|
483
|
+
success: boolean;
|
|
484
|
+
}[];
|
|
485
|
+
}>;
|
|
486
|
+
export declare const CreateConfigMapResponseSchema: z.ZodObject<{
|
|
487
|
+
content: z.ZodArray<z.ZodObject<{
|
|
488
|
+
success: z.ZodBoolean;
|
|
489
|
+
message: z.ZodString;
|
|
490
|
+
}, "strip", z.ZodTypeAny, {
|
|
491
|
+
message: string;
|
|
492
|
+
success: boolean;
|
|
493
|
+
}, {
|
|
494
|
+
message: string;
|
|
495
|
+
success: boolean;
|
|
496
|
+
}>, "many">;
|
|
497
|
+
}, "strip", z.ZodTypeAny, {
|
|
498
|
+
content: {
|
|
499
|
+
message: string;
|
|
500
|
+
success: boolean;
|
|
501
|
+
}[];
|
|
502
|
+
}, {
|
|
503
|
+
content: {
|
|
504
|
+
message: string;
|
|
505
|
+
success: boolean;
|
|
506
|
+
}[];
|
|
507
|
+
}>;
|
|
@@ -7,6 +7,9 @@ const ToolResponseContent = z.object({
|
|
|
7
7
|
export const CreateNamespaceResponseSchema = z.object({
|
|
8
8
|
content: z.array(ToolResponseContent),
|
|
9
9
|
});
|
|
10
|
+
export const DeleteNamespaceResponseSchema = z.object({
|
|
11
|
+
content: z.array(ToolResponseContent),
|
|
12
|
+
});
|
|
10
13
|
export const CreatePodResponseSchema = z.object({
|
|
11
14
|
content: z.array(ToolResponseContent),
|
|
12
15
|
});
|
|
@@ -70,3 +73,15 @@ export const ScaleDeploymentResponseSchema = z.object({
|
|
|
70
73
|
message: z.string(),
|
|
71
74
|
})),
|
|
72
75
|
});
|
|
76
|
+
export const DeleteCronJobResponseSchema = z.object({
|
|
77
|
+
content: z.array(z.object({
|
|
78
|
+
success: z.boolean(),
|
|
79
|
+
message: z.string(),
|
|
80
|
+
})),
|
|
81
|
+
});
|
|
82
|
+
export const CreateConfigMapResponseSchema = z.object({
|
|
83
|
+
content: z.array(z.object({
|
|
84
|
+
success: z.boolean(),
|
|
85
|
+
message: z.string(),
|
|
86
|
+
})),
|
|
87
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { KubernetesManager } from "../types.js";
|
|
2
|
+
export declare const CreateConfigMapSchema: {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
inputSchema: {
|
|
6
|
+
type: string;
|
|
7
|
+
properties: {
|
|
8
|
+
name: {
|
|
9
|
+
type: string;
|
|
10
|
+
};
|
|
11
|
+
namespace: {
|
|
12
|
+
type: string;
|
|
13
|
+
};
|
|
14
|
+
data: {
|
|
15
|
+
type: string;
|
|
16
|
+
ConfigData: {
|
|
17
|
+
type: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
required: string[];
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export declare function createConfigMap(k8sManager: KubernetesManager, input: {
|
|
25
|
+
name: string;
|
|
26
|
+
namespace: string;
|
|
27
|
+
data: Record<string, string>;
|
|
28
|
+
}): Promise<{
|
|
29
|
+
content: {
|
|
30
|
+
success: boolean;
|
|
31
|
+
message: string;
|
|
32
|
+
}[];
|
|
33
|
+
}>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export const CreateConfigMapSchema = {
|
|
2
|
+
name: "create_configmap",
|
|
3
|
+
description: "Create a new Kubernetes ConfigMap",
|
|
4
|
+
inputSchema: {
|
|
5
|
+
type: "object",
|
|
6
|
+
properties: {
|
|
7
|
+
name: { type: "string" },
|
|
8
|
+
namespace: { type: "string" },
|
|
9
|
+
data: {
|
|
10
|
+
type: "object",
|
|
11
|
+
ConfigData: { type: "string" },
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
required: ["name", "namespace", "data"],
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
export async function createConfigMap(k8sManager, input) {
|
|
18
|
+
try {
|
|
19
|
+
const configmap = {
|
|
20
|
+
apiVersion: "v1",
|
|
21
|
+
kind: "ConfigMap",
|
|
22
|
+
binaryData: undefined,
|
|
23
|
+
data: input.data,
|
|
24
|
+
immutable: false,
|
|
25
|
+
metadata: {
|
|
26
|
+
name: input.name,
|
|
27
|
+
namespace: input.namespace,
|
|
28
|
+
labels: {
|
|
29
|
+
"mcp-managed": "true",
|
|
30
|
+
app: input.name,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
const response = await k8sManager.getCoreApi().createNamespacedConfigMap(input.namespace, configmap);
|
|
35
|
+
if (response.response?.statusCode !== undefined && (response.response.statusCode == 200 || response.response.statusCode == 201 || response.response.statusCode == 202)) {
|
|
36
|
+
return {
|
|
37
|
+
content: [
|
|
38
|
+
{
|
|
39
|
+
success: true,
|
|
40
|
+
message: `Created ConfigMap ${response.body.metadata?.name} in namespace ${response.body.metadata?.namespace}`,
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
return {
|
|
47
|
+
content: [
|
|
48
|
+
{
|
|
49
|
+
success: false,
|
|
50
|
+
message: `Failed to create ConfigMap ${response.body.metadata?.name} in namespace ${response.body.metadata?.namespace}`,
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
return {
|
|
58
|
+
content: [
|
|
59
|
+
{
|
|
60
|
+
success: false,
|
|
61
|
+
message: `Failed to create ConfigMap ${input.name} in namespace ${input.namespace}. Error: ${error.message}`,
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { KubernetesManager } from "../types.js";
|
|
2
|
+
export declare const DeleteCronJobSchema: {
|
|
3
|
+
readonly name: "delete_cronjob";
|
|
4
|
+
readonly description: "Delete a Kubernetes CronJob";
|
|
5
|
+
readonly inputSchema: {
|
|
6
|
+
readonly type: "object";
|
|
7
|
+
readonly properties: {
|
|
8
|
+
readonly name: {
|
|
9
|
+
readonly type: "string";
|
|
10
|
+
};
|
|
11
|
+
readonly namespace: {
|
|
12
|
+
readonly type: "string";
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
readonly required: readonly ["name", "namespace"];
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export declare function DeleteCronJob(k8sManager: KubernetesManager, input: {
|
|
19
|
+
name: string;
|
|
20
|
+
namespace: string;
|
|
21
|
+
}): Promise<{
|
|
22
|
+
content: {
|
|
23
|
+
success: boolean;
|
|
24
|
+
message: string;
|
|
25
|
+
}[];
|
|
26
|
+
}>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export const DeleteCronJobSchema = {
|
|
2
|
+
name: "delete_cronjob",
|
|
3
|
+
description: "Delete a Kubernetes CronJob",
|
|
4
|
+
inputSchema: {
|
|
5
|
+
type: "object",
|
|
6
|
+
properties: {
|
|
7
|
+
name: { type: "string" },
|
|
8
|
+
namespace: { type: "string" }
|
|
9
|
+
},
|
|
10
|
+
required: ["name", "namespace"]
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
export async function DeleteCronJob(k8sManager, input) {
|
|
14
|
+
try {
|
|
15
|
+
const response = await k8sManager.getBatchApi().deleteNamespacedCronJob(input.name, input.namespace);
|
|
16
|
+
if (response.response?.statusCode !== undefined && (response.response.statusCode === 200 || response.response.statusCode === 202)) {
|
|
17
|
+
return {
|
|
18
|
+
content: [
|
|
19
|
+
{
|
|
20
|
+
success: true,
|
|
21
|
+
message: `Deleted cronjob ${input.name} in namespace ${input.namespace}.` +
|
|
22
|
+
(response.body?.details ? ` Details: ${response.body.details}` : "")
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return {
|
|
29
|
+
content: [
|
|
30
|
+
{
|
|
31
|
+
success: false,
|
|
32
|
+
message: `Failed to delete cronjob ${input.name} in namespace ${input.namespace}.` + (response.body?.details ? ` Details: ${response.body.details}` : "")
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
return {
|
|
40
|
+
content: [
|
|
41
|
+
{
|
|
42
|
+
success: false,
|
|
43
|
+
message: `Failed to delete cronjob: ${error.message}`
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { KubernetesManager } from "../types.js";
|
|
2
|
+
export declare const deleteNamespaceSchema: {
|
|
3
|
+
readonly name: "delete_namespace";
|
|
4
|
+
readonly description: "Delete a Kubernetes namespace";
|
|
5
|
+
readonly inputSchema: {
|
|
6
|
+
readonly type: "object";
|
|
7
|
+
readonly properties: {
|
|
8
|
+
readonly name: {
|
|
9
|
+
readonly type: "string";
|
|
10
|
+
};
|
|
11
|
+
readonly ignoreNotFound: {
|
|
12
|
+
readonly type: "boolean";
|
|
13
|
+
readonly default: false;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
readonly required: readonly ["name"];
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export declare function deleteNamespace(k8sManager: KubernetesManager, input: {
|
|
20
|
+
name: string;
|
|
21
|
+
ignoreNotFound?: boolean;
|
|
22
|
+
}): Promise<{
|
|
23
|
+
content: {
|
|
24
|
+
type: string;
|
|
25
|
+
text: string;
|
|
26
|
+
}[];
|
|
27
|
+
}>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export const deleteNamespaceSchema = {
|
|
2
|
+
name: "delete_namespace",
|
|
3
|
+
description: "Delete a Kubernetes namespace",
|
|
4
|
+
inputSchema: {
|
|
5
|
+
type: "object",
|
|
6
|
+
properties: {
|
|
7
|
+
name: { type: "string" },
|
|
8
|
+
ignoreNotFound: { type: "boolean", default: false },
|
|
9
|
+
},
|
|
10
|
+
required: ["name"],
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
export async function deleteNamespace(k8sManager, input) {
|
|
14
|
+
try {
|
|
15
|
+
await k8sManager.getCoreApi().deleteNamespace(input.name);
|
|
16
|
+
return {
|
|
17
|
+
content: [
|
|
18
|
+
{
|
|
19
|
+
type: "text",
|
|
20
|
+
text: JSON.stringify({
|
|
21
|
+
success: true,
|
|
22
|
+
status: "deleted",
|
|
23
|
+
}, null, 2),
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
if (input.ignoreNotFound && error.response?.statusCode === 404) {
|
|
30
|
+
return {
|
|
31
|
+
content: [
|
|
32
|
+
{
|
|
33
|
+
type: "text",
|
|
34
|
+
text: JSON.stringify({
|
|
35
|
+
success: true,
|
|
36
|
+
status: "not_found",
|
|
37
|
+
}, null, 2),
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-server-kubernetes",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "MCP server for interacting with Kubernetes clusters via kubectl",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@kubernetes/client-node": "0.20.0",
|
|
39
39
|
"@modelcontextprotocol/sdk": "1.7.0",
|
|
40
|
+
"express": "4.21.2",
|
|
40
41
|
"js-yaml": "4.1.0",
|
|
41
42
|
"yaml": "2.7.0",
|
|
42
|
-
"zod": "3.23.8"
|
|
43
|
-
"express": "4.21.2"
|
|
43
|
+
"zod": "3.23.8"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/express": "5.0.1",
|