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.
- package/README.md +46 -22
- package/dist/config/container-templates.d.ts +2 -2
- package/dist/index.d.ts +314 -736
- package/dist/index.js +93 -200
- package/dist/models/resource-models.d.ts +6 -6
- package/dist/tools/kubectl-apply.d.ts +46 -0
- package/dist/tools/kubectl-apply.js +110 -0
- package/dist/tools/kubectl-context.d.ts +49 -0
- package/dist/tools/kubectl-context.js +233 -0
- package/dist/tools/kubectl-create.d.ts +150 -0
- package/dist/tools/kubectl-create.js +321 -0
- package/dist/tools/kubectl-delete.d.ts +77 -0
- package/dist/tools/kubectl-delete.js +177 -0
- package/dist/tools/kubectl-describe.d.ts +47 -0
- package/dist/tools/kubectl-describe.js +96 -0
- package/dist/tools/kubectl-generic.d.ts +71 -0
- package/dist/tools/kubectl-generic.js +121 -0
- package/dist/tools/kubectl-get.d.ts +72 -0
- package/dist/tools/kubectl-get.js +251 -0
- package/dist/tools/kubectl-list.d.ts +61 -0
- package/dist/tools/kubectl-list.js +189 -0
- package/dist/tools/{get_logs.d.ts → kubectl-logs.d.ts} +35 -19
- package/dist/tools/kubectl-logs.js +312 -0
- package/dist/tools/kubectl-patch.d.ts +57 -0
- package/dist/tools/kubectl-patch.js +128 -0
- package/dist/tools/kubectl-rollout.d.ts +67 -0
- package/dist/tools/kubectl-rollout.js +115 -0
- package/dist/tools/{scale_deployment.d.ts → kubectl-scale.d.ts} +13 -3
- package/dist/tools/kubectl-scale.js +73 -0
- package/package.json +1 -1
- package/dist/tools/create_configmap.d.ts +0 -33
- package/dist/tools/create_configmap.js +0 -66
- package/dist/tools/create_cronjob.d.ts +0 -47
- package/dist/tools/create_cronjob.js +0 -93
- package/dist/tools/create_deployment.d.ts +0 -135
- package/dist/tools/create_deployment.js +0 -162
- package/dist/tools/create_namespace.d.ts +0 -22
- package/dist/tools/create_namespace.js +0 -48
- package/dist/tools/create_pod.d.ts +0 -130
- package/dist/tools/create_pod.js +0 -153
- package/dist/tools/create_service.d.ts +0 -74
- package/dist/tools/create_service.js +0 -102
- package/dist/tools/delete_configmap.d.ts +0 -26
- package/dist/tools/delete_configmap.js +0 -49
- package/dist/tools/delete_cronjob.d.ts +0 -26
- package/dist/tools/delete_cronjob.js +0 -48
- package/dist/tools/delete_deployment.d.ts +0 -31
- package/dist/tools/delete_deployment.js +0 -47
- package/dist/tools/delete_namespace.d.ts +0 -27
- package/dist/tools/delete_namespace.js +0 -44
- package/dist/tools/delete_pod.d.ts +0 -31
- package/dist/tools/delete_pod.js +0 -45
- package/dist/tools/delete_service.d.ts +0 -32
- package/dist/tools/delete_service.js +0 -46
- package/dist/tools/describe_cronjob.d.ts +0 -27
- package/dist/tools/describe_cronjob.js +0 -83
- package/dist/tools/describe_deployment.d.ts +0 -26
- package/dist/tools/describe_deployment.js +0 -40
- package/dist/tools/describe_node.d.ts +0 -22
- package/dist/tools/describe_node.js +0 -84
- package/dist/tools/describe_pod.d.ts +0 -33
- package/dist/tools/describe_pod.js +0 -81
- package/dist/tools/describe_service.d.ts +0 -34
- package/dist/tools/describe_service.js +0 -85
- package/dist/tools/get_configmap.d.ts +0 -27
- package/dist/tools/get_configmap.js +0 -48
- package/dist/tools/get_current_context.d.ts +0 -23
- package/dist/tools/get_current_context.js +0 -55
- package/dist/tools/get_events.d.ts +0 -28
- package/dist/tools/get_events.js +0 -66
- package/dist/tools/get_job_logs.d.ts +0 -40
- package/dist/tools/get_job_logs.js +0 -104
- package/dist/tools/get_logs.js +0 -150
- package/dist/tools/list_contexts.d.ts +0 -23
- package/dist/tools/list_contexts.js +0 -39
- package/dist/tools/list_cronjobs.d.ts +0 -23
- package/dist/tools/list_cronjobs.js +0 -35
- package/dist/tools/list_deployments.d.ts +0 -23
- package/dist/tools/list_deployments.js +0 -30
- package/dist/tools/list_jobs.d.ts +0 -29
- package/dist/tools/list_jobs.js +0 -77
- package/dist/tools/list_nodes.d.ts +0 -15
- package/dist/tools/list_nodes.js +0 -21
- package/dist/tools/list_pods.d.ts +0 -23
- package/dist/tools/list_pods.js +0 -29
- package/dist/tools/list_services.d.ts +0 -23
- package/dist/tools/list_services.js +0 -31
- package/dist/tools/scale_deployment.js +0 -50
- package/dist/tools/set_current_context.d.ts +0 -23
- package/dist/tools/set_current_context.js +0 -35
- package/dist/tools/update_configmap.d.ts +0 -33
- package/dist/tools/update_configmap.js +0 -71
- package/dist/tools/update_deployment.d.ts +0 -113
- package/dist/tools/update_deployment.js +0 -155
- package/dist/tools/update_service.d.ts +0 -72
- package/dist/tools/update_service.js +0 -125
package/dist/tools/get_events.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
export const getEventsSchema = {
|
|
2
|
-
name: "get_events",
|
|
3
|
-
description: "Get Kubernetes events from the cluster",
|
|
4
|
-
inputSchema: {
|
|
5
|
-
type: "object",
|
|
6
|
-
properties: {
|
|
7
|
-
namespace: {
|
|
8
|
-
type: "string",
|
|
9
|
-
description: "Namespace to get events from. If not specified, gets events from all namespaces",
|
|
10
|
-
},
|
|
11
|
-
fieldSelector: {
|
|
12
|
-
type: "string",
|
|
13
|
-
description: "Field selector to filter events",
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
required: [],
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
export async function getEvents(k8sManager, params) {
|
|
20
|
-
const { namespace, fieldSelector } = params;
|
|
21
|
-
const api = k8sManager.getCoreApi();
|
|
22
|
-
let events;
|
|
23
|
-
if (namespace) {
|
|
24
|
-
const { body } = await api.listNamespacedEvent(namespace, undefined, // pretty
|
|
25
|
-
undefined, // allowWatchBookmarks
|
|
26
|
-
undefined, // _continue
|
|
27
|
-
undefined, // fieldSelector
|
|
28
|
-
fieldSelector // fieldSelector
|
|
29
|
-
);
|
|
30
|
-
events = body;
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
const { body } = await api.listEventForAllNamespaces(undefined, // allowWatchBookmarks
|
|
34
|
-
undefined, // _continue
|
|
35
|
-
fieldSelector, // fieldSelector
|
|
36
|
-
undefined, // labelSelector
|
|
37
|
-
undefined, // limit
|
|
38
|
-
undefined, // pretty
|
|
39
|
-
undefined, // resourceVersion
|
|
40
|
-
undefined, // resourceVersionMatch
|
|
41
|
-
undefined // timeoutSeconds
|
|
42
|
-
);
|
|
43
|
-
events = body;
|
|
44
|
-
}
|
|
45
|
-
const formattedEvents = events.items.map((event) => ({
|
|
46
|
-
type: event.type || "",
|
|
47
|
-
reason: event.reason || "",
|
|
48
|
-
message: event.message || "",
|
|
49
|
-
involvedObject: {
|
|
50
|
-
kind: event.involvedObject.kind || "",
|
|
51
|
-
name: event.involvedObject.name || "",
|
|
52
|
-
namespace: event.involvedObject.namespace || "",
|
|
53
|
-
},
|
|
54
|
-
firstTimestamp: event.firstTimestamp || "",
|
|
55
|
-
lastTimestamp: event.lastTimestamp || "",
|
|
56
|
-
count: event.count || 0,
|
|
57
|
-
}));
|
|
58
|
-
return {
|
|
59
|
-
content: [
|
|
60
|
-
{
|
|
61
|
-
type: "text",
|
|
62
|
-
text: JSON.stringify({ events: formattedEvents }, null, 2),
|
|
63
|
-
},
|
|
64
|
-
],
|
|
65
|
-
};
|
|
66
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { KubernetesManager } from "../types.js";
|
|
2
|
-
export declare const getJobLogsSchema: {
|
|
3
|
-
readonly name: "get_job_logs";
|
|
4
|
-
readonly description: "Get logs from Pods created by a specific Job";
|
|
5
|
-
readonly inputSchema: {
|
|
6
|
-
readonly type: "object";
|
|
7
|
-
readonly properties: {
|
|
8
|
-
readonly name: {
|
|
9
|
-
readonly type: "string";
|
|
10
|
-
readonly description: "Name of the Job to get logs from";
|
|
11
|
-
};
|
|
12
|
-
readonly namespace: {
|
|
13
|
-
readonly type: "string";
|
|
14
|
-
readonly default: "default";
|
|
15
|
-
};
|
|
16
|
-
readonly tail: {
|
|
17
|
-
readonly type: "number";
|
|
18
|
-
readonly description: "Number of lines to return from the end of the logs";
|
|
19
|
-
readonly optional: true;
|
|
20
|
-
};
|
|
21
|
-
readonly timestamps: {
|
|
22
|
-
readonly type: "boolean";
|
|
23
|
-
readonly description: "Include timestamps in the logs";
|
|
24
|
-
readonly optional: true;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
readonly required: readonly ["name", "namespace"];
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
export declare function getJobLogs(k8sManager: KubernetesManager, input: {
|
|
31
|
-
name: string;
|
|
32
|
-
namespace: string;
|
|
33
|
-
tail?: number;
|
|
34
|
-
timestamps?: boolean;
|
|
35
|
-
}): Promise<{
|
|
36
|
-
content: {
|
|
37
|
-
type: string;
|
|
38
|
-
text: string;
|
|
39
|
-
}[];
|
|
40
|
-
}>;
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
export const getJobLogsSchema = {
|
|
2
|
-
name: "get_job_logs",
|
|
3
|
-
description: "Get logs from Pods created by a specific Job",
|
|
4
|
-
inputSchema: {
|
|
5
|
-
type: "object",
|
|
6
|
-
properties: {
|
|
7
|
-
name: {
|
|
8
|
-
type: "string",
|
|
9
|
-
description: "Name of the Job to get logs from",
|
|
10
|
-
},
|
|
11
|
-
namespace: {
|
|
12
|
-
type: "string",
|
|
13
|
-
default: "default",
|
|
14
|
-
},
|
|
15
|
-
tail: {
|
|
16
|
-
type: "number",
|
|
17
|
-
description: "Number of lines to return from the end of the logs",
|
|
18
|
-
optional: true,
|
|
19
|
-
},
|
|
20
|
-
timestamps: {
|
|
21
|
-
type: "boolean",
|
|
22
|
-
description: "Include timestamps in the logs",
|
|
23
|
-
optional: true,
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
required: ["name", "namespace"],
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
export async function getJobLogs(k8sManager, input) {
|
|
30
|
-
try {
|
|
31
|
-
const coreApi = k8sManager.getCoreApi();
|
|
32
|
-
// First, get the job to check if it exists
|
|
33
|
-
const batchApi = k8sManager.getBatchApi();
|
|
34
|
-
await batchApi.readNamespacedJob(input.name, input.namespace);
|
|
35
|
-
// Find pods associated with this job
|
|
36
|
-
const labelSelector = `job-name=${input.name}`;
|
|
37
|
-
const { body: podList } = await coreApi.listNamespacedPod(input.namespace, undefined, // pretty
|
|
38
|
-
undefined, // allowWatchBookmarks
|
|
39
|
-
undefined, // _continue
|
|
40
|
-
undefined, // fieldSelector
|
|
41
|
-
labelSelector // labelSelector
|
|
42
|
-
);
|
|
43
|
-
if (podList.items.length === 0) {
|
|
44
|
-
return {
|
|
45
|
-
content: [
|
|
46
|
-
{
|
|
47
|
-
type: "text",
|
|
48
|
-
text: JSON.stringify({
|
|
49
|
-
message: `No pods found for job ${input.name}`,
|
|
50
|
-
}, null, 2),
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
// Get logs from all pods belonging to this job
|
|
56
|
-
const podLogs = await Promise.all(podList.items.map(async (pod) => {
|
|
57
|
-
const podName = pod.metadata?.name || "";
|
|
58
|
-
try {
|
|
59
|
-
const logResponse = await coreApi.readNamespacedPodLog(podName, input.namespace, undefined, // container
|
|
60
|
-
undefined, // follow
|
|
61
|
-
input.timestamps || false, // timestamps
|
|
62
|
-
undefined, // sinceSeconds
|
|
63
|
-
undefined, // sinceTime
|
|
64
|
-
(input.tail != undefined ? true : true) || undefined, // tailLines
|
|
65
|
-
undefined // pretty
|
|
66
|
-
);
|
|
67
|
-
return {
|
|
68
|
-
podName,
|
|
69
|
-
logs: logResponse.body,
|
|
70
|
-
status: pod.status?.phase || "Unknown",
|
|
71
|
-
startTime: pod.status?.startTime || null,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
return {
|
|
76
|
-
podName,
|
|
77
|
-
logs: `Error retrieving logs: ${error.message || "Unknown error"}`,
|
|
78
|
-
status: pod.status?.phase || "Unknown",
|
|
79
|
-
startTime: pod.status?.startTime || null,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
}));
|
|
83
|
-
return {
|
|
84
|
-
content: [
|
|
85
|
-
{
|
|
86
|
-
type: "text",
|
|
87
|
-
text: JSON.stringify({
|
|
88
|
-
job: input.name,
|
|
89
|
-
namespace: input.namespace,
|
|
90
|
-
pods: podLogs,
|
|
91
|
-
}, null, 2),
|
|
92
|
-
},
|
|
93
|
-
],
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
console.error("Error getting Job logs:", {
|
|
98
|
-
status: error.response?.statusCode,
|
|
99
|
-
message: error.response?.body?.message || error.message,
|
|
100
|
-
details: error.response?.body,
|
|
101
|
-
});
|
|
102
|
-
throw error;
|
|
103
|
-
}
|
|
104
|
-
}
|
package/dist/tools/get_logs.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
-
export const getLogsSchema = {
|
|
3
|
-
name: "get_logs",
|
|
4
|
-
description: "Get logs from pods, deployments, jobs, or resources matching a label selector",
|
|
5
|
-
inputSchema: {
|
|
6
|
-
type: "object",
|
|
7
|
-
properties: {
|
|
8
|
-
resourceType: {
|
|
9
|
-
type: "string",
|
|
10
|
-
enum: ["pod", "deployment", "job"],
|
|
11
|
-
description: "Type of resource to get logs from",
|
|
12
|
-
},
|
|
13
|
-
name: {
|
|
14
|
-
type: "string",
|
|
15
|
-
description: "Name of the resource",
|
|
16
|
-
},
|
|
17
|
-
namespace: {
|
|
18
|
-
type: "string",
|
|
19
|
-
description: "Namespace of the resource",
|
|
20
|
-
default: "default",
|
|
21
|
-
},
|
|
22
|
-
labelSelector: {
|
|
23
|
-
type: "string",
|
|
24
|
-
description: "Label selector to filter resources",
|
|
25
|
-
optional: true,
|
|
26
|
-
},
|
|
27
|
-
container: {
|
|
28
|
-
type: "string",
|
|
29
|
-
description: "Container name (required when pod has multiple containers)",
|
|
30
|
-
optional: true,
|
|
31
|
-
},
|
|
32
|
-
tail: {
|
|
33
|
-
type: "number",
|
|
34
|
-
description: "Number of lines to show from end of logs",
|
|
35
|
-
optional: true,
|
|
36
|
-
},
|
|
37
|
-
since: {
|
|
38
|
-
type: "number",
|
|
39
|
-
description: "Get logs since relative time in seconds",
|
|
40
|
-
optional: true,
|
|
41
|
-
},
|
|
42
|
-
timestamps: {
|
|
43
|
-
type: "boolean",
|
|
44
|
-
description: "Include timestamps in logs",
|
|
45
|
-
default: false,
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
required: ["resourceType"],
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
async function getPodLogs(k8sManager, podName, podNamespace, input) {
|
|
52
|
-
try {
|
|
53
|
-
const { body } = await k8sManager.getCoreApi().readNamespacedPodLog(podName, podNamespace, input.container, input.follow, undefined, // insecureSkipTLSVerifyBackend
|
|
54
|
-
undefined, // limitBytes
|
|
55
|
-
input.pretty ? "true" : "false", undefined, // previous
|
|
56
|
-
input.sinceSeconds, input.tail, input.timestamps);
|
|
57
|
-
return body;
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
if (error.response?.statusCode === 404) {
|
|
61
|
-
throw new McpError(ErrorCode.InvalidRequest, `Pod ${podName} not found in namespace ${podNamespace}`);
|
|
62
|
-
}
|
|
63
|
-
// Log full error details
|
|
64
|
-
console.error("Full error:", {
|
|
65
|
-
statusCode: error.response?.statusCode,
|
|
66
|
-
message: error.response?.body?.message || error.message,
|
|
67
|
-
details: error.response?.body,
|
|
68
|
-
});
|
|
69
|
-
throw new McpError(ErrorCode.InternalError, `Failed to get logs for pod ${podName}: ${error.response?.body?.message || error.message}`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
export async function getLogs(k8sManager, input) {
|
|
73
|
-
const namespace = input.namespace || "default";
|
|
74
|
-
const logs = {};
|
|
75
|
-
try {
|
|
76
|
-
// Get logs based on resource type
|
|
77
|
-
switch (input.resourceType.toLowerCase()) {
|
|
78
|
-
case "pod": {
|
|
79
|
-
if (!input.name) {
|
|
80
|
-
throw new McpError(ErrorCode.InvalidRequest, "Pod name is required when resourceType is 'pod'");
|
|
81
|
-
}
|
|
82
|
-
logs[input.name] = await getPodLogs(k8sManager, input.name, namespace, input);
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
case "deployment": {
|
|
86
|
-
if (!input.name) {
|
|
87
|
-
throw new McpError(ErrorCode.InvalidRequest, "Deployment name is required when resourceType is 'deployment'");
|
|
88
|
-
}
|
|
89
|
-
const { body: deployment } = await k8sManager
|
|
90
|
-
.getAppsApi()
|
|
91
|
-
.readNamespacedDeployment(input.name, namespace);
|
|
92
|
-
if (!deployment.spec?.selector?.matchLabels) {
|
|
93
|
-
throw new McpError(ErrorCode.InvalidRequest, `Deployment ${input.name} has no selector`);
|
|
94
|
-
}
|
|
95
|
-
const selector = Object.entries(deployment.spec.selector.matchLabels)
|
|
96
|
-
.map(([key, value]) => `${key}=${value}`)
|
|
97
|
-
.join(",");
|
|
98
|
-
const { body: podList } = await k8sManager
|
|
99
|
-
.getCoreApi()
|
|
100
|
-
.listNamespacedPod(namespace, undefined, undefined, undefined, undefined, selector);
|
|
101
|
-
for (const pod of podList.items) {
|
|
102
|
-
if (pod.metadata?.name) {
|
|
103
|
-
logs[pod.metadata.name] = await getPodLogs(k8sManager, pod.metadata.name, namespace, input);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
case "job": {
|
|
109
|
-
if (!input.name) {
|
|
110
|
-
throw new McpError(ErrorCode.InvalidRequest, "Job name is required when resourceType is 'job'");
|
|
111
|
-
}
|
|
112
|
-
const { body: podList } = await k8sManager
|
|
113
|
-
.getCoreApi()
|
|
114
|
-
.listNamespacedPod(namespace, undefined, undefined, undefined, undefined, `job-name=${input.name}`);
|
|
115
|
-
for (const pod of podList.items) {
|
|
116
|
-
if (pod.metadata?.name) {
|
|
117
|
-
logs[pod.metadata.name] = await getPodLogs(k8sManager, pod.metadata.name, namespace, input);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
default:
|
|
123
|
-
throw new McpError(ErrorCode.InvalidRequest, `Unsupported resource type: ${input.resourceType}`);
|
|
124
|
-
}
|
|
125
|
-
// If labelSelector is provided, filter or add logs by label
|
|
126
|
-
if (input.labelSelector) {
|
|
127
|
-
const { body: labeledPods } = await k8sManager
|
|
128
|
-
.getCoreApi()
|
|
129
|
-
.listNamespacedPod(namespace, undefined, undefined, undefined, undefined, input.labelSelector);
|
|
130
|
-
for (const pod of labeledPods.items) {
|
|
131
|
-
if (pod.metadata?.name) {
|
|
132
|
-
logs[pod.metadata.name] = await getPodLogs(k8sManager, pod.metadata.name, namespace, input);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return {
|
|
137
|
-
content: [
|
|
138
|
-
{
|
|
139
|
-
type: "text",
|
|
140
|
-
text: JSON.stringify({ logs }, null, 2),
|
|
141
|
-
},
|
|
142
|
-
],
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
catch (error) {
|
|
146
|
-
if (error instanceof McpError)
|
|
147
|
-
throw error;
|
|
148
|
-
throw new McpError(ErrorCode.InternalError, `Failed to get logs: ${error}`);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { KubernetesManager } from "../types.js";
|
|
2
|
-
export declare const listContextsSchema: {
|
|
3
|
-
readonly name: "list_contexts";
|
|
4
|
-
readonly description: "List all available Kubernetes contexts";
|
|
5
|
-
readonly inputSchema: {
|
|
6
|
-
readonly type: "object";
|
|
7
|
-
readonly properties: {
|
|
8
|
-
readonly showCurrent: {
|
|
9
|
-
readonly type: "boolean";
|
|
10
|
-
readonly description: "Show which context is currently active";
|
|
11
|
-
readonly default: true;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
export declare function listContexts(k8sManager: KubernetesManager, input: {
|
|
17
|
-
showCurrent?: boolean;
|
|
18
|
-
}): Promise<{
|
|
19
|
-
content: {
|
|
20
|
-
type: string;
|
|
21
|
-
text: string;
|
|
22
|
-
}[];
|
|
23
|
-
}>;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export const listContextsSchema = {
|
|
2
|
-
name: "list_contexts",
|
|
3
|
-
description: "List all available Kubernetes contexts",
|
|
4
|
-
inputSchema: {
|
|
5
|
-
type: "object",
|
|
6
|
-
properties: {
|
|
7
|
-
showCurrent: {
|
|
8
|
-
type: "boolean",
|
|
9
|
-
description: "Show which context is currently active",
|
|
10
|
-
default: true
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
export async function listContexts(k8sManager, input) {
|
|
16
|
-
try {
|
|
17
|
-
// Get the KubeConfig from the KubernetesManager
|
|
18
|
-
const kc = k8sManager.getKubeConfig();
|
|
19
|
-
const contexts = kc.getContexts();
|
|
20
|
-
const currentContext = input.showCurrent ? kc.getCurrentContext() : undefined;
|
|
21
|
-
const contextList = contexts.map(context => ({
|
|
22
|
-
name: context.name,
|
|
23
|
-
cluster: context.cluster,
|
|
24
|
-
user: context.user,
|
|
25
|
-
isCurrent: context.name === currentContext
|
|
26
|
-
}));
|
|
27
|
-
return {
|
|
28
|
-
content: [
|
|
29
|
-
{
|
|
30
|
-
type: "text",
|
|
31
|
-
text: JSON.stringify({ contexts: contextList }, null, 2),
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
throw new Error(`Failed to list contexts: ${error.message}`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { KubernetesManager } from "../types.js";
|
|
2
|
-
export declare const listCronJobsSchema: {
|
|
3
|
-
readonly name: "list_cronjobs";
|
|
4
|
-
readonly description: "List CronJobs 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 listCronJobs(k8sManager: KubernetesManager, input: {
|
|
17
|
-
namespace?: string;
|
|
18
|
-
}): Promise<{
|
|
19
|
-
content: {
|
|
20
|
-
type: string;
|
|
21
|
-
text: string;
|
|
22
|
-
}[];
|
|
23
|
-
}>;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export const listCronJobsSchema = {
|
|
2
|
-
name: "list_cronjobs",
|
|
3
|
-
description: "List CronJobs 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 listCronJobs(k8sManager, input) {
|
|
13
|
-
const namespace = input.namespace || "default";
|
|
14
|
-
// Get BatchV1Api from KubernetesManager
|
|
15
|
-
const batchV1Api = k8sManager.getBatchApi();
|
|
16
|
-
// List cronjobs in the specified namespace
|
|
17
|
-
const { body } = await batchV1Api.listNamespacedCronJob(namespace);
|
|
18
|
-
// Transform cronjob data to a more readable format
|
|
19
|
-
const cronjobs = body.items.map((cronjob) => ({
|
|
20
|
-
name: cronjob.metadata?.name || "",
|
|
21
|
-
namespace: cronjob.metadata?.namespace || "",
|
|
22
|
-
schedule: cronjob.spec?.schedule || "",
|
|
23
|
-
suspend: cronjob.spec?.suspend || false,
|
|
24
|
-
lastScheduleTime: cronjob.status?.lastScheduleTime || null,
|
|
25
|
-
createdAt: cronjob.metadata?.creationTimestamp,
|
|
26
|
-
}));
|
|
27
|
-
return {
|
|
28
|
-
content: [
|
|
29
|
-
{
|
|
30
|
-
type: "text",
|
|
31
|
-
text: JSON.stringify({ cronjobs }, null, 2),
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
};
|
|
35
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
}>;
|
|
@@ -1,30 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { KubernetesManager } from "../types.js";
|
|
2
|
-
export declare const listJobsSchema: {
|
|
3
|
-
readonly name: "list_jobs";
|
|
4
|
-
readonly description: "List Jobs in a namespace, optionally filtered by a CronJob parent";
|
|
5
|
-
readonly inputSchema: {
|
|
6
|
-
readonly type: "object";
|
|
7
|
-
readonly properties: {
|
|
8
|
-
readonly namespace: {
|
|
9
|
-
readonly type: "string";
|
|
10
|
-
readonly default: "default";
|
|
11
|
-
};
|
|
12
|
-
readonly cronJobName: {
|
|
13
|
-
readonly type: "string";
|
|
14
|
-
readonly description: "Optional: Filter jobs created by a specific CronJob";
|
|
15
|
-
readonly optional: true;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
readonly required: readonly ["namespace"];
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
export declare function listJobs(k8sManager: KubernetesManager, input: {
|
|
22
|
-
namespace: string;
|
|
23
|
-
cronJobName?: string;
|
|
24
|
-
}): Promise<{
|
|
25
|
-
content: {
|
|
26
|
-
type: string;
|
|
27
|
-
text: string;
|
|
28
|
-
}[];
|
|
29
|
-
}>;
|
package/dist/tools/list_jobs.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
export const listJobsSchema = {
|
|
2
|
-
name: "list_jobs",
|
|
3
|
-
description: "List Jobs in a namespace, optionally filtered by a CronJob parent",
|
|
4
|
-
inputSchema: {
|
|
5
|
-
type: "object",
|
|
6
|
-
properties: {
|
|
7
|
-
namespace: { type: "string", default: "default" },
|
|
8
|
-
cronJobName: {
|
|
9
|
-
type: "string",
|
|
10
|
-
description: "Optional: Filter jobs created by a specific CronJob",
|
|
11
|
-
optional: true,
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
required: ["namespace"],
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
export async function listJobs(k8sManager, input) {
|
|
18
|
-
try {
|
|
19
|
-
const namespace = input.namespace;
|
|
20
|
-
const batchV1Api = k8sManager.getBatchApi();
|
|
21
|
-
// Set up label selector if cronJobName is provided
|
|
22
|
-
let labelSelector;
|
|
23
|
-
if (input.cronJobName) {
|
|
24
|
-
labelSelector = `cronjob-name=${input.cronJobName}`;
|
|
25
|
-
}
|
|
26
|
-
// Get jobs with optional filtering
|
|
27
|
-
const { body } = await batchV1Api.listNamespacedJob(namespace, undefined, // pretty
|
|
28
|
-
undefined, // allowWatchBookmarks
|
|
29
|
-
undefined, // _continue
|
|
30
|
-
undefined, // fieldSelector
|
|
31
|
-
labelSelector // labelSelector
|
|
32
|
-
);
|
|
33
|
-
// Sort jobs by creation time (newest first)
|
|
34
|
-
const jobs = body.items.sort((a, b) => {
|
|
35
|
-
const aTime = a.metadata?.creationTimestamp
|
|
36
|
-
? new Date(a.metadata.creationTimestamp)
|
|
37
|
-
: new Date(0);
|
|
38
|
-
const bTime = b.metadata?.creationTimestamp
|
|
39
|
-
? new Date(b.metadata.creationTimestamp)
|
|
40
|
-
: new Date(0);
|
|
41
|
-
return bTime.getTime() - aTime.getTime();
|
|
42
|
-
});
|
|
43
|
-
// Transform job data to a more readable format
|
|
44
|
-
const formattedJobs = jobs.map((job) => ({
|
|
45
|
-
name: job.metadata?.name || "",
|
|
46
|
-
namespace: job.metadata?.namespace || "",
|
|
47
|
-
creationTime: job.metadata?.creationTimestamp || "",
|
|
48
|
-
labels: job.metadata?.labels || {},
|
|
49
|
-
completions: job.spec?.completions || 1,
|
|
50
|
-
parallelism: job.spec?.parallelism || 1,
|
|
51
|
-
status: {
|
|
52
|
-
active: job.status?.active || 0,
|
|
53
|
-
succeeded: job.status?.succeeded || 0,
|
|
54
|
-
failed: job.status?.failed || 0,
|
|
55
|
-
completionTime: job.status?.completionTime || null,
|
|
56
|
-
startTime: job.status?.startTime || null,
|
|
57
|
-
conditions: job.status?.conditions || [],
|
|
58
|
-
},
|
|
59
|
-
}));
|
|
60
|
-
return {
|
|
61
|
-
content: [
|
|
62
|
-
{
|
|
63
|
-
type: "text",
|
|
64
|
-
text: JSON.stringify({ jobs: formattedJobs }, null, 2),
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
console.error("Error listing Jobs:", {
|
|
71
|
-
status: error.response?.statusCode,
|
|
72
|
-
message: error.response?.body?.message || error.message,
|
|
73
|
-
details: error.response?.body,
|
|
74
|
-
});
|
|
75
|
-
throw error;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
}>;
|