mcp-server-kubernetes 1.6.2 → 2.1.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/dist/utils/kubernetes-manager.d.ts +4 -0
- package/dist/utils/kubernetes-manager.js +21 -3
- 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
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
export const GetConfigMapSchema = {
|
|
2
|
-
name: "get_configmap",
|
|
3
|
-
description: "Get a Kubernetes ConfigMap",
|
|
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 getConfigMap(k8sManager, input) {
|
|
14
|
-
try {
|
|
15
|
-
const response = await k8sManager.getCoreApi().readNamespacedConfigMap(input.name, input.namespace);
|
|
16
|
-
if (response.body && response.body.data) {
|
|
17
|
-
return {
|
|
18
|
-
content: [
|
|
19
|
-
{
|
|
20
|
-
success: true,
|
|
21
|
-
message: `Fetched ConfigMap ${input.name} in namespace ${input.namespace}`,
|
|
22
|
-
data: response.body.data,
|
|
23
|
-
},
|
|
24
|
-
],
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
return {
|
|
29
|
-
content: [
|
|
30
|
-
{
|
|
31
|
-
success: false,
|
|
32
|
-
message: `ConfigMap ${input.name} in namespace ${input.namespace} not found or has no data.`,
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
return {
|
|
40
|
-
content: [
|
|
41
|
-
{
|
|
42
|
-
success: false,
|
|
43
|
-
message: `Failed to get ConfigMap ${input.name} in namespace ${input.namespace}. Error: ${error.message}`,
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { KubernetesManager } from "../types.js";
|
|
2
|
-
export declare const getCurrentContextSchema: {
|
|
3
|
-
readonly name: "get_current_context";
|
|
4
|
-
readonly description: "Get the current Kubernetes context";
|
|
5
|
-
readonly inputSchema: {
|
|
6
|
-
readonly type: "object";
|
|
7
|
-
readonly properties: {
|
|
8
|
-
readonly detailed: {
|
|
9
|
-
readonly type: "boolean";
|
|
10
|
-
readonly description: "Include detailed information about the current context";
|
|
11
|
-
readonly default: false;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
export declare function getCurrentContext(k8sManager: KubernetesManager, input: {
|
|
17
|
-
detailed?: boolean;
|
|
18
|
-
}): Promise<{
|
|
19
|
-
content: {
|
|
20
|
-
type: string;
|
|
21
|
-
text: string;
|
|
22
|
-
}[];
|
|
23
|
-
}>;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
export const getCurrentContextSchema = {
|
|
2
|
-
name: "get_current_context",
|
|
3
|
-
description: "Get the current Kubernetes context",
|
|
4
|
-
inputSchema: {
|
|
5
|
-
type: "object",
|
|
6
|
-
properties: {
|
|
7
|
-
detailed: {
|
|
8
|
-
type: "boolean",
|
|
9
|
-
description: "Include detailed information about the current context",
|
|
10
|
-
default: false
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
export async function getCurrentContext(k8sManager, input) {
|
|
16
|
-
try {
|
|
17
|
-
// Get the KubeConfig from the KubernetesManager
|
|
18
|
-
const kc = k8sManager.getKubeConfig();
|
|
19
|
-
// Get the current context name
|
|
20
|
-
const currentContextName = kc.getCurrentContext();
|
|
21
|
-
// If detailed is true, get more information about the context
|
|
22
|
-
if (input.detailed) {
|
|
23
|
-
const contexts = kc.getContexts();
|
|
24
|
-
const currentContext = contexts.find(context => context.name === currentContextName);
|
|
25
|
-
if (!currentContext) {
|
|
26
|
-
throw new Error(`Current context '${currentContextName}' not found in available contexts`);
|
|
27
|
-
}
|
|
28
|
-
return {
|
|
29
|
-
content: [
|
|
30
|
-
{
|
|
31
|
-
type: "text",
|
|
32
|
-
text: JSON.stringify({
|
|
33
|
-
name: currentContextName,
|
|
34
|
-
cluster: currentContext.cluster,
|
|
35
|
-
user: currentContext.user,
|
|
36
|
-
namespace: currentContext.namespace || "default"
|
|
37
|
-
}, null, 2),
|
|
38
|
-
},
|
|
39
|
-
],
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
// Simple response with just the context name
|
|
43
|
-
return {
|
|
44
|
-
content: [
|
|
45
|
-
{
|
|
46
|
-
type: "text",
|
|
47
|
-
text: JSON.stringify({ currentContext: currentContextName }, null, 2),
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
throw new Error(`Failed to get current context: ${error.message}`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { KubernetesManager } from "../types.js";
|
|
2
|
-
export declare const getEventsSchema: {
|
|
3
|
-
name: string;
|
|
4
|
-
description: string;
|
|
5
|
-
inputSchema: {
|
|
6
|
-
type: string;
|
|
7
|
-
properties: {
|
|
8
|
-
namespace: {
|
|
9
|
-
type: string;
|
|
10
|
-
description: string;
|
|
11
|
-
};
|
|
12
|
-
fieldSelector: {
|
|
13
|
-
type: string;
|
|
14
|
-
description: string;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
required: never[];
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
export declare function getEvents(k8sManager: KubernetesManager, params: {
|
|
21
|
-
namespace?: string;
|
|
22
|
-
fieldSelector?: string;
|
|
23
|
-
}): Promise<{
|
|
24
|
-
content: {
|
|
25
|
-
type: string;
|
|
26
|
-
text: string;
|
|
27
|
-
}[];
|
|
28
|
-
}>;
|
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
|
-
}>;
|