mcp-server-kubernetes 2.6.0 → 2.7.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.js
CHANGED
|
@@ -24,6 +24,7 @@ import { kubectlPatch, kubectlPatchSchema } from "./tools/kubectl-patch.js";
|
|
|
24
24
|
import { kubectlRollout, kubectlRolloutSchema, } from "./tools/kubectl-rollout.js";
|
|
25
25
|
import { registerPromptHandlers } from "./prompts/index.js";
|
|
26
26
|
import { ping, pingSchema } from "./tools/ping.js";
|
|
27
|
+
import { startStreamableHTTPServer } from "./utils/streamable-http.js";
|
|
27
28
|
// Check environment variables for tool filtering
|
|
28
29
|
const allowOnlyReadonlyTools = process.env.ALLOW_ONLY_READONLY_TOOLS === "true";
|
|
29
30
|
const allowedToolsEnv = process.env.ALLOWED_TOOLS;
|
|
@@ -217,6 +218,10 @@ if (process.env.ENABLE_UNSAFE_SSE_TRANSPORT) {
|
|
|
217
218
|
startSSEServer(server);
|
|
218
219
|
console.log(`SSE server started`);
|
|
219
220
|
}
|
|
221
|
+
else if (process.env.ENABLE_UNSAFE_STREAMABLE_HTTP_TRANSPORT) {
|
|
222
|
+
startStreamableHTTPServer(server);
|
|
223
|
+
console.log(`Streamable HTTP server started`);
|
|
224
|
+
}
|
|
220
225
|
else {
|
|
221
226
|
const transport = new StdioServerTransport();
|
|
222
227
|
console.error(`Starting Kubernetes MCP server v${serverConfig.version}, handling commands...`);
|
|
@@ -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.7.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",
|