@prodisco/k8s-mcp 0.1.4 → 0.1.6

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.
Files changed (45) hide show
  1. package/README.md +140 -23
  2. package/dist/server.js +190 -10
  3. package/dist/server.js.map +1 -1
  4. package/dist/tools/kubernetes/metadata.d.ts +118 -8
  5. package/dist/tools/kubernetes/metadata.d.ts.map +1 -1
  6. package/dist/tools/kubernetes/metadata.js +9 -2
  7. package/dist/tools/kubernetes/metadata.js.map +1 -1
  8. package/dist/tools/kubernetes/runSandbox.d.ts +121 -0
  9. package/dist/tools/kubernetes/runSandbox.d.ts.map +1 -0
  10. package/dist/tools/kubernetes/runSandbox.js +412 -0
  11. package/dist/tools/kubernetes/runSandbox.js.map +1 -0
  12. package/dist/tools/kubernetes/searchTools.d.ts +19 -3
  13. package/dist/tools/kubernetes/searchTools.d.ts.map +1 -1
  14. package/dist/tools/kubernetes/searchTools.js +145 -53
  15. package/dist/tools/kubernetes/searchTools.js.map +1 -1
  16. package/dist/util/paths.d.ts +5 -0
  17. package/dist/util/paths.d.ts.map +1 -1
  18. package/dist/util/paths.js +5 -0
  19. package/dist/util/paths.js.map +1 -1
  20. package/dist/util/summary.d.ts +10 -10
  21. package/package.json +13 -8
  22. package/dist/tools/api/apiTools.d.ts +0 -6
  23. package/dist/tools/api/apiTools.d.ts.map +0 -1
  24. package/dist/tools/api/apiTools.js +0 -132
  25. package/dist/tools/api/apiTools.js.map +0 -1
  26. package/dist/tools/kubernetes/searchTools-old.d.ts +0 -35
  27. package/dist/tools/kubernetes/searchTools-old.d.ts.map +0 -1
  28. package/dist/tools/kubernetes/searchTools-old.js +0 -414
  29. package/dist/tools/kubernetes/searchTools-old.js.map +0 -1
  30. package/dist/tools/kubernetes/searchTools-v2.d.ts +0 -35
  31. package/dist/tools/kubernetes/searchTools-v2.d.ts.map +0 -1
  32. package/dist/tools/kubernetes/searchTools-v2.js +0 -269
  33. package/dist/tools/kubernetes/searchTools-v2.js.map +0 -1
  34. package/dist/tools/kubernetes/typeDefinitions.d.ts +0 -24
  35. package/dist/tools/kubernetes/typeDefinitions.d.ts.map +0 -1
  36. package/dist/tools/kubernetes/typeDefinitions.js +0 -518
  37. package/dist/tools/kubernetes/typeDefinitions.js.map +0 -1
  38. package/dist/util/apiClient.d.ts +0 -20
  39. package/dist/util/apiClient.d.ts.map +0 -1
  40. package/dist/util/apiClient.js +0 -90
  41. package/dist/util/apiClient.js.map +0 -1
  42. package/dist/util/k8sClient.d.ts +0 -38
  43. package/dist/util/k8sClient.d.ts.map +0 -1
  44. package/dist/util/k8sClient.js +0 -85
  45. package/dist/util/k8sClient.js.map +0 -1
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # ProDisco (Progressive Disclosure Kubernetes MCP Server)
2
2
 
3
- ProDisco gives AI agents **Kubernetes access + Prometheus metrics analysis** through a single unified search tool. It follows Anthropic's [Progressive Disclosure](https://www.anthropic.com/engineering/code-execution-with-mcp) pattern: the MCP server exposes search tools which surface TypeScript modules, agents discover them to write code, and only the final console output returns to the agent.
3
+ ProDisco gives AI agents **Kubernetes access + Prometheus metrics analysis** through two unified tools. It follows Anthropic's [Progressive Disclosure](https://www.anthropic.com/engineering/code-execution-with-mcp) pattern: the MCP server exposes search tools which surface API methods, agents discover them to write code, execute it in a sandbox, and only the final console output returns to the agent.
4
4
 
