mcp-server-kubernetes 0.1.5 → 0.2.3

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 (49) hide show
  1. package/README.md +29 -9
  2. package/dist/config/cleanup-config.d.ts +8 -0
  3. package/dist/config/cleanup-config.js +8 -0
  4. package/dist/config/container-templates.d.ts +5 -0
  5. package/dist/config/container-templates.js +109 -0
  6. package/dist/config/deployment-config.d.ts +31 -0
  7. package/dist/config/deployment-config.js +23 -0
  8. package/dist/config/namespace-config.d.ts +8 -0
  9. package/dist/config/namespace-config.js +8 -0
  10. package/dist/config/server-config.d.ts +8 -0
  11. package/dist/config/server-config.js +8 -0
  12. package/dist/index.js +49 -928
  13. package/dist/models/helm-models.d.ts +39 -0
  14. package/dist/models/helm-models.js +8 -0
  15. package/dist/models/resource-models.d.ts +94 -0
  16. package/dist/models/resource-models.js +17 -0
  17. package/dist/models/response-schemas.d.ts +221 -0
  18. package/dist/models/response-schemas.js +36 -0
  19. package/dist/models/tool-models.d.ts +42 -0
  20. package/dist/models/tool-models.js +10 -0
  21. package/dist/resources/handlers.d.ts +22 -0
  22. package/dist/resources/handlers.js +112 -0
  23. package/dist/tools/create_pod.d.ts +39 -0
  24. package/dist/tools/create_pod.js +71 -0
  25. package/dist/tools/delete_pod.d.ts +31 -0
  26. package/dist/tools/delete_pod.js +45 -0
  27. package/dist/tools/describe_pod.d.ts +33 -0
  28. package/dist/tools/describe_pod.js +81 -0
  29. package/dist/tools/get_logs.d.ts +67 -0
  30. package/dist/tools/get_logs.js +150 -0
  31. package/dist/tools/helm-operations.d.ts +99 -0
  32. package/dist/tools/helm-operations.js +198 -0
  33. package/dist/tools/list_deployments.d.ts +23 -0
  34. package/dist/tools/list_deployments.js +30 -0
  35. package/dist/tools/list_nodes.d.ts +15 -0
  36. package/dist/tools/list_nodes.js +21 -0
  37. package/dist/tools/list_pods.d.ts +23 -0
  38. package/dist/tools/list_pods.js +29 -0
  39. package/dist/tools/list_services.d.ts +23 -0
  40. package/dist/tools/list_services.js +31 -0
  41. package/dist/types.d.ts +4 -433
  42. package/dist/types.js +6 -120
  43. package/dist/utils/kubernetes-manager.d.ts +21 -0
  44. package/dist/utils/kubernetes-manager.js +68 -0
  45. package/package.json +3 -2
  46. package/dist/helm.test.d.ts +0 -1
  47. package/dist/helm.test.js +0 -208
  48. package/dist/unit.test.d.ts +0 -1
  49. package/dist/unit.test.js +0 -293
