mcp-server-kubernetes 0.3.2 → 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 CHANGED
@@ -118,76 +118,36 @@ bun run build
118
118
  4. Local Testing with [Inspector](https://github.com/modelcontextprotocol/inspector)
119
119
 
120
120
  ```bash
121
- npx @modelcontextprotocol/inspector node build/index.js
121
+ npx @modelcontextprotocol/inspector node dist/index.js
122
122
  # Follow further instructions on terminal for Inspector link
123
123
  ```
124
124
 
125
- 5. Local testing with [mcp-chat](https://github.com/Flux159/mcp-chat)
125
+ 5. Local testing with Claude Desktop
126
126
 
127
- ```bash
128
- npm run chat
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
+ }
129
136
  ```
130
137
 
131
- ### Project Structure
138
+ 6. Local testing with [mcp-chat](https://github.com/Flux159/mcp-chat)
132
139
 
140
+ ```bash
141
+ npm run chat
133
142
  ```
134
- ├── src/
135
- │ ├── index.ts # Main server implementation
136
- │ ├── types.ts # Type re-exports
137
- │ ├── config/ # Configuration files
138
- │ │ ├── container-templates.ts # Container configurations
139
- │ │ ├── server-config.ts # Server settings
140
- │ │ ├── deployment-config.ts # Deployment schemas
141
- │ │ ├── namespace-config.ts # Namespace schemas
142
- │ │ └── cleanup-config.ts # Resource cleanup configuration
143
- │ ├── models/ # Data models and schemas
144
- │ │ ├── response-schemas.ts # API response schemas
145
- │ │ ├── resource-models.ts # Resource models
146
- │ │ ├── tool-models.ts # Tool schemas
147
- │ │ ├── helm-models.ts # Helm operation schemas
148
- │ │ └── kubectl-models.ts # Kubectl operation schemas
149
- │ ├── utils/ # Utility classes
150
- │ │ └── kubernetes-manager.ts # K8s management
151
- │ ├── resources/ # Resource handlers
152
- │ │ └── handlers.ts # Resource implementation
153
- │ └── tools/ # Tool implementations
154
- │ ├── list_pods.ts # Pod listing operations
155
- │ ├── list_services.ts # Service listing operations
156
- │ ├── list_deployments.ts # Deployment listing operations
157
- │ ├── list_nodes.ts # Node listing operations
158
- │ ├── create_pod.ts # Pod creation operations
159
- │ ├── delete_pod.ts # Pod deletion operations
160
- │ ├── describe_pod.ts # Pod description operations
161
- │ ├── get_logs.ts # Container logs operations
162
- │ ├── get_events.ts # Kubernetes events operations
163
- │ ├── helm-operations.ts # Helm chart operations
164
- │ └── kubectl-operations.ts # Kubectl utility operations
165
- ├── tests/ # Test files
166
- │ ├── unit.test.ts # Unit tests for basic operations
167
- │ ├── helm.test.ts # Helm-specific tests
168
- │ └── kubectl.test.ts # Kubectl-specific tests
169
- ├── .github/ # GitHub configuration
170
- │ └── workflows/ # CI/CD workflows
171
- │ ├── ci.yml # Continuous integration
172
- │ └── cd.yml # Continuous deployment
173
- ├── Dockerfile # Docker container definition
174
- ├── LICENSE # MIT license
175
- ├── README.md # Project documentation
176
- ├── package.json # NPM package configuration
177
- ├── tsconfig.json # TypeScript configuration
178
- └── vitest.config.ts # Test configuration
179
- ```
180
143
 
181
- ### Contributing
144
+ ## Contributing
145
+
146
+ See the [CONTRIBUTING.md](CONTRIBUTING.md) file for details.
182
147
 
183
- 1. Fork the repository
184
- 2. Create a feature branch
185
- 3. Make your changes
186
- 4. Add tests for new functionality
187
- 5. Ensure all tests pass
188
- 6. Submit a pull request
148
+ ## Advanced
189
149
 
190
- For bigger changes please open an issue first to discuss the proposed changes.
150
+ For more advanced information like using SSE transport, see the [ADVANCED_README.md](ADVANCED_README.md).
191
151
 
192
152
  ## Architecture
193
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
- const transport = new StdioServerTransport();
141
- await server.connect(transport);
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,2 @@
1
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
+ export declare function startSSEServer(server: Server): void;
@@ -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.2",
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",