mcp-server-kubernetes 0.3.1 → 0.4.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 +31 -42
- package/dist/index.js +8 -2
- package/dist/utils/sse.d.ts +2 -0
- package/dist/utils/sse.js +27 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# MCP Server Kubernetes
|
|
2
|
+
|
|
3
|
+
[](https://github.com/yourusername/mcp-server-kubernetes/actions/workflows/ci.yml)
|
|
4
|
+
[](https://github.com/yourusername/mcp-server-kubernetes)
|
|
5
|
+
[](https://bun.sh)
|
|
6
|
+
[](https://kubernetes.io/)
|
|
7
|
+
[](https://www.docker.com/)
|
|
8
|
+
[](https://github.com/Flux159/mcp-server-kubernetes/stargazers)
|
|
9
|
+
[](https://github.com/Flux159/mcp-server-kubernetes/issues)
|
|
10
|
+
[](https://github.com/Flux159/mcp-server-kubernetes/pulls)
|
|
11
|
+
[](https://github.com/Flux159/mcp-server-kubernetes/commits/main)
|
|
12
|
+
[](https://smithery.ai/protocol/mcp-server-kubernetes)
|
|
2
13
|
|
|
3
14
|
MCP Server that can connect to a Kubernetes cluster and manage it.
|
|
4
15
|
|
|
@@ -6,8 +17,6 @@ https://github.com/user-attachments/assets/f25f8f4e-4d04-479b-9ae0-5dac452dd2ed
|
|
|
6
17
|
|
|
7
18
|
<a href="https://glama.ai/mcp/servers/w71ieamqrt"><img width="380" height="200" src="https://glama.ai/mcp/servers/w71ieamqrt/badge" /></a>
|
|
8
19
|
|
|
9
|
-
[](https://smithery.ai/server/mcp-server-kubernetes)
|
|
10
|
-
|
|
11
20
|
## Usage with Claude Desktop
|
|
12
21
|
|
|
13
22
|
```json
|
|
@@ -109,56 +118,36 @@ bun run build
|
|
|
109
118
|
4. Local Testing with [Inspector](https://github.com/modelcontextprotocol/inspector)
|
|
110
119
|
|
|
111
120
|
```bash
|
|
112
|
-
npx @modelcontextprotocol/inspector node
|
|
121
|
+
npx @modelcontextprotocol/inspector node dist/index.js
|
|
113
122
|
# Follow further instructions on terminal for Inspector link
|
|
114
123
|
```
|
|
115
124
|
|
|
116
|
-
5. Local testing with
|
|
125
|
+
5. Local testing with Claude Desktop
|
|
117
126
|
|
|
118
|
-
```
|
|
119
|
-
|
|
127
|
+
```json
|
|
128
|
+
{
|
|
129
|
+
"mcpServers": {
|
|
130
|
+
"mcp-server-kubernetes": {
|
|
131
|
+
"command": "node",
|
|
132
|
+
"args": ["/path/to/your/mcp-server-kubernetes/dist/index.js"]
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
120
136
|
```
|
|
121
137
|
|
|
122
|
-
|
|
138
|
+
6. Local testing with [mcp-chat](https://github.com/Flux159/mcp-chat)
|
|
123
139
|
|
|
140
|
+
```bash
|
|
141
|
+
npm run chat
|
|
124
142
|
```
|
|
125
|
-
├── src/
|
|
126
|
-
│ ├── index.ts # Main server implementation
|
|
127
|
-
│ ├── types.ts # Type re-exports
|
|
128
|
-
│ ├── config/ # Configuration files
|
|
129
|
-
│ │ ├── container-templates.ts # Container configurations
|
|
130
|
-
│ │ ├── server-config.ts # Server settings
|
|
131
|
-
│ │ ├── deployment-config.ts # Deployment schemas
|
|
132
|
-
│ │ └── ...
|
|
133
|
-
│ ├── models/ # Data models and schemas
|
|
134
|
-
│ │ ├── response-schemas.ts # API response schemas
|
|
135
|
-
│ │ ├── resource-models.ts # Resource models
|
|
136
|
-
│ │ └── tool-models.ts # Tool schemas
|
|
137
|
-
│ ├── utils/ # Utility classes
|
|
138
|
-
│ │ └── kubernetes-manager.ts # K8s management
|
|
139
|
-
│ ├── resources/ # Resource handlers
|
|
140
|
-
│ │ └── handlers.ts # Resource implementation
|
|
141
|
-
│ └── tools/ # Tool implementations
|
|
142
|
-
│ ├── list_pods.ts
|
|
143
|
-
│ ├── list_services.ts
|
|
144
|
-
│ ├── list_deployments.ts
|
|
145
|
-
│ └── ...
|
|
146
|
-
├── tests/ # Test files
|
|
147
|
-
│ └── unit.test.ts # Unit tests
|
|
148
|
-
│ └── helm.test.ts # Helm tests
|
|
149
|
-
└── ...
|
|
150
|
-
```
|
|
151
143
|
|
|
152
|
-
|
|
144
|
+
## Contributing
|
|
145
|
+
|
|
146
|
+
See the [CONTRIBUTING.md](CONTRIBUTING.md) file for details.
|
|
153
147
|
|
|
154
|
-
|
|
155
|
-
2. Create a feature branch
|
|
156
|
-
3. Make your changes
|
|
157
|
-
4. Add tests for new functionality
|
|
158
|
-
5. Ensure all tests pass
|
|
159
|
-
6. Submit a pull request
|
|
148
|
+
## Advanced
|
|
160
149
|
|
|
161
|
-
For
|
|
150
|
+
For more advanced information like using SSE transport, see the [ADVANCED_README.md](ADVANCED_README.md).
|
|
162
151
|
|
|
163
152
|
## Architecture
|
|
164
153
|
|
package/dist/index.js
CHANGED
|
@@ -19,6 +19,7 @@ import { serverConfig } from "./config/server-config.js";
|
|
|
19
19
|
import { createDeploymentSchema } from "./config/deployment-config.js";
|
|
20
20
|
import { listNamespacesSchema } from "./config/namespace-config.js";
|
|
21
21
|
import { cleanupSchema } from "./config/cleanup-config.js";
|
|
22
|
+
import { startSSEServer } from "./utils/sse.js";
|
|
22
23
|
const k8sManager = new KubernetesManager();
|
|
23
24
|
const server = new Server({
|
|
24
25
|
name: serverConfig.name,
|
|
@@ -137,8 +138,13 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
137
138
|
const resourceHandlers = getResourceHandlers(k8sManager);
|
|
138
139
|
server.setRequestHandler(ListResourcesRequestSchema, resourceHandlers.listResources);
|
|
139
140
|
server.setRequestHandler(ReadResourceRequestSchema, resourceHandlers.readResource);
|
|
140
|
-
|
|
141
|
-
|
|
141
|
+
if (process.env.ENABLE_UNSAFE_SSE_TRANSPORT) {
|
|
142
|
+
startSSEServer(server);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
const transport = new StdioServerTransport();
|
|
146
|
+
await server.connect(transport);
|
|
147
|
+
}
|
|
142
148
|
["SIGINT", "SIGTERM"].forEach((signal) => {
|
|
143
149
|
process.on(signal, async () => {
|
|
144
150
|
console.log(`Received ${signal}, shutting down...`);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
|
|
3
|
+
export function startSSEServer(server) {
|
|
4
|
+
const app = express();
|
|
5
|
+
// Currently just copying from docs & allowing for multiple transport connections: https://modelcontextprotocol.io/docs/concepts/transports#server-sent-events-sse
|
|
6
|
+
// TODO: If exposed to web, then this will enable any client to connect to the server via http - so marked as UNSAFE until mcp has a proper auth solution.
|
|
7
|
+
let transports = [];
|
|
8
|
+
app.get("/sse", async (req, res) => {
|
|
9
|
+
const transport = new SSEServerTransport("/messages", res);
|
|
10
|
+
transports.push(transport);
|
|
11
|
+
await server.connect(transport);
|
|
12
|
+
});
|
|
13
|
+
app.post("/messages", (req, res) => {
|
|
14
|
+
const transport = transports.find((t) => t.sessionId === req.query.sessionId);
|
|
15
|
+
if (transport) {
|
|
16
|
+
transport.handlePostMessage(req, res);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
res
|
|
20
|
+
.status(404)
|
|
21
|
+
.send("Not found. Must pass valid sessionId as query param.");
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
const port = process.env.PORT || 3000;
|
|
25
|
+
app.listen(port);
|
|
26
|
+
console.log(`mcp-kubernetes-server is listening on port ${port}\nUse the following url to connect to the server:\n\http://localhost:${port}/sse`);
|
|
27
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-server-kubernetes",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "MCP server for interacting with Kubernetes clusters via kubectl",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -39,9 +39,11 @@
|
|
|
39
39
|
"@modelcontextprotocol/sdk": "1.0.1",
|
|
40
40
|
"js-yaml": "^4.1.0",
|
|
41
41
|
"yaml": "^2.7.0",
|
|
42
|
-
"zod": "^3.24.2"
|
|
42
|
+
"zod": "^3.24.2",
|
|
43
|
+
"express": "4.21.2"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
46
|
+
"@types/express": "^5.0.1",
|
|
45
47
|
"@types/js-yaml": "^4.0.9",
|
|
46
48
|
"@types/node": "^22.9.3",
|
|
47
49
|
"shx": "^0.3.4",
|