mcp-server-kubernetes 2.6.0 → 2.8.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/dist/index.d.ts +86 -29
- package/dist/index.js +6 -0
- package/dist/models/common-parameters.d.ts +15 -0
- package/dist/models/common-parameters.js +15 -0
- package/dist/models/kubectl-models.d.ts +2 -0
- package/dist/tools/exec_in_pod.d.ts +7 -1
- package/dist/tools/exec_in_pod.js +7 -5
- package/dist/tools/helm-operations.d.ts +21 -3
- package/dist/tools/helm-operations.js +7 -12
- package/dist/tools/kubectl-apply.d.ts +12 -6
- package/dist/tools/kubectl-apply.js +9 -10
- package/dist/tools/kubectl-create.d.ts +12 -6
- package/dist/tools/kubectl-create.js +9 -10
- package/dist/tools/kubectl-delete.d.ts +9 -3
- package/dist/tools/kubectl-delete.js +8 -5
- package/dist/tools/kubectl-describe.d.ts +9 -3
- package/dist/tools/kubectl-describe.js +7 -5
- package/dist/tools/kubectl-generic.d.ts +7 -1
- package/dist/tools/kubectl-generic.js +7 -5
- package/dist/tools/kubectl-get.d.ts +9 -3
- package/dist/tools/kubectl-get.js +7 -5
- package/dist/tools/kubectl-logs.d.ts +9 -3
- package/dist/tools/kubectl-logs.js +11 -5
- package/dist/tools/kubectl-operations.d.ts +10 -0
- package/dist/tools/kubectl-operations.js +13 -0
- package/dist/tools/kubectl-patch.d.ts +8 -2
- package/dist/tools/kubectl-patch.js +9 -10
- package/dist/tools/kubectl-rollout.d.ts +7 -1
- package/dist/tools/kubectl-rollout.js +8 -5
- package/dist/tools/kubectl-scale.d.ts +7 -1
- package/dist/tools/kubectl-scale.js +8 -5
- package/dist/utils/streamable-http.d.ts +3 -0
- package/dist/utils/streamable-http.js +79 -0
- package/package.json +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { execFileSync } from "child_process";
|
|
2
2
|
import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
|
|
3
3
|
import { getSpawnMaxBuffer } from "../config/max-buffer.js";
|
|
4
|
+
import { contextParameter, namespaceParameter } from "../models/common-parameters.js";
|
|
4
5
|
export const kubectlScaleSchema = {
|
|
5
6
|
name: "kubectl_scale",
|
|
6
7
|
description: "Scale a Kubernetes deployment",
|
|
@@ -11,11 +12,7 @@ export const kubectlScaleSchema = {
|
|
|
11
12
|
type: "string",
|
|
12
13
|
description: "Name of the deployment to scale",
|
|
13
14
|
},
|
|
14
|
-
namespace:
|
|
15
|
-
type: "string",
|
|
16
|
-
description: "Namespace of the deployment",
|
|
17
|
-
default: "default",
|
|
18
|
-
},
|
|
15
|
+
namespace: namespaceParameter,
|
|
19
16
|
replicas: {
|
|
20
17
|
type: "number",
|
|
21
18
|
description: "Number of replicas to scale to",
|
|
@@ -25,6 +22,7 @@ export const kubectlScaleSchema = {
|
|
|
25
22
|
description: "Resource type to scale (deployment, replicaset, statefulset)",
|
|
26
23
|
default: "deployment",
|
|
27
24
|
},
|
|
25
|
+
context: contextParameter,
|
|
28
26
|
},
|
|
29
27
|
required: ["name", "replicas"],
|
|
30
28
|
},
|
|
@@ -33,6 +31,7 @@ export async function kubectlScale(k8sManager, input) {
|
|
|
33
31
|
try {
|
|
34
32
|
const namespace = input.namespace || "default";
|
|
35
33
|
const resourceType = input.resourceType || "deployment";
|
|
34
|
+
const context = input.context || "";
|
|
36
35
|
const command = "kubectl";
|
|
37
36
|
const args = [
|
|
38
37
|
"scale",
|
|
@@ -41,6 +40,10 @@ export async function kubectlScale(k8sManager, input) {
|
|
|
41
40
|
`--replicas=${input.replicas}`,
|
|
42
41
|
`--namespace=${namespace}`,
|
|
43
42
|
];
|
|
43
|
+
// Add context if provided
|
|
44
|
+
if (context) {
|
|
45
|
+
args.push("--context", context);
|
|
46
|
+
}
|
|
44
47
|
// Execute the command
|
|
45
48
|
try {
|
|
46
49
|
const result = execFileSync(command, args, {
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
3
|
+
export function startStreamableHTTPServer(server) {
|
|
4
|
+
const app = express();
|
|
5
|
+
app.use(express.json());
|
|
6
|
+
app.post("/mcp", async (req, res) => {
|
|
7
|
+
// In stateless mode, create a new instance of transport and server for each request
|
|
8
|
+
// to ensure complete isolation. A single instance would cause request ID collisions
|
|
9
|
+
// when multiple clients connect concurrently.
|
|
10
|
+
try {
|
|
11
|
+
// DNS rebinding protection is disabled by default for backwards compatibility. If you are running this server
|
|
12
|
+
// locally, make sure to set DNS_REBINDING_PROTECTION=true
|
|
13
|
+
const enableDnsRebindingProtection = process.env.DNS_REBINDING_PROTECTION === "true";
|
|
14
|
+
const allowedHosts = process.env.DNS_REBINDING_ALLOWED_HOST
|
|
15
|
+
? [process.env.DNS_REBINDING_ALLOWED_HOST]
|
|
16
|
+
: ["127.0.0.1"];
|
|
17
|
+
const transport = new StreamableHTTPServerTransport({
|
|
18
|
+
sessionIdGenerator: undefined,
|
|
19
|
+
enableDnsRebindingProtection,
|
|
20
|
+
allowedHosts,
|
|
21
|
+
});
|
|
22
|
+
res.on("close", () => {
|
|
23
|
+
transport.close();
|
|
24
|
+
server.close();
|
|
25
|
+
});
|
|
26
|
+
await server.connect(transport);
|
|
27
|
+
await transport.handleRequest(req, res, req.body);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.error("Error handling MCP request:", error);
|
|
31
|
+
if (!res.headersSent) {
|
|
32
|
+
res.status(500).json({
|
|
33
|
+
jsonrpc: "2.0",
|
|
34
|
+
error: {
|
|
35
|
+
code: -32603,
|
|
36
|
+
message: "Internal server error",
|
|
37
|
+
},
|
|
38
|
+
id: null,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
// SSE notifications not supported in stateless mode
|
|
44
|
+
app.get("/mcp", async (req, res) => {
|
|
45
|
+
console.log("Received GET MCP request");
|
|
46
|
+
res.writeHead(405).end(JSON.stringify({
|
|
47
|
+
jsonrpc: "2.0",
|
|
48
|
+
error: {
|
|
49
|
+
code: -32000,
|
|
50
|
+
message: "Method not allowed.",
|
|
51
|
+
},
|
|
52
|
+
id: null,
|
|
53
|
+
}));
|
|
54
|
+
});
|
|
55
|
+
// Session termination not needed in stateless mode
|
|
56
|
+
app.delete("/mcp", async (req, res) => {
|
|
57
|
+
console.log("Received DELETE MCP request");
|
|
58
|
+
res.writeHead(405).end(JSON.stringify({
|
|
59
|
+
jsonrpc: "2.0",
|
|
60
|
+
error: {
|
|
61
|
+
code: -32000,
|
|
62
|
+
message: "Method not allowed.",
|
|
63
|
+
},
|
|
64
|
+
id: null,
|
|
65
|
+
}));
|
|
66
|
+
});
|
|
67
|
+
let port = 3000;
|
|
68
|
+
try {
|
|
69
|
+
port = parseInt(process.env.PORT || "3000", 10);
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
console.error("Invalid PORT environment variable, using default port 3000.");
|
|
73
|
+
}
|
|
74
|
+
const host = process.env.HOST || "localhost";
|
|
75
|
+
const httpServer = app.listen(port, host, () => {
|
|
76
|
+
console.log(`mcp-kubernetes-server is listening on port ${port}\nUse the following url to connect to the server:\nhttp://${host}:${port}/mcp`);
|
|
77
|
+
});
|
|
78
|
+
return httpServer;
|
|
79
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-server-kubernetes",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
4
4
|
"description": "MCP server for interacting with Kubernetes clusters via kubectl",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@kubernetes/client-node": "1.3.0",
|
|
41
|
-
"@modelcontextprotocol/sdk": "1.
|
|
41
|
+
"@modelcontextprotocol/sdk": "1.17.0",
|
|
42
42
|
"express": "4.21.2",
|
|
43
43
|
"js-yaml": "4.1.0",
|
|
44
44
|
"yaml": "2.7.0",
|