5
- **One tool, two domains:**
6
- - **Kubernetes Operations** - Discover API methods from `@kubernetes/client-node` to manage pods, deployments, services, and more
7
- - **Prometheus Metrics** - Discover methods from `prometheus-query` for PromQL queries and metrics analysis
5
+ **Two tools:**
6
+ - **kubernetes.searchTools** - Discover API methods, type definitions, cached scripts, and Prometheus methods
7
+ - **kubernetes.runSandbox** - Execute TypeScript code in a sandboxed VM environment
8
8
 
9
9
  ## Why Progressive Disclosure Matters
10
10
 
@@ -20,11 +20,7 @@ ProDisco goes a step further: instead of exposing custom TypeScript modules, it
20
20
 
21
21
  ## Demo
22
22
 
23
- ### Kubernetes Operations
24
- ![Kubernetes Operations Demo](docs/demo.gif)
25
-
26
- ### Prometheus Queries
27
- ![Prometheus Queries Demo](docs/demo2.gif)
23
+ [![Watch the demo](https://img.youtube.com/vi/W-DyrsGRJeQ/maxresdefault.jpg)](https://www.youtube.com/watch?v=W-DyrsGRJeQ)
28
24
 
29
25
  ---
30
26
 
@@ -32,18 +28,21 @@ ProDisco goes a step further: instead of exposing custom TypeScript modules, it
32
28
 
33
29
  ### Add to Claude Code
34
30
 
35
- Add ProDisco to Claude Code with a single command:
31
+ Add ProDisco to Claude Code:
36
32
 
37
33
  ```bash
38
- claude mcp add ProDisco --env KUBECONFIG="${HOME}/.kube/config" -- npx -y @prodisco/k8s-mcp
34
+ # Set environment variables first (--env flag may not work reliably)
35
+ export KUBECONFIG="${HOME}/.kube/config"
36
+
37
+ # Then add the MCP server
38
+ claude mcp add ProDisco -- npx -y @prodisco/k8s-mcp
39
39
  ```
40
40
 
41
41
  **With Prometheus (optional):**
42
42
  ```bash
43
- claude mcp add ProDisco \
44
- --env KUBECONFIG="${HOME}/.kube/config" \
45
- --env PROMETHEUS_URL="http://localhost:9090" \
46
- -- npx -y @prodisco/k8s-mcp
43
+ export KUBECONFIG="${HOME}/.kube/config"
44
+ export PROMETHEUS_URL="http://localhost:9090"
45
+ claude mcp add ProDisco -- npx -y @prodisco/k8s-mcp
47
46
  ```
48
47
 
49
48
  Remove if needed:
@@ -58,12 +57,49 @@ claude mcp remove ProDisco
58
57
  | `K8S_CONTEXT` | No | Kubernetes context (defaults to current context) |
59
58
  | `PROMETHEUS_URL` | No | Prometheus server URL for metrics queries |
60
59
 
60
+ > **Important:** Export environment variables before running `claude mcp add`. The `--env` flag may not reliably pass variables to the MCP server process.
61
+
61
62
  > **Tip:** If you're using a kind cluster for local testing, you can port-forward to Prometheus:
62
63
  > ```bash
63
64
  > kubectl port-forward -n monitoring svc/prometheus-server 9090:80
64
65
  > ```
65
66
  > Then set `PROMETHEUS_URL="http://localhost:9090"`
66
67
 
68
+ ### Container Isolation (Advanced)
69
+
70
+ For stronger isolation, you can run the sandbox server in a Kubernetes cluster and connect to it via TCP instead of using the local subprocess.
71
+
72
+ **1. Deploy the sandbox server to your cluster:**
73
+ ```bash
74
+ # Build and load the image (for kind clusters)
75
+ docker build -f packages/sandbox-server/Dockerfile -t prodisco/sandbox-server:latest .
76
+ kind load docker-image prodisco/sandbox-server:latest
77
+
78
+ # Deploy
79
+ kubectl apply -f packages/sandbox-server/k8s/deployment.yaml
80
+
81
+ # Port-forward to access locally
82
+ kubectl -n prodisco port-forward service/sandbox-server 50051:50051
83
+ ```
84
+
85
+ **2. Configure the MCP server to use TCP transport:**
86
+ ```bash
87
+ export KUBECONFIG="${HOME}/.kube/config"
88
+ export SANDBOX_USE_TCP=true
89
+ export SANDBOX_TCP_HOST=localhost
90
+ export SANDBOX_TCP_PORT=50051
91
+ claude mcp add ProDisco -- npx -y @prodisco/k8s-mcp
92
+ ```
93
+
94
+ **Sandbox transport environment variables:**
95
+ | Variable | Default | Description |
96
+ |----------|---------|-------------|
97
+ | `SANDBOX_USE_TCP` | `false` | Use TCP instead of local subprocess |
98
+ | `SANDBOX_TCP_HOST` | `localhost` | Sandbox server host |
99
+ | `SANDBOX_TCP_PORT` | `50051` | Sandbox server port |
100
+
101
+ See [docs/grpc-sandbox-architecture.md](docs/grpc-sandbox-architecture.md) for full architecture details.
102
+
67
103
  ### Development Setup
68
104
 
69
105
  For local development:
@@ -77,17 +113,102 @@ claude mcp add --transport stdio prodisco -- node dist/server.js
77
113
  claude mcp remove prodisco # remove when you're done
78
114
  ```
79
115
 
80
- ### Scripts cache convention
116
+ ### Startup Options
81
117
 
82
- **Script Location:** `~/.prodisco/scripts/cache/`
118
+ | Flag | Description |
119
+ |------|-------------|
120
+ | `--clear-cache` | Clear the scripts cache before starting |
83
121
 
84
- ProDisco automatically creates a `~/.prodisco/scripts/cache/` directory in your home directory for storing helper scripts. This ensures scripts work from any directory and persist across sessions.
122
+ Example:
123
+ ```bash
124
+ node dist/server.js --clear-cache
125
+ ```
85
126
 
86
127
  ---
87
128
 
88
129
  ## Available Tools
89
130
 
90
- ProDisco exposes a single unified tool with four modes:
131
+ ProDisco exposes two tools:
132
+
133
+ ### kubernetes.runSandbox
134
+
135
+ Execute TypeScript code in a sandboxed environment for Kubernetes and Prometheus operations. Supports multiple execution modes for different use cases.
136
+
137
+ **Execution Modes:**
138
+
139
+ | Mode | Purpose | Key Parameters |
140
+ |------|---------|----------------|
141
+ | `execute` (default) | Blocking execution, waits for completion | `code` or `cached`, `timeout` |
142
+ | `stream` | Real-time output streaming | `code` or `cached`, `timeout` |
143
+ | `async` | Start execution, return immediately | `code` or `cached`, `timeout` |
144
+ | `status` | Get status/output of async execution | `executionId`, `wait`, `outputOffset` |
145
+ | `cancel` | Cancel a running execution | `executionId` |
146
+ | `list` | List active and recent executions | `states`, `limit`, `includeCompletedWithinMs` |
147
+
148
+ **Input:**
149
+ ```typescript
150
+ {
151
+ // Mode selection (default: 'execute')
152
+ mode?: 'execute' | 'stream' | 'async' | 'status' | 'cancel' | 'list';
153
+
154
+ // Execute/Stream/Async mode parameters
155
+ code?: string; // TypeScript code to execute directly
156
+ cached?: string; // Name of a cached script to run (from searchTools results)
157
+ timeout?: number; // Execution timeout in ms (default: 30000, max: 120000)
158
+
159
+ // Status/Cancel mode parameters
160
+ executionId?: string; // ID from async mode response
161
+ wait?: boolean; // Long-poll until completion (status mode)
162
+ outputOffset?: number; // Offset for incremental reads (status mode)
163
+
164
+ // List mode parameters
165
+ states?: ('pending' | 'running' | 'completed' | 'failed' | 'cancelled' | 'timeout')[];
166
+ limit?: number; // Max results (default: 10)
167
+ includeCompletedWithinMs?: number; // Include recent completions
168
+ }
169
+ ```
170
+
171
+ **Sandbox Environment:**
172
+ - `k8s` - Full `@kubernetes/client-node` library
173
+ - `kc` - Pre-configured KubeConfig instance
174
+ - `console` - Captured output (log, error, warn, info)
175
+ - `require()` - Whitelisted modules: `@kubernetes/client-node`, `prometheus-query`
176
+ - `process.env` - Environment variables (PROMETHEUS_URL, etc.)
177
+
178
+ **Examples:**
179
+ ```typescript
180
+ // Execute mode (default) - blocking execution
181
+ {
182
+ code: `
183
+ const api = kc.makeApiClient(k8s.CoreV1Api);
184
+ const pods = await api.listNamespacedPod({ namespace: 'default' });
185
+ console.log(\`Found \${pods.items.length} pods\`);
186
+ `
187
+ }
188
+
189
+ // Run a cached script
190
+ { cached: "script-2025-01-01T12-00-00-abc123.ts" }
191
+
192
+ // Stream mode - real-time output
193
+ { mode: "stream", code: "for(let i=0; i<5; i++) console.log(i)" }
194
+
195
+ // Async mode - start long-running task
196
+ { mode: "async", code: "longRunningTask()" }
197
+ // Returns: { executionId: "abc-123", state: "running", ... }
198
+
199
+ // Status mode - check async execution progress
200
+ { mode: "status", executionId: "abc-123", wait: true }
201
+
202
+ // Cancel mode - stop a running execution
203
+ { mode: "cancel", executionId: "abc-123" }
204
+
205
+ // List mode - show running executions
206
+ { mode: "list", states: ["running"], limit: 5 }
207
+ ```
208
+
209
+ ### kubernetes.searchTools
210
+
211
+ A unified search interface with four modes:
91
212
 
92
213
  | Mode | Purpose | Example |
93
214
  |------|---------|---------|
@@ -98,10 +219,6 @@ ProDisco exposes a single unified tool with four modes:
98
219
 
99
220
  For comprehensive documentation including architecture details and example workflows, see [docs/search-tools.md](docs/search-tools.md).
100
221
 
101
- ### kubernetes.searchTools
102
-
103
- A unified search interface for Kubernetes operations and metrics analysis.
104
-
105
222
  **Input:**
106
223
  ```typescript
107
224
  {
package/dist/server.js CHANGED
@@ -3,15 +3,20 @@ import { createRequire } from 'node:module';
3
3
  import * as path from 'node:path';
4
4
  import { fileURLToPath } from 'node:url';
5
5
  import * as fs from 'node:fs';
6
- import * as os from 'node:os';
6
+ import { spawn } from 'node:child_process';
7
7
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
8
8
  import { logger } from './util/logger.js';
9
9
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
10
10
  const require = createRequire(import.meta.url);
11
11
  const pkg = require('../package.json');
12
12
  import { searchToolsTool, warmupSearchIndex, shutdownSearchIndex } from './tools/kubernetes/searchTools.js';
13
+ import { runSandboxTool } from './tools/kubernetes/runSandbox.js';
14
+ import { getSandboxClient, closeSandboxClient } from '@prodisco/sandbox-server/client';
15
+ // Track the sandbox server subprocess
16
+ let sandboxProcess = null;
13
17
  import { PUBLIC_GENERATED_ROOT_PATH_WITH_SLASH, listGeneratedFiles, readGeneratedFile, } from './resources/filesystem.js';
14
18
  import { probeClusterConnectivity } from './kube/client.js';
19
+ import { SCRIPTS_CACHE_DIR } from './util/paths.js';
15
20
  const __filename = fileURLToPath(import.meta.url);
16
21
  const __dirname = path.dirname(__filename);
17
22
  const GENERATED_DIR = path.resolve(__dirname, 'tools/kubernetes');
@@ -19,10 +24,10 @@ const server = new McpServer({
19
24
  name: 'kubernetes-mcp',
20
25
  version: typeof pkg.version === 'string' ? pkg.version : '0.0.0',
21
26
  }, {
22
- instructions: 'Kubernetes operations via Progressive Disclosure. Use the kubernetes.searchTools tool to discover available operations. ' +
23
- 'The tool returns available Kubernetes API methods and a "paths.scriptsDirectory" for writing scripts. ' +
24
- 'Write scripts to scriptsDirectory and use bare imports: import * as k8s from \'@kubernetes/client-node\'. ' +
25
- 'The scriptsDirectory has a node_modules symlink that handles package resolution automatically.',
27
+ instructions: 'Kubernetes and Prometheus operations via Progressive Disclosure. ' +
28
+ 'Use kubernetes.searchTools to discover available APIs. ' +
29
+ 'Use kubernetes.runSandbox to execute TypeScript scripts directly. ' +
30
+ 'The sandbox provides: k8s, kc (pre-configured KubeConfig), console, and require("prometheus-query").',
26
31
  });
27
32
  // Expose generated TypeScript files as MCP resources using ResourceTemplate
28
33
  import { ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js';
@@ -157,7 +162,185 @@ server.registerTool(searchToolsTool.name, {
157
162
  };
158
163
  }
159
164
  });
165
+ // Register kubernetes.runSandbox tool for executing scripts in a sandboxed environment
166
+ server.registerTool(runSandboxTool.name, {
167
+ title: 'Kubernetes Run Sandbox',
168
+ description: runSandboxTool.description,
169
+ inputSchema: runSandboxTool.schema,
170
+ }, async (args) => {
171
+ const parsedArgs = await runSandboxTool.schema.parseAsync(args);
172
+ const result = await runSandboxTool.execute(parsedArgs);
173
+ // Build the output message based on mode
174
+ let text;
175
+ if ('error' in result && result.error && !('output' in result)) {
176
+ // Error result without output
177
+ text = `Error: ${result.error}`;
178
+ }
179
+ else if (result.mode === 'execute' || result.mode === 'stream') {
180
+ // Execution results with output
181
+ const execResult = result;
182
+ const cachedInfo = execResult.cachedScript ? ` [cached: ${execResult.cachedScript}]` : '';
183
+ if (execResult.success) {
184
+ text = `Execution successful${cachedInfo} (${execResult.executionTimeMs}ms)\n\nOutput:\n${execResult.output}`;
185
+ }
186
+ else {
187
+ text = `Execution failed${cachedInfo} (${execResult.executionTimeMs}ms)\n\nError: ${execResult.error}\n\nOutput:\n${execResult.output}`;
188
+ }
189
+ }
190
+ else if (result.mode === 'async') {
191
+ // Async mode - return execution ID
192
+ const asyncResult = result;
193
+ text = `${asyncResult.message}\n\nExecution ID: ${asyncResult.executionId}\nState: ${asyncResult.state}`;
194
+ }
195
+ else if (result.mode === 'status') {
196
+ // Status mode - return status and output
197
+ const statusResult = result;
198
+ const isComplete = statusResult.result !== undefined;
199
+ text = `Execution ${statusResult.executionId}\nState: ${statusResult.state}${isComplete ? ' (completed)' : ''}\n\nOutput:\n${statusResult.output}`;
200
+ if (statusResult.errorOutput) {
201
+ text += `\n\nErrors:\n${statusResult.errorOutput}`;
202
+ }
203
+ }
204
+ else if (result.mode === 'cancel') {
205
+ // Cancel mode
206
+ const cancelResult = result;
207
+ text = cancelResult.success
208
+ ? `Execution ${cancelResult.executionId} cancelled. State: ${cancelResult.state}`
209
+ : `Failed to cancel execution ${cancelResult.executionId}: ${cancelResult.message || 'Unknown error'}`;
210
+ }
211
+ else if (result.mode === 'list') {
212
+ // List mode
213
+ const listResult = result;
214
+ if (listResult.executions.length === 0) {
215
+ text = 'No executions found.';
216
+ }
217
+ else {
218
+ text = `Found ${listResult.totalCount} execution(s):\n\n`;
219
+ for (const exec of listResult.executions) {
220
+ text += `• ${exec.executionId} [${exec.state}]: ${exec.codePreview}\n`;
221
+ }
222
+ }
223
+ }
224
+ else {
225
+ // Fallback
226
+ text = JSON.stringify(result, null, 2);
227
+ }
228
+ return {
229
+ content: [
230
+ {
231
+ type: 'text',
232
+ text,
233
+ },
234
+ ],
235
+ structuredContent: result,
236
+ };
237
+ });
238
+ /**
239
+ * Check if TCP transport is configured via environment variables.
240
+ */
241
+ function isUsingTcpTransport() {
242
+ const envUseTcp = process.env.SANDBOX_USE_TCP;
243
+ if (envUseTcp === 'true' || envUseTcp === '1') {
244
+ return true;
245
+ }
246
+ // If TCP host or port is specified, assume TCP mode
247
+ if (process.env.SANDBOX_TCP_HOST || process.env.SANDBOX_TCP_PORT) {
248
+ return true;
249
+ }
250
+ return false;
251
+ }
252
+ /**
253
+ * Start the gRPC sandbox server.
254
+ * In TCP mode, connects to an existing remote sandbox server.
255
+ * In local mode (default), spawns a subprocess.
256
+ */
257
+ async function startSandboxServer() {
258
+ // If using TCP transport, connect to remote sandbox server instead of spawning subprocess
259
+ if (isUsingTcpTransport()) {
260
+ const host = process.env.SANDBOX_TCP_HOST || 'localhost';
261
+ const port = process.env.SANDBOX_TCP_PORT || '50051';
262
+ logger.info(`Connecting to remote sandbox server at ${host}:${port}...`);
263
+ const client = getSandboxClient(); // Will use TCP env vars automatically
264
+ const healthy = await client.waitForHealthy(10000);
265
+ if (!healthy) {
266
+ throw new Error(`Remote sandbox server at ${host}:${port} is not reachable`);
267
+ }
268
+ const healthStatus = await client.healthCheck();
269
+ logger.info(`Remote sandbox server is ready (context: ${healthStatus.kubernetesContext})`);
270
+ return;
271
+ }
272
+ // Local mode: spawn subprocess
273
+ const sandboxServerPath = path.resolve(__dirname, '../packages/sandbox-server/dist/server/index.js');
274
+ const socketPath = process.env.SANDBOX_SOCKET_PATH || '/tmp/prodisco-sandbox.sock';
275
+ logger.info('Starting sandbox gRPC server...');
276
+ sandboxProcess = spawn('node', [sandboxServerPath], {
277
+ stdio: ['ignore', 'pipe', 'pipe'],
278
+ env: {
279
+ ...process.env,
280
+ SANDBOX_SOCKET_PATH: socketPath,
281
+ SCRIPTS_CACHE_DIR,
282
+ },
283
+ });
284
+ // Log sandbox server output
285
+ sandboxProcess.stdout?.on('data', (data) => {
286
+ logger.info(`[sandbox] ${data.toString().trim()}`);
287
+ });
288
+ sandboxProcess.stderr?.on('data', (data) => {
289
+ logger.error(`[sandbox] ${data.toString().trim()}`);
290
+ });
291
+ sandboxProcess.on('error', (error) => {
292
+ logger.error('Sandbox server process error', error);
293
+ });
294
+ sandboxProcess.on('exit', (code, signal) => {
295
+ if (code !== 0 && code !== null) {
296
+ logger.error(`Sandbox server exited with code ${code}`);
297
+ }
298
+ else if (signal) {
299
+ logger.info(`Sandbox server terminated by signal ${signal}`);
300
+ }
301
+ sandboxProcess = null;
302
+ });
303
+ // Wait for the sandbox server to become healthy
304
+ const client = getSandboxClient({ socketPath });
305
+ const healthy = await client.waitForHealthy(10000);
306
+ if (!healthy) {
307
+ throw new Error('Sandbox server failed to start within timeout');
308
+ }
309
+ logger.info('Sandbox gRPC server is ready');
310
+ }
311
+ /**
312
+ * Stop the sandbox server subprocess (only in local mode).
313
+ */
314
+ function stopSandboxServer() {
315
+ closeSandboxClient();
316
+ // Only stop subprocess if running in local mode
317
+ if (sandboxProcess) {
318
+ logger.info('Stopping sandbox server...');
319
+ sandboxProcess.kill('SIGTERM');
320
+ sandboxProcess = null;
321
+ }
322
+ }
160
323
  async function main() {
324
+ // Parse command line arguments
325
+ const args = process.argv.slice(2);
326
+ const clearCache = args.includes('--clear-cache');
327
+ // Handle --clear-cache flag
328
+ if (clearCache) {
329
+ logger.info('Clearing scripts cache...');
330
+ try {
331
+ await fs.promises.rm(SCRIPTS_CACHE_DIR, { recursive: true, force: true });
332
+ logger.info('Scripts cache cleared');
333
+ }
334
+ catch (error) {
335
+ const message = error instanceof Error ? error.message : String(error);
336
+ logger.warn(`Failed to clear cache: ${message}`);
337
+ }
338
+ }
339
+ // Ensure scripts cache directory exists (server-controlled location)
340
+ await fs.promises.mkdir(SCRIPTS_CACHE_DIR, { recursive: true });
341
+ logger.info(`Scripts cache directory: ${SCRIPTS_CACHE_DIR}`);
342
+ // Start the sandbox gRPC server
343
+ await startSandboxServer();
161
344
  // Probe cluster connectivity before starting the server
162
345
  // This ensures we fail fast if the cluster is not reachable
163
346
  logger.info('Probing Kubernetes cluster connectivity...');
@@ -170,10 +353,6 @@ async function main() {
170
353
  logger.error(`Failed to connect to Kubernetes cluster: ${message}`);
171
354
  throw new Error(`Kubernetes cluster is not accessible: ${message}`);
172
355
  }
173
- // Ensure ~/.prodisco/scripts/cache/ directory exists (using async API for consistency)
174
- const scriptsDir = path.join(os.homedir(), '.prodisco', 'scripts', 'cache');
175
- await fs.promises.mkdir(scriptsDir, { recursive: true });
176
- logger.info(`Scripts directory: ${scriptsDir}`);
177
356
  // Pre-warm the Orama search index to avoid delay on first search
178
357
  await warmupSearchIndex();
179
358
  const transport = new StdioServerTransport();
@@ -182,11 +361,12 @@ async function main() {
182
361
  }
183
362
  /**
184
363
  * Graceful shutdown handler.
185
- * Stops the script watcher and cleans up resources.
364
+ * Stops the sandbox server, script watcher, and cleans up resources.
186
365
  */
187
366
  async function shutdown(signal) {
188
367
  logger.info(`Received ${signal}, shutting down gracefully...`);
189
368
  try {
369
+ stopSandboxServer();
190
370
  await shutdownSearchIndex();
191
371
  logger.info('Shutdown complete');
192
372
  process.exit(0);
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,C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