@@ -0,0 +1,198 @@
1
+ import { execSync } from "child_process";
2
+ import { writeFileSync, unlinkSync } from "fs";
3
+ import yaml from "yaml";
4
+ export const installHelmChartSchema = {
5
+ name: "install_helm_chart",
6
+ description: "Install a Helm chart",
7
+ inputSchema: {
8
+ type: "object",
9
+ properties: {
10
+ name: {
11
+ type: "string",
12
+ description: "Release name",
13
+ },
14
+ chart: {
15
+ type: "string",
16
+ description: "Chart name",
17
+ },
18
+ repo: {
19
+ type: "string",
20
+ description: "Chart repository URL",
21
+ },
22
+ namespace: {
23
+ type: "string",
24
+ description: "Kubernetes namespace",
25
+ },
26
+ values: {
27
+ type: "object",
28
+ description: "Chart values",
29
+ additionalProperties: true,
30
+ },
31
+ },
32
+ required: ["name", "chart", "repo", "namespace"],
33
+ },
34
+ };
35
+ export const upgradeHelmChartSchema = {
36
+ name: "upgrade_helm_chart",
37
+ description: "Upgrade a Helm release",
38
+ inputSchema: {
39
+ type: "object",
40
+ properties: {
41
+ name: {
42
+ type: "string",
43
+ description: "Release name",
44
+ },
45
+ chart: {
46
+ type: "string",
47
+ description: "Chart name",
48
+ },
49
+ repo: {
50
+ type: "string",
51
+ description: "Chart repository URL",
52
+ },
53
+ namespace: {
54
+ type: "string",
55
+ description: "Kubernetes namespace",
56
+ },
57
+ values: {
58
+ type: "object",
59
+ description: "Chart values",
60
+ additionalProperties: true,
61
+ },
62
+ },
63
+ required: ["name", "chart", "repo", "namespace"],
64
+ },
65
+ };
66
+ export const uninstallHelmChartSchema = {
67
+ name: "uninstall_helm_chart",
68
+ description: "Uninstall a Helm release",
69
+ inputSchema: {
70
+ type: "object",
71
+ properties: {
72
+ name: {
73
+ type: "string",
74
+ description: "Release name",
75
+ },
76
+ namespace: {
77
+ type: "string",
78
+ description: "Kubernetes namespace",
79
+ },
80
+ },
81
+ required: ["name", "namespace"],
82
+ },
83
+ };
84
+ const executeHelmCommand = (command) => {
85
+ try {
86
+ return execSync(command, { encoding: "utf8" });
87
+ }
88
+ catch (error) {
89
+ throw new Error(`Helm command failed: ${error.message}`);
90
+ }
91
+ };
92
+ const writeValuesFile = (name, values) => {
93
+ const filename = `${name}-values.yaml`;
94
+ writeFileSync(filename, yaml.stringify(values));
95
+ return filename;
96
+ };
97
+ export async function installHelmChart(params) {
98
+ try {
99
+ // Add helm repository if provided
100
+ if (params.repo) {
101
+ const repoName = params.chart.split("/")[0];
102
+ executeHelmCommand(`helm repo add ${repoName} ${params.repo}`);
103
+ executeHelmCommand("helm repo update");
104
+ }
105
+ let command = `helm install ${params.name} ${params.chart} --namespace ${params.namespace} --create-namespace`;
106
+ // Handle values if provided
107
+ if (params.values) {
108
+ const valuesFile = writeValuesFile(params.name, params.values);
109
+ command += ` -f ${valuesFile}`;
110
+ try {
111
+ executeHelmCommand(command);
112
+ }
113
+ finally {
114
+ // Cleanup values file
115
+ unlinkSync(valuesFile);
116
+ }
117
+ }
118
+ else {
119
+ executeHelmCommand(command);
120
+ }
121
+ const response = {
122
+ status: "installed",
123
+ message: `Successfully installed ${params.name}`,
124
+ };
125
+ return {
126
+ content: [
127
+ {
128
+ type: "text",
129
+ text: JSON.stringify(response, null, 2),
130
+ },
131
+ ],
132
+ };
133
+ }
134
+ catch (error) {
135
+ throw new Error(`Failed to install Helm chart: ${error.message}`);
136
+ }
137
+ }
138
+ export async function upgradeHelmChart(params) {
139
+ try {
140
+ // Add helm repository if provided
141
+ if (params.repo) {
142
+ const repoName = params.chart.split("/")[0];
143
+ executeHelmCommand(`helm repo add ${repoName} ${params.repo}`);
144
+ executeHelmCommand("helm repo update");
145
+ }
146
+ let command = `helm upgrade ${params.name} ${params.chart} --namespace ${params.namespace}`;
147
+ // Handle values if provided
148
+ if (params.values) {
149
+ const valuesFile = writeValuesFile(params.name, params.values);
150
+ command += ` -f ${valuesFile}`;
151
+ try {
152
+ executeHelmCommand(command);
153
+ }
154
+ finally {
155
+ // Cleanup values file
156
+ unlinkSync(valuesFile);
157
+ }
158
+ }
159
+ else {
160
+ executeHelmCommand(command);
161
+ }
162
+ const response = {
163
+ status: "upgraded",
164
+ message: `Successfully upgraded ${params.name}`,
165
+ };
166
+ return {
167
+ content: [
168
+ {
169
+ type: "text",
170
+ text: JSON.stringify(response, null, 2),
171
+ },
172
+ ],
173
+ };
174
+ }
175
+ catch (error) {
176
+ throw new Error(`Failed to upgrade Helm chart: ${error.message}`);
177
+ }
178
+ }
179
+ export async function uninstallHelmChart(params) {
180
+ try {
181
+ executeHelmCommand(`helm uninstall ${params.name} --namespace ${params.namespace}`);
182
+ const response = {
183
+ status: "uninstalled",
184
+ message: `Successfully uninstalled ${params.name}`,
185
+ };
186
+ return {
187
+ content: [
188
+ {
189
+ type: "text",
190
+ text: JSON.stringify(response, null, 2),
191
+ },
192
+ ],
193
+ };
194
+ }
195
+ catch (error) {
196
+ throw new Error(`Failed to uninstall Helm chart: ${error.message}`);
197
+ }
198
+ }
@@ -0,0 +1,23 @@
1
+ import { KubernetesManager } from "../types.js";
2
+ export declare const listDeploymentsSchema: {
3
+ readonly name: "list_deployments";
4
+ readonly description: "List deployments in a namespace";
5
+ readonly inputSchema: {
6
+ readonly type: "object";
7
+ readonly properties: {
8
+ readonly namespace: {
9
+ readonly type: "string";
10
+ readonly default: "default";
11
+ };
12
+ };
13
+ readonly required: readonly ["namespace"];
14
+ };
15
+ };
16
+ export declare function listDeployments(k8sManager: KubernetesManager, input: {
17
+ namespace?: string;
18
+ }): Promise<{
19
+ content: {
20
+ type: string;
21
+ text: string;
22
+ }[];
23
+ }>;
@@ -0,0 +1,30 @@
1
+ export const listDeploymentsSchema = {
2
+ name: "list_deployments",
3
+ description: "List deployments in a namespace",
4
+ inputSchema: {
5
+ type: "object",
6
+ properties: {
7
+ namespace: { type: "string", default: "default" },
8
+ },
9
+ required: ["namespace"],
10
+ },
11
+ };
12
+ export async function listDeployments(k8sManager, input) {
13
+ const namespace = input.namespace || "default";
14
+ const { body } = await k8sManager.getAppsApi().listNamespacedDeployment(namespace);
15
+ const deployments = body.items.map((deployment) => ({
16
+ name: deployment.metadata?.name || "",
17
+ namespace: deployment.metadata?.namespace || "",
18
+ replicas: deployment.spec?.replicas || 0,
19
+ availableReplicas: deployment.status?.availableReplicas || 0,
20
+ createdAt: deployment.metadata?.creationTimestamp,
21
+ }));
22
+ return {
23
+ content: [
24
+ {
25
+ type: "text",
26
+ text: JSON.stringify({ deployments }, null, 2),
27
+ },
28
+ ],
29
+ };
30
+ }
@@ -0,0 +1,15 @@
1
+ import { KubernetesManager } from "../types.js";
2
+ export declare const listNodesSchema: {
3
+ readonly name: "list_nodes";
4
+ readonly description: "List all nodes in the cluster";
5
+ readonly inputSchema: {
6
+ readonly type: "object";
7
+ readonly properties: {};
8
+ };
9
+ };
10
+ export declare function listNodes(k8sManager: KubernetesManager): Promise<{
11
+ content: {
12
+ type: string;
13
+ text: string;
14
+ }[];
15
+ }>;
@@ -0,0 +1,21 @@
1
+ export const listNodesSchema = {
2
+ name: "list_nodes",
3
+ description: "List all nodes in the cluster",
4
+ inputSchema: {
5
+ type: "object",
6
+ properties: {},
7
+ },
8
+ };
9
+ export async function listNodes(k8sManager) {
10
+ const { body } = await k8sManager.getCoreApi().listNode();
11
+ return {
12
+ content: [
13
+ {
14
+ type: "text",
15
+ text: JSON.stringify({
16
+ nodes: body.items,
17
+ }, null, 2),
18
+ },
19
+ ],
20
+ };
21
+ }
@@ -0,0 +1,23 @@
1
+ import { KubernetesManager } from "../types.js";
2
+ export declare const listPodsSchema: {
3
+ readonly name: "list_pods";
4
+ readonly description: "List pods in a namespace";
5
+ readonly inputSchema: {
6
+ readonly type: "object";
7
+ readonly properties: {
8
+ readonly namespace: {
9
+ readonly type: "string";
10
+ readonly default: "default";
11
+ };
12
+ };
13
+ readonly required: readonly ["namespace"];
14
+ };
15
+ };
16
+ export declare function listPods(k8sManager: KubernetesManager, input: {
17
+ namespace?: string;
18
+ }): Promise<{
19
+ content: {
20
+ type: string;
21
+ text: string;
22
+ }[];
23
+ }>;
@@ -0,0 +1,29 @@
1
+ export const listPodsSchema = {
2
+ name: "list_pods",
3
+ description: "List pods in a namespace",
4
+ inputSchema: {
5
+ type: "object",
6
+ properties: {
7
+ namespace: { type: "string", default: "default" },
8
+ },
9
+ required: ["namespace"],
10
+ },
11
+ };
12
+ export async function listPods(k8sManager, input) {
13
+ const namespace = input.namespace || "default";
14
+ const { body } = await k8sManager.getCoreApi().listNamespacedPod(namespace);
15
+ const pods = body.items.map((pod) => ({
16
+ name: pod.metadata?.name || "",
17
+ namespace: pod.metadata?.namespace || "",
18
+ status: pod.status?.phase,
19
+ createdAt: pod.metadata?.creationTimestamp,
20
+ }));
21
+ return {
22
+ content: [
23
+ {
24
+ type: "text",
25
+ text: JSON.stringify({ pods }, null, 2),
26
+ },
27
+ ],
28
+ };
29
+ }
@@ -0,0 +1,23 @@
1
+ import { KubernetesManager } from "../types.js";
2
+ export declare const listServicesSchema: {
3
+ readonly name: "list_services";
4
+ readonly description: "List services in a namespace";
5
+ readonly inputSchema: {
6
+ readonly type: "object";
7
+ readonly properties: {
8
+ readonly namespace: {
9
+ readonly type: "string";
10
+ readonly default: "default";
11
+ };
12
+ };
13
+ readonly required: readonly ["namespace"];
14
+ };
15
+ };
16
+ export declare function listServices(k8sManager: KubernetesManager, input: {
17
+ namespace?: string;
18
+ }): Promise<{
19
+ content: {
20
+ type: string;
21
+ text: string;
22
+ }[];
23
+ }>;
@@ -0,0 +1,31 @@
1
+ export const listServicesSchema = {
2
+ name: "list_services",
3
+ description: "List services in a namespace",
4
+ inputSchema: {
5
+ type: "object",
6
+ properties: {
7
+ namespace: { type: "string", default: "default" },
8
+ },
9
+ required: ["namespace"],
10
+ },
11
+ };
12
+ export async function listServices(k8sManager, input) {
13
+ const namespace = input.namespace || "default";
14
+ const { body } = await k8sManager.getCoreApi().listNamespacedService(namespace);
15
+ const services = body.items.map((service) => ({
16
+ name: service.metadata?.name || "",
17
+ namespace: service.metadata?.namespace || "",
18
+ type: service.spec?.type,
19
+ clusterIP: service.spec?.clusterIP,
20
+ ports: service.spec?.ports || [],
21
+ createdAt: service.metadata?.creationTimestamp,
22
+ }));
23
+ return {
24
+ content: [
25
+ {
26
+ type: "text",
27
+ text: JSON.stringify({ services }, null, 2),
28
+ },
29
+ ],
30
+ };
31
+ }