mcp-server-kubernetes 1.6.2 → 2.0.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.
Files changed (96) hide show
  1. package/README.md +46 -22
  2. package/dist/config/container-templates.d.ts +2 -2
  3. package/dist/index.d.ts +314 -736
  4. package/dist/index.js +93 -200
  5. package/dist/models/resource-models.d.ts +6 -6
  6. package/dist/tools/kubectl-apply.d.ts +46 -0
  7. package/dist/tools/kubectl-apply.js +110 -0
  8. package/dist/tools/kubectl-context.d.ts +49 -0
  9. package/dist/tools/kubectl-context.js +233 -0
  10. package/dist/tools/kubectl-create.d.ts +150 -0
  11. package/dist/tools/kubectl-create.js +321 -0
  12. package/dist/tools/kubectl-delete.d.ts +77 -0
  13. package/dist/tools/kubectl-delete.js +177 -0
  14. package/dist/tools/kubectl-describe.d.ts +47 -0
  15. package/dist/tools/kubectl-describe.js +96 -0
  16. package/dist/tools/kubectl-generic.d.ts +71 -0
  17. package/dist/tools/kubectl-generic.js +121 -0
  18. package/dist/tools/kubectl-get.d.ts +72 -0
  19. package/dist/tools/kubectl-get.js +251 -0
  20. package/dist/tools/kubectl-list.d.ts +61 -0
  21. package/dist/tools/kubectl-list.js +189 -0
  22. package/dist/tools/{get_logs.d.ts → kubectl-logs.d.ts} +35 -19
  23. package/dist/tools/kubectl-logs.js +312 -0
  24. package/dist/tools/kubectl-patch.d.ts +57 -0
  25. package/dist/tools/kubectl-patch.js +128 -0
  26. package/dist/tools/kubectl-rollout.d.ts +67 -0
  27. package/dist/tools/kubectl-rollout.js +115 -0
  28. package/dist/tools/{scale_deployment.d.ts → kubectl-scale.d.ts} +13 -3
  29. package/dist/tools/kubectl-scale.js +73 -0
  30. package/package.json +1 -1
  31. package/dist/tools/create_configmap.d.ts +0 -33
  32. package/dist/tools/create_configmap.js +0 -66
  33. package/dist/tools/create_cronjob.d.ts +0 -47
  34. package/dist/tools/create_cronjob.js +0 -93
  35. package/dist/tools/create_deployment.d.ts +0 -135
  36. package/dist/tools/create_deployment.js +0 -162
  37. package/dist/tools/create_namespace.d.ts +0 -22
  38. package/dist/tools/create_namespace.js +0 -48
  39. package/dist/tools/create_pod.d.ts +0 -130
  40. package/dist/tools/create_pod.js +0 -153
  41. package/dist/tools/create_service.d.ts +0 -74
  42. package/dist/tools/create_service.js +0 -102
  43. package/dist/tools/delete_configmap.d.ts +0 -26
  44. package/dist/tools/delete_configmap.js +0 -49
  45. package/dist/tools/delete_cronjob.d.ts +0 -26
  46. package/dist/tools/delete_cronjob.js +0 -48
  47. package/dist/tools/delete_deployment.d.ts +0 -31
  48. package/dist/tools/delete_deployment.js +0 -47
  49. package/dist/tools/delete_namespace.d.ts +0 -27
  50. package/dist/tools/delete_namespace.js +0 -44
  51. package/dist/tools/delete_pod.d.ts +0 -31
  52. package/dist/tools/delete_pod.js +0 -45
  53. package/dist/tools/delete_service.d.ts +0 -32
  54. package/dist/tools/delete_service.js +0 -46
  55. package/dist/tools/describe_cronjob.d.ts +0 -27
  56. package/dist/tools/describe_cronjob.js +0 -83
  57. package/dist/tools/describe_deployment.d.ts +0 -26
  58. package/dist/tools/describe_deployment.js +0 -40
  59. package/dist/tools/describe_node.d.ts +0 -22
  60. package/dist/tools/describe_node.js +0 -84
  61. package/dist/tools/describe_pod.d.ts +0 -33
  62. package/dist/tools/describe_pod.js +0 -81
  63. package/dist/tools/describe_service.d.ts +0 -34
  64. package/dist/tools/describe_service.js +0 -85
  65. package/dist/tools/get_configmap.d.ts +0 -27
  66. package/dist/tools/get_configmap.js +0 -48
  67. package/dist/tools/get_current_context.d.ts +0 -23
  68. package/dist/tools/get_current_context.js +0 -55
  69. package/dist/tools/get_events.d.ts +0 -28
  70. package/dist/tools/get_events.js +0 -66
  71. package/dist/tools/get_job_logs.d.ts +0 -40
  72. package/dist/tools/get_job_logs.js +0 -104
  73. package/dist/tools/get_logs.js +0 -150
  74. package/dist/tools/list_contexts.d.ts +0 -23
  75. package/dist/tools/list_contexts.js +0 -39
  76. package/dist/tools/list_cronjobs.d.ts +0 -23
  77. package/dist/tools/list_cronjobs.js +0 -35
  78. package/dist/tools/list_deployments.d.ts +0 -23
  79. package/dist/tools/list_deployments.js +0 -30
  80. package/dist/tools/list_jobs.d.ts +0 -29
  81. package/dist/tools/list_jobs.js +0 -77
  82. package/dist/tools/list_nodes.d.ts +0 -15
  83. package/dist/tools/list_nodes.js +0 -21
  84. package/dist/tools/list_pods.d.ts +0 -23
  85. package/dist/tools/list_pods.js +0 -29
  86. package/dist/tools/list_services.d.ts +0 -23
  87. package/dist/tools/list_services.js +0 -31
  88. package/dist/tools/scale_deployment.js +0 -50
  89. package/dist/tools/set_current_context.d.ts +0 -23
  90. package/dist/tools/set_current_context.js +0 -35
  91. package/dist/tools/update_configmap.d.ts +0 -33
  92. package/dist/tools/update_configmap.js +0 -71
  93. package/dist/tools/update_deployment.d.ts +0 -113
  94. package/dist/tools/update_deployment.js +0 -155
  95. package/dist/tools/update_service.d.ts +0 -72
  96. package/dist/tools/update_service.js +0 -125
