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,39 @@
1
+ import { z } from "zod";
2
+ export declare const HelmResponseSchema: z.ZodObject<{
3
+ content: z.ZodArray<z.ZodObject<{
4
+ type: z.ZodLiteral<"text">;
5
+ text: z.ZodString;
6
+ }, "strip", z.ZodTypeAny, {
7
+ type: "text";
8
+ text: string;
9
+ }, {
10
+ type: "text";
11
+ text: string;
12
+ }>, "many">;
13
+ }, "strip", z.ZodTypeAny, {
14
+ content: {
15
+ type: "text";
16
+ text: string;
17
+ }[];
18
+ }, {
19
+ content: {
20
+ type: "text";
21
+ text: string;
22
+ }[];
23
+ }>;
24
+ export declare const HelmValuesSchema: z.ZodRecord<z.ZodString, z.ZodAny>;
25
+ export interface HelmOperation {
26
+ name: string;
27
+ namespace: string;
28
+ }
29
+ export interface HelmInstallOperation extends HelmOperation {
30
+ chart: string;
31
+ repo: string;
32
+ values?: Record<string, any>;
33
+ }
34
+ export interface HelmUpgradeOperation extends HelmInstallOperation {
35
+ }
36
+ export type HelmResponse = {
37
+ status: "installed" | "upgraded" | "uninstalled";
38
+ message?: string;
39
+ };
@@ -0,0 +1,8 @@
1
+ import { z } from "zod";
2
+ export const HelmResponseSchema = z.object({
3
+ content: z.array(z.object({
4
+ type: z.literal("text"),
5
+ text: z.string(),
6
+ })),
7
+ });
8
+ export const HelmValuesSchema = z.record(z.any());
@@ -0,0 +1,94 @@
1
+ import { z } from "zod";
2
+ export declare const ResourceSchema: z.ZodObject<{
3
+ uri: z.ZodString;
4
+ name: z.ZodString;
5
+ description: z.ZodString;
6
+ }, "strip", z.ZodTypeAny, {
7
+ uri: string;
8
+ name: string;
9
+ description: string;
10
+ }, {
11
+ uri: string;
12
+ name: string;
13
+ description: string;
14
+ }>;
15
+ export declare const ListResourcesResponseSchema: z.ZodObject<{
16
+ resources: z.ZodArray<z.ZodObject<{
17
+ uri: z.ZodString;
18
+ name: z.ZodString;
19
+ description: z.ZodString;
20
+ }, "strip", z.ZodTypeAny, {
21
+ uri: string;
22
+ name: string;
23
+ description: string;
24
+ }, {
25
+ uri: string;
26
+ name: string;
27
+ description: string;
28
+ }>, "many">;
29
+ }, "strip", z.ZodTypeAny, {
30
+ resources: {
31
+ uri: string;
32
+ name: string;
33
+ description: string;
34
+ }[];
35
+ }, {
36
+ resources: {
37
+ uri: string;
38
+ name: string;
39
+ description: string;
40
+ }[];
41
+ }>;
42
+ export declare const ReadResourceResponseSchema: z.ZodObject<{
43
+ contents: z.ZodArray<z.ZodObject<{
44
+ uri: z.ZodString;
45
+ mimeType: z.ZodString;
46
+ text: z.ZodString;
47
+ }, "strip", z.ZodTypeAny, {
48
+ text: string;
49
+ uri: string;
50
+ mimeType: string;
51
+ }, {
52
+ text: string;
53
+ uri: string;
54
+ mimeType: string;
55
+ }>, "many">;
56
+ }, "strip", z.ZodTypeAny, {
57
+ contents: {
58
+ text: string;
59
+ uri: string;
60
+ mimeType: string;
61
+ }[];
62
+ }, {
63
+ contents: {
64
+ text: string;
65
+ uri: string;
66
+ mimeType: string;
67
+ }[];
68
+ }>;
69
+ export type K8sResource = z.infer<typeof ResourceSchema>;
70
+ export interface ResourceTracker {
71
+ kind: string;
72
+ name: string;
73
+ namespace: string;
74
+ createdAt: Date;
75
+ }
76
+ export interface PortForwardTracker {
77
+ id: string;
78
+ server: {
79
+ stop: () => Promise<void>;
80
+ };
81
+ resourceType: string;
82
+ name: string;
83
+ namespace: string;
84
+ ports: {
85
+ local: number;
86
+ remote: number;
87
+ }[];
88
+ }
89
+ export interface WatchTracker {
90
+ id: string;
91
+ abort: AbortController;
92
+ resourceType: string;
93
+ namespace: string;
94
+ }
@@ -0,0 +1,17 @@
1
+ import { z } from "zod";
2
+ // Resource schemas
3
+ export const ResourceSchema = z.object({
4
+ uri: z.string(),
5
+ name: z.string(),
6
+ description: z.string(),
7
+ });
8
+ export const ListResourcesResponseSchema = z.object({
9
+ resources: z.array(ResourceSchema),
10
+ });
11
+ export const ReadResourceResponseSchema = z.object({
12
+ contents: z.array(z.object({
13
+ uri: z.string(),
14
+ mimeType: z.string(),
15
+ text: z.string(),
16
+ })),
17
+ });
@@ -0,0 +1,221 @@
1
+ import { z } from "zod";
2
+ export declare const CreatePodResponseSchema: z.ZodObject<{
3
+ content: z.ZodArray<z.ZodObject<{
4
+ type: z.ZodLiteral<"text">;
5
+ text: z.ZodString;
6
+ }, "strip", z.ZodTypeAny, {
7
+ type: "text";
8
+ text: string;
9
+ }, {
10
+ type: "text";
11
+ text: string;
12
+ }>, "many">;
13
+ }, "strip", z.ZodTypeAny, {
14
+ content: {
15
+ type: "text";
16
+ text: string;
17
+ }[];
18
+ }, {
19
+ content: {
20
+ type: "text";
21
+ text: string;
22
+ }[];
23
+ }>;
24
+ export declare const CreateDeploymentResponseSchema: 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
+ }>;
46
+ export declare const DeletePodResponseSchema: z.ZodObject<{
47
+ content: z.ZodArray<z.ZodObject<{
48
+ type: z.ZodLiteral<"text">;
49
+ text: z.ZodString;
50
+ }, "strip", z.ZodTypeAny, {
51
+ type: "text";
52
+ text: string;
53
+ }, {
54
+ type: "text";
55
+ text: string;
56
+ }>, "many">;
57
+ }, "strip", z.ZodTypeAny, {
58
+ content: {
59
+ type: "text";
60
+ text: string;
61
+ }[];
62
+ }, {
63
+ content: {
64
+ type: "text";
65
+ text: string;
66
+ }[];
67
+ }>;
68
+ export declare const CleanupResponseSchema: z.ZodObject<{
69
+ content: z.ZodArray<z.ZodObject<{
70
+ type: z.ZodLiteral<"text">;
71
+ text: z.ZodString;
72
+ }, "strip", z.ZodTypeAny, {
73
+ type: "text";
74
+ text: string;
75
+ }, {
76
+ type: "text";
77
+ text: string;
78
+ }>, "many">;
79
+ }, "strip", z.ZodTypeAny, {
80
+ content: {
81
+ type: "text";
82
+ text: string;
83
+ }[];
84
+ }, {
85
+ content: {
86
+ type: "text";
87
+ text: string;
88
+ }[];
89
+ }>;
90
+ export declare const ListPodsResponseSchema: z.ZodObject<{
91
+ content: z.ZodArray<z.ZodObject<{
92
+ type: z.ZodLiteral<"text">;
93
+ text: z.ZodString;
94
+ }, "strip", z.ZodTypeAny, {
95
+ type: "text";
96
+ text: string;
97
+ }, {
98
+ type: "text";
99
+ text: string;
100
+ }>, "many">;
101
+ }, "strip", z.ZodTypeAny, {
102
+ content: {
103
+ type: "text";
104
+ text: string;
105
+ }[];
106
+ }, {
107
+ content: {
108
+ type: "text";
109
+ text: string;
110
+ }[];
111
+ }>;
112
+ export declare const ListDeploymentsResponseSchema: z.ZodObject<{
113
+ content: z.ZodArray<z.ZodObject<{
114
+ type: z.ZodLiteral<"text">;
115
+ text: z.ZodString;
116
+ }, "strip", z.ZodTypeAny, {
117
+ type: "text";
118
+ text: string;
119
+ }, {
120
+ type: "text";
121
+ text: string;
122
+ }>, "many">;
123
+ }, "strip", z.ZodTypeAny, {
124
+ content: {
125
+ type: "text";
126
+ text: string;
127
+ }[];
128
+ }, {
129
+ content: {
130
+ type: "text";
131
+ text: string;
132
+ }[];
133
+ }>;
134
+ export declare const ListServicesResponseSchema: z.ZodObject<{
135
+ content: z.ZodArray<z.ZodObject<{
136
+ type: z.ZodLiteral<"text">;
137
+ text: z.ZodString;
138
+ }, "strip", z.ZodTypeAny, {
139
+ type: "text";
140
+ text: string;
141
+ }, {
142
+ type: "text";
143
+ text: string;
144
+ }>, "many">;
145
+ }, "strip", z.ZodTypeAny, {
146
+ content: {
147
+ type: "text";
148
+ text: string;
149
+ }[];
150
+ }, {
151
+ content: {
152
+ type: "text";
153
+ text: string;
154
+ }[];
155
+ }>;
156
+ export declare const ListNamespacesResponseSchema: z.ZodObject<{
157
+ content: z.ZodArray<z.ZodObject<{
158
+ type: z.ZodLiteral<"text">;
159
+ text: z.ZodString;
160
+ }, "strip", z.ZodTypeAny, {
161
+ type: "text";
162
+ text: string;
163
+ }, {
164
+ type: "text";
165
+ text: string;
166
+ }>, "many">;
167
+ }, "strip", z.ZodTypeAny, {
168
+ content: {
169
+ type: "text";
170
+ text: string;
171
+ }[];
172
+ }, {
173
+ content: {
174
+ type: "text";
175
+ text: string;
176
+ }[];
177
+ }>;
178
+ export declare const ListNodesResponseSchema: z.ZodObject<{
179
+ content: z.ZodArray<z.ZodObject<{
180
+ type: z.ZodLiteral<"text">;
181
+ text: z.ZodString;
182
+ }, "strip", z.ZodTypeAny, {
183
+ type: "text";
184
+ text: string;
185
+ }, {
186
+ type: "text";
187
+ text: string;
188
+ }>, "many">;
189
+ }, "strip", z.ZodTypeAny, {
190
+ content: {
191
+ type: "text";
192
+ text: string;
193
+ }[];
194
+ }, {
195
+ content: {
196
+ type: "text";
197
+ text: string;
198
+ }[];
199
+ }>;
200
+ export declare const GetLogsResponseSchema: z.ZodObject<{
201
+ content: z.ZodArray<z.ZodObject<{
202
+ type: z.ZodLiteral<"text">;
203
+ text: z.ZodString;
204
+ }, "strip", z.ZodTypeAny, {
205
+ type: "text";
206
+ text: string;
207
+ }, {
208
+ type: "text";
209
+ text: string;
210
+ }>, "many">;
211
+ }, "strip", z.ZodTypeAny, {
212
+ content: {
213
+ type: "text";
214
+ text: string;
215
+ }[];
216
+ }, {
217
+ content: {
218
+ type: "text";
219
+ text: string;
220
+ }[];
221
+ }>;
@@ -0,0 +1,36 @@
1
+ import { z } from "zod";
2
+ // Common response structure for tool operations
3
+ const ToolResponseContent = z.object({
4
+ type: z.literal("text"),
5
+ text: z.string(),
6
+ });
7
+ export const CreatePodResponseSchema = z.object({
8
+ content: z.array(ToolResponseContent),
9
+ });
10
+ export const CreateDeploymentResponseSchema = z.object({
11
+ content: z.array(ToolResponseContent),
12
+ });
13
+ export const DeletePodResponseSchema = z.object({
14
+ content: z.array(ToolResponseContent),
15
+ });
16
+ export const CleanupResponseSchema = z.object({
17
+ content: z.array(ToolResponseContent),
18
+ });
19
+ export const ListPodsResponseSchema = z.object({
20
+ content: z.array(ToolResponseContent),
21
+ });
22
+ export const ListDeploymentsResponseSchema = z.object({
23
+ content: z.array(ToolResponseContent),
24
+ });
25
+ export const ListServicesResponseSchema = z.object({
26
+ content: z.array(ToolResponseContent),
27
+ });
28
+ export const ListNamespacesResponseSchema = z.object({
29
+ content: z.array(ToolResponseContent),
30
+ });
31
+ export const ListNodesResponseSchema = z.object({
32
+ content: z.array(ToolResponseContent),
33
+ });
34
+ export const GetLogsResponseSchema = z.object({
35
+ content: z.array(ToolResponseContent),
36
+ });
@@ -0,0 +1,42 @@
1
+ import { z } from "zod";
2
+ export declare const ToolSchema: z.ZodObject<{
3
+ name: z.ZodString;
4
+ description: z.ZodString;
5
+ inputSchema: z.ZodRecord<z.ZodString, z.ZodAny>;
6
+ }, "strip", z.ZodTypeAny, {
7
+ name: string;
8
+ description: string;
9
+ inputSchema: Record<string, any>;
10
+ }, {
11
+ name: string;
12
+ description: string;
13
+ inputSchema: Record<string, any>;
14
+ }>;
15
+ export declare const ListToolsResponseSchema: z.ZodObject<{
16
+ tools: z.ZodArray<z.ZodObject<{
17
+ name: z.ZodString;
18
+ description: z.ZodString;
19
+ inputSchema: z.ZodRecord<z.ZodString, z.ZodAny>;
20
+ }, "strip", z.ZodTypeAny, {
21
+ name: string;
22
+ description: string;
23
+ inputSchema: Record<string, any>;
24
+ }, {
25
+ name: string;
26
+ description: string;
27
+ inputSchema: Record<string, any>;
28
+ }>, "many">;
29
+ }, "strip", z.ZodTypeAny, {
30
+ tools: {
31
+ name: string;
32
+ description: string;
33
+ inputSchema: Record<string, any>;
34
+ }[];
35
+ }, {
36
+ tools: {
37
+ name: string;
38
+ description: string;
39
+ inputSchema: Record<string, any>;
40
+ }[];
41
+ }>;
42
+ export type K8sTool = z.infer<typeof ToolSchema>;
@@ -0,0 +1,10 @@
1
+ import { z } from "zod";
2
+ // Tool schemas
3
+ export const ToolSchema = z.object({
4
+ name: z.string(),
5
+ description: z.string(),
6
+ inputSchema: z.record(z.any()),
7
+ });
8
+ export const ListToolsResponseSchema = z.object({
9
+ tools: z.array(ToolSchema),
10
+ });
@@ -0,0 +1,22 @@
1
+ import { KubernetesManager } from "../types.js";
2
+ export declare const getResourceHandlers: (k8sManager: KubernetesManager) => {
3
+ listResources: () => Promise<{
4
+ resources: {
5
+ uri: string;
6
+ name: string;
7
+ mimeType: string;
8
+ description: string;
9
+ }[];
10
+ }>;
11
+ readResource: (request: {
12
+ params: {
13
+ uri: string;
14
+ };
15
+ }) => Promise<{
16
+ contents: {
17
+ uri: string;
18
+ mimeType: string;
19
+ text: string;
20
+ }[];
21
+ }>;
22
+ };
@@ -0,0 +1,112 @@
1
+ import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
2
+ export const getResourceHandlers = (k8sManager) => ({
3
+ listResources: async () => {
4
+ return {
5
+ resources: [
6
+ {
7
+ uri: "k8s://default/pods",
8
+ name: "Kubernetes Pods",
9
+ mimeType: "application/json",
10
+ description: "List of pods in the default namespace",
11
+ },
12
+ {
13
+ uri: "k8s://default/deployments",
14
+ name: "Kubernetes Deployments",
15
+ mimeType: "application/json",
16
+ description: "List of deployments in the default namespace",
17
+ },
18
+ {
19
+ uri: "k8s://default/services",
20
+ name: "Kubernetes Services",
21
+ mimeType: "application/json",
22
+ description: "List of services in the default namespace",
23
+ },
24
+ {
25
+ uri: "k8s://namespaces",
26
+ name: "Kubernetes Namespaces",
27
+ mimeType: "application/json",
28
+ description: "List of all namespaces",
29
+ },
30
+ {
31
+ uri: "k8s://nodes",
32
+ name: "Kubernetes Nodes",
33
+ mimeType: "application/json",
34
+ description: "List of all nodes in the cluster",
35
+ },
36
+ ],
37
+ };
38
+ },
39
+ readResource: async (request) => {
40
+ try {
41
+ const uri = request.params.uri;
42
+ const parts = uri.replace("k8s://", "").split("/");
43
+ const isNamespaces = parts[0] === "namespaces";
44
+ const isNodes = parts[0] === "nodes";
45
+ if ((isNamespaces || isNodes) && parts.length === 1) {
46
+ const fn = isNodes ? "listNode" : "listNamespace";
47
+ const { body } = await k8sManager.getCoreApi()[fn]();
48
+ return {
49
+ contents: [
50
+ {
51
+ uri: request.params.uri,
52
+ mimeType: "application/json",
53
+ text: JSON.stringify(body.items, null, 2),
54
+ },
55
+ ],
56
+ };
57
+ }
58
+ const [namespace, resourceType] = parts;
59
+ switch (resourceType) {
60
+ case "pods": {
61
+ const { body } = await k8sManager
62
+ .getCoreApi()
63
+ .listNamespacedPod(namespace);
64
+ return {
65
+ contents: [
66
+ {
67
+ uri: request.params.uri,
68
+ mimeType: "application/json",
69
+ text: JSON.stringify(body.items, null, 2),
70
+ },
71
+ ],
72
+ };
73
+ }
74
+ case "deployments": {
75
+ const { body } = await k8sManager
76
+ .getAppsApi()
77
+ .listNamespacedDeployment(namespace);
78
+ return {
79
+ contents: [
80
+ {
81
+ uri: request.params.uri,
82
+ mimeType: "application/json",
83
+ text: JSON.stringify(body.items, null, 2),
84
+ },
85
+ ],
86
+ };
87
+ }
88
+ case "services": {
89
+ const { body } = await k8sManager
90
+ .getCoreApi()
91
+ .listNamespacedService(namespace);
92
+ return {
93
+ contents: [
94
+ {
95
+ uri: request.params.uri,
96
+ mimeType: "application/json",
97
+ text: JSON.stringify(body.items, null, 2),
98
+ },
99
+ ],
100
+ };
101
+ }
102
+ default:
103
+ throw new McpError(ErrorCode.InvalidRequest, `Unsupported resource type: ${resourceType}`);
104
+ }
105
+ }
106
+ catch (error) {
107
+ if (error instanceof McpError)
108
+ throw error;
109
+ throw new McpError(ErrorCode.InternalError, `Failed to read resource: ${error}`);
110
+ }
111
+ },
112
+ });
@@ -0,0 +1,39 @@
1
+ import { KubernetesManager } from "../types.js";
2
+ export declare const createPodSchema: {
3
+ readonly name: "create_pod";
4
+ readonly description: "Create a new Kubernetes pod";
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
+ readonly template: {
15
+ readonly type: "string";
16
+ readonly enum: ["ubuntu", "nginx", "busybox", "alpine"];
17
+ };
18
+ readonly command: {
19
+ readonly type: "array";
20
+ readonly items: {
21
+ readonly type: "string";
22
+ };
23
+ readonly optional: true;
24
+ };
25
+ };
26
+ readonly required: readonly ["name", "namespace", "template"];
27
+ };
28
+ };
29
+ export declare function createPod(k8sManager: KubernetesManager, input: {
30
+ name: string;
31
+ namespace: string;
32
+ template: string;
33
+ command?: string[];
34
+ }): Promise<{
35
+ content: {
36
+ type: string;
37
+ text: string;
38
+ }[];
39
+ }>;