@@ -1,135 +0,0 @@
1
- import { KubernetesManager } from "../types.js";
2
- import { CustomContainerConfigType } from "../config/container-templates.js";
3
- export declare const createDeploymentSchema: {
4
- readonly name: "create_deployment";
5
- readonly description: "Create a new Kubernetes deployment";
6
- readonly inputSchema: {
7
- readonly type: "object";
8
- readonly properties: {
9
- readonly name: {
10
- readonly type: "string";
11
- };
12
- readonly namespace: {
13
- readonly type: "string";
14
- };
15
- readonly template: {
16
- readonly type: "string";
17
- readonly enum: ["ubuntu", "nginx", "busybox", "alpine", "custom"];
18
- };
19
- readonly replicas: {
20
- readonly type: "number";
21
- readonly default: 1;
22
- };
23
- readonly ports: {
24
- readonly type: "array";
25
- readonly items: {
26
- readonly type: "number";
27
- };
28
- readonly optional: true;
29
- };
30
- readonly customConfig: {
31
- readonly type: "object";
32
- readonly optional: true;
33
- readonly properties: {
34
- readonly image: {
35
- readonly type: "string";
36
- };
37
- readonly command: {
38
- readonly type: "array";
39
- readonly items: {
40
- readonly type: "string";
41
- };
42
- };
43
- readonly args: {
44
- readonly type: "array";
45
- readonly items: {
46
- readonly type: "string";
47
- };
48
- };
49
- readonly ports: {
50
- readonly type: "array";
51
- readonly items: {
52
- readonly type: "object";
53
- readonly properties: {
54
- readonly containerPort: {
55
- readonly type: "number";
56
- };
57
- readonly name: {
58
- readonly type: "string";
59
- };
60
- readonly protocol: {
61
- readonly type: "string";
62
- };
63
- };
64
- };
65
- };
66
- readonly resources: {
67
- readonly type: "object";
68
- readonly properties: {
69
- readonly limits: {
70
- readonly type: "object";
71
- readonly additionalProperties: {
72
- readonly type: "string";
73
- };
74
- };
75
- readonly requests: {
76
- readonly type: "object";
77
- readonly additionalProperties: {
78
- readonly type: "string";
79
- };
80
- };
81
- };
82
- };
83
- readonly env: {
84
- readonly type: "array";
85
- readonly items: {
86
- readonly type: "object";
87
- readonly properties: {
88
- readonly name: {
89
- readonly type: "string";
90
- };
91
- readonly value: {
92
- readonly type: "string";
93
- };
94
- readonly valueFrom: {
95
- readonly type: "object";
96
- };
97
- };
98
- };
99
- };
100
- readonly volumeMounts: {
101
- readonly type: "array";
102
- readonly items: {
103
- readonly type: "object";
104
- readonly properties: {
105
- readonly name: {
106
- readonly type: "string";
107
- };
108
- readonly mountPath: {
109
- readonly type: "string";
110
- };
111
- readonly readOnly: {
112
- readonly type: "boolean";
113
- };
114
- };
115
- };
116
- };
117
- };
118
- };
119
- };
120
- readonly required: readonly ["name", "namespace", "template"];
121
- };
122
- };
123
- export declare function createDeployment(k8sManager: KubernetesManager, input: {
124
- name: string;
125
- namespace: string;
126
- template: string;
127
- replicas?: number;
128
- ports?: number[];
129
- customConfig?: CustomContainerConfigType;
130
- }): Promise<{
131
- content: {
132
- type: string;
133
- text: string;
134
- }[];
135
- }>;
@@ -1,162 +0,0 @@
1
- import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
2
- import { ContainerTemplate, containerTemplates, CustomContainerConfig, } from "../config/container-templates.js";
3
- export const createDeploymentSchema = {
4
- name: "create_deployment",
5
- description: "Create a new Kubernetes deployment",
6
- inputSchema: {
7
- type: "object",
8
- properties: {
9
- name: { type: "string" },
10
- namespace: { type: "string" },
11
- template: {
12
- type: "string",
13
- enum: ContainerTemplate.options,
14
- },
15
- replicas: { type: "number", default: 1 },
16
- ports: {
17
- type: "array",
18
- items: { type: "number" },
19
- optional: true,
20
- },
21
- customConfig: {
22
- type: "object",
23
- optional: true,
24
- properties: {
25
- image: { type: "string" },
26
- command: { type: "array", items: { type: "string" } },
27
- args: { type: "array", items: { type: "string" } },
28
- ports: {
29
- type: "array",
30
- items: {
31
- type: "object",
32
- properties: {
33
- containerPort: { type: "number" },
34
- name: { type: "string" },
35
- protocol: { type: "string" },
36
- },
37
- },
38
- },
39
- resources: {
40
- type: "object",
41
- properties: {
42
- limits: {
43
- type: "object",
44
- additionalProperties: { type: "string" },
45
- },
46
- requests: {
47
- type: "object",
48
- additionalProperties: { type: "string" },
49
- },
50
- },
51
- },
52
- env: {
53
- type: "array",
54
- items: {
55
- type: "object",
56
- properties: {
57
- name: { type: "string" },
58
- value: { type: "string" },
59
- valueFrom: { type: "object" },
60
- },
61
- },
62
- },
63
- volumeMounts: {
64
- type: "array",
65
- items: {
66
- type: "object",
67
- properties: {
68
- name: { type: "string" },
69
- mountPath: { type: "string" },
70
- readOnly: { type: "boolean" },
71
- },
72
- },
73
- },
74
- },
75
- },
76
- },
77
- required: ["name", "namespace", "template"],
78
- },
79
- };
80
- export async function createDeployment(k8sManager, input) {
81
- const templateConfig = containerTemplates[input.template];
82
- // If using custom template, validate and merge custom config
83
- let containerConfig;
84
- if (input.template === "custom") {
85
- if (!input.customConfig) {
86
- throw new McpError(ErrorCode.InvalidRequest, "Custom container configuration is required when using 'custom' template");
87
- }
88
- // Validate custom config against schema
89
- const validatedConfig = CustomContainerConfig.parse(input.customConfig);
90
- // Merge base template with custom config
91
- containerConfig = {
92
- ...templateConfig,
93
- image: validatedConfig.image,
94
- command: validatedConfig.command,
95
- args: validatedConfig.args,
96
- ports: validatedConfig.ports,
97
- resources: validatedConfig.resources,
98
- env: validatedConfig.env,
99
- volumeMounts: validatedConfig.volumeMounts,
100
- };
101
- }
102
- else {
103
- containerConfig = {
104
- ...templateConfig,
105
- ports: input.ports?.map((port) => ({ containerPort: port })) ||
106
- templateConfig.ports,
107
- };
108
- }
109
- const deployment = {
110
- apiVersion: "apps/v1",
111
- kind: "Deployment",
112
- metadata: {
113
- name: input.name,
114
- namespace: input.namespace,
115
- labels: {
116
- "mcp-managed": "true",
117
- app: input.name,
118
- },
119
- },
120
- spec: {
121
- replicas: input.replicas || 1,
122
- selector: {
123
- matchLabels: {
124
- app: input.name,
125
- },
126
- },
127
- template: {
128
- metadata: {
129
- labels: {
130
- app: input.name,
131
- },
132
- },
133
- spec: {
134
- containers: [containerConfig],
135
- },
136
- },
137
- },
138
- };
139
- const response = await k8sManager
140
- .getAppsApi()
141
- .createNamespacedDeployment(input.namespace, deployment)
142
- .catch((error) => {
143
- console.error("Deployment creation error:", {
144
- status: error.response?.statusCode,
145
- message: error.response?.body?.message || error.message,
146
- details: error.response?.body,
147
- });
148
- throw error;
149
- });
150
- k8sManager.trackResource("Deployment", input.name, input.namespace);
151
- return {
152
- content: [
153
- {
154
- type: "text",
155
- text: JSON.stringify({
156
- deploymentName: response.body.metadata.name,
157
- status: "created",
158
- }, null, 2),
159
- },
160
- ],
161
- };
162
- }
@@ -1,22 +0,0 @@
1
- import { KubernetesManager } from "../types.js";
2
- export declare const createNamespaceSchema: {
3
- readonly name: "create_namespace";
4
- readonly description: "Create a new Kubernetes namespace";
5
- readonly inputSchema: {
6
- readonly type: "object";
7
- readonly properties: {
8
- readonly name: {
9
- readonly type: "string";
10
- };
11
- };
12
- readonly required: readonly ["name"];
13
- };
14
- };
15
- export declare function createNamespace(k8sManager: KubernetesManager, input: {
16
- name: string;
17
- }): Promise<{
18
- content: {
19
- type: string;
20
- text: string;
21
- }[];
22
- }>;
@@ -1,48 +0,0 @@
1
- export const createNamespaceSchema = {
2
- name: "create_namespace",
3
- description: "Create a new Kubernetes namespace",
4
- inputSchema: {
5
- type: "object",
6
- properties: {
7
- name: { type: "string" },
8
- },
9
- required: ["name"],
10
- },
11
- };
12
- export async function createNamespace(k8sManager, input) {
13
- const namespace = {
14
- apiVersion: "v1",
15
- kind: "Namespace",
16
- metadata: {
17
- name: input.name,
18
- labels: {
19
- "mcp-managed": "true",
20
- app: input.name,
21
- },
22
- },
23
- spec: {},
24
- };
25
- try {
26
- const response = await k8sManager.getCoreApi().createNamespace(namespace);
27
- k8sManager.trackResource("Namespace", input.name, input.name);
28
- return {
29
- content: [
30
- {
31
- type: "text",
32
- text: JSON.stringify({
33
- namespaceName: response.body.metadata.name,
34
- status: "created",
35
- }, null, 2),
36
- },
37
- ],
38
- };
39
- }
40
- catch (error) {
41
- console.error("Namespace creation error:", {
42
- status: error.response?.statusCode,
43
- message: error.response?.body?.message || error.message,
44
- details: error.response?.body,
45
- });
46
- throw error;
47
- }
48
- }
@@ -1,130 +0,0 @@
1
- import { KubernetesManager } from "../types.js";
2
- import { CustomContainerConfigType } from "../config/container-templates.js";
3
- export declare const createPodSchema: {
4
- readonly name: "create_pod";
5
- readonly description: "Create a new Kubernetes pod";
6
- readonly inputSchema: {
7
- readonly type: "object";
8
- readonly properties: {
9
- readonly name: {
10
- readonly type: "string";
11
- };
12
- readonly namespace: {
13
- readonly type: "string";
14
- };
15
- readonly template: {
16
- readonly type: "string";
17
- readonly enum: ["ubuntu", "nginx", "busybox", "alpine", "custom"];
18
- };
19
- readonly command: {
20
- readonly type: "array";
21
- readonly items: {
22
- readonly type: "string";
23
- };
24
- readonly optional: true;
25
- };
26
- readonly customConfig: {
27
- readonly type: "object";
28
- readonly optional: true;
29
- readonly properties: {
30
- readonly image: {
31
- readonly type: "string";
32
- };
33
- readonly command: {
34
- readonly type: "array";
35
- readonly items: {
36
- readonly type: "string";
37
- };
38
- };
39
- readonly args: {
40
- readonly type: "array";
41
- readonly items: {
42
- readonly type: "string";
43
- };
44
- };
45
- readonly ports: {
46
- readonly type: "array";
47
- readonly items: {
48
- readonly type: "object";
49
- readonly properties: {
50
- readonly containerPort: {
51
- readonly type: "number";
52
- };
53
- readonly name: {
54
- readonly type: "string";
55
- };
56
- readonly protocol: {
57
- readonly type: "string";
58
- };
59
- };
60
- };
61
- };
62
- readonly resources: {
63
- readonly type: "object";
64
- readonly properties: {
65
- readonly limits: {
66
- readonly type: "object";
67
- readonly additionalProperties: {
68
- readonly type: "string";
69
- };
70
- };
71
- readonly requests: {
72
- readonly type: "object";
73
- readonly additionalProperties: {
74
- readonly type: "string";
75
- };
76
- };
77
- };
78
- };
79
- readonly env: {
80
- readonly type: "array";
81
- readonly items: {
82
- readonly type: "object";
83
- readonly properties: {
84
- readonly name: {
85
- readonly type: "string";
86
- };
87
- readonly value: {
88
- readonly type: "string";
89
- };
90
- readonly valueFrom: {
91
- readonly type: "object";
92
- };
93
- };
94
- };
95
- };
96
- readonly volumeMounts: {
97
- readonly type: "array";
98
- readonly items: {
99
- readonly type: "object";
100
- readonly properties: {
101
- readonly name: {
102
- readonly type: "string";
103
- };
104
- readonly mountPath: {
105
- readonly type: "string";
106
- };
107
- readonly readOnly: {
108
- readonly type: "boolean";
109
- };
110
- };
111
- };
112
- };
113
- };
114
- };
115
- };
116
- readonly required: readonly ["name", "namespace", "template"];
117
- };
118
- };
119
- export declare function createPod(k8sManager: KubernetesManager, input: {
120
- name: string;
121
- namespace: string;
122
- template: string;
123
- command?: string[];
124
- customConfig?: CustomContainerConfigType;
125
- }): Promise<{
126
- content: {
127
- type: string;
128
- text: string;
129
- }[];
130
- }>;
@@ -1,153 +0,0 @@
1
- import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
2
- import { ContainerTemplate, containerTemplates, CustomContainerConfig, } from "../config/container-templates.js";
3
- export const createPodSchema = {
4
- name: "create_pod",
5
- description: "Create a new Kubernetes pod",
6
- inputSchema: {
7
- type: "object",
8
- properties: {
9
- name: { type: "string" },
10
- namespace: { type: "string" },
11
- template: {
12
- type: "string",
13
- enum: ContainerTemplate.options,
14
- },
15
- command: {
16
- type: "array",
17
- items: { type: "string" },
18
- optional: true,
19
- },
20
- customConfig: {
21
- type: "object",
22
- optional: true,
23
- properties: {
24
- image: { type: "string" },
25
- command: { type: "array", items: { type: "string" } },
26
- args: { type: "array", items: { type: "string" } },
27
- ports: {
28
- type: "array",
29
- items: {
30
- type: "object",
31
- properties: {
32
- containerPort: { type: "number" },
33
- name: { type: "string" },
34
- protocol: { type: "string" },
35
- },
36
- },
37
- },
38
- resources: {
39
- type: "object",
40
- properties: {
41
- limits: {
42
- type: "object",
43
- additionalProperties: { type: "string" },
44
- },
45
- requests: {
46
- type: "object",
47
- additionalProperties: { type: "string" },
48
- },
49
- },
50
- },
51
- env: {
52
- type: "array",
53
- items: {
54
- type: "object",
55
- properties: {
56
- name: { type: "string" },
57
- value: { type: "string" },
58
- valueFrom: { type: "object" },
59
- },
60
- },
61
- },
62
- volumeMounts: {
63
- type: "array",
64
- items: {
65
- type: "object",
66
- properties: {
67
- name: { type: "string" },
68
- mountPath: { type: "string" },
69
- readOnly: { type: "boolean" },
70
- },
71
- },
72
- },
73
- },
74
- },
75
- },
76
- required: ["name", "namespace", "template"],
77
- },
78
- };
79
- export async function createPod(k8sManager, input) {
80
- const templateConfig = containerTemplates[input.template];
81
- // If using custom template, validate and merge custom config
82
- let containerConfig;
83
- if (input.template === "custom") {
84
- if (!input.customConfig) {
85
- throw new McpError(ErrorCode.InvalidRequest, "Custom container configuration is required when using 'custom' template");
86
- }
87
- // Validate custom config against schema
88
- const validatedConfig = CustomContainerConfig.parse(input.customConfig);
89
- // Create a new container config with all fields explicitly set
90
- containerConfig = {
91
- name: "main",
92
- image: validatedConfig.image,
93
- command: validatedConfig.command,
94
- args: validatedConfig.args,
95
- ports: validatedConfig.ports || [],
96
- resources: validatedConfig.resources || {
97
- limits: {},
98
- requests: {},
99
- },
100
- env: validatedConfig.env || [],
101
- volumeMounts: validatedConfig.volumeMounts || [],
102
- livenessProbe: templateConfig.livenessProbe,
103
- readinessProbe: templateConfig.readinessProbe,
104
- };
105
- }
106
- else {
107
- containerConfig = {
108
- ...templateConfig,
109
- ...(input.command && {
110
- command: input.command,
111
- args: undefined, // Clear default args when command is overridden
112
- }),
113
- };
114
- }
115
- const pod = {
116
- apiVersion: "v1",
117
- kind: "Pod",
118
- metadata: {
119
- name: input.name,
120
- namespace: input.namespace,
121
- labels: {
122
- "mcp-managed": "true",
123
- app: input.name,
124
- },
125
- },
126
- spec: {
127
- containers: [containerConfig],
128
- },
129
- };
130
- const response = await k8sManager
131
- .getCoreApi()
132
- .createNamespacedPod(input.namespace, pod)
133
- .catch((error) => {
134
- console.error("Pod creation error:", {
135
- status: error.response?.statusCode,
136
- message: error.response?.body?.message || error.message,
137
- details: error.response?.body,
138
- });
139
- throw error;
140
- });
141
- k8sManager.trackResource("Pod", input.name, input.namespace);
142
- return {
143
- content: [
144
- {
145
- type: "text",
146
- text: JSON.stringify({
147
- podName: response.body.metadata.name,
148
- status: "created",
149
- }, null, 2),
150
- },
151
- ],
152
- };
153
- }