You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(code): add evaluate_script tool for JavaScript script execution
Add a new MCP tool that enables LLMs to execute JavaScript scripts with
direct access to Kubernetes clients. This allows complex operations that
require multiple API calls, data transformation, filtering, or aggregation
to be performed efficiently in a single tool call.
Key features:
- JavaScript execution via Goja (pure Go ES5.1+ engine)
- Access to typed Kubernetes clients (CoreV1, AppsV1, BatchV1, etc.)
- Transparent metadata flattening for standard K8s YAML/JSON structure
- Case-insensitive method resolution (CoreV1/coreV1, Pods/pods, List/list)
- SDK introspection support for API discovery
- Configurable execution timeout (default 30s, max 5min)
- Sandboxed environment with no file system or network access
The tool is designed to be lenient and model-friendly:
- Models can use familiar Kubernetes structure with metadata wrapper
- Both uppercase and lowercase method names are supported
- Automatic conversion handles the Go struct format requirements
Signed-off-by: Marc Nuri <marc@marcnuri.com>
Copy file name to clipboardExpand all lines: README.md
+113-1Lines changed: 113 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,6 +35,7 @@ A powerful and flexible Kubernetes [Model Context Protocol (MCP)](https://blog.m
35
35
-**List** Helm releases in all namespaces or in a specific namespace.
36
36
-**Uninstall** a Helm release in the current or provided namespace.
37
37
-**🔭 Observability**: Optional OpenTelemetry distributed tracing and metrics with custom sampling rates. Includes `/stats` endpoint for real-time statistics. See [OTEL.md](docs/OTEL.md).
38
+
-**💻 Code Evaluation**_(opt-in with `--toolsets code`)_: Execute JavaScript scripts with direct access to Kubernetes clients for complex operations, data transformation, and aggregation in a single tool call.
38
39
39
40
Unlike other Kubernetes MCP server implementations, this **IS NOT** just a wrapper around `kubectl` or `helm` command-line tools.
40
41
It is a **Go-based native implementation** that interacts directly with the Kubernetes API server.
@@ -431,6 +432,7 @@ The following sets of tools are available (toolsets marked with ✓ in the Defau
| code | Execute JavaScript code with access to Kubernetes clients for advanced operations and data transformation (opt-in, security-sensitive) ||
434
436
| config | View and manage the current local Kubernetes configuration (kubeconfig) | ✓ |
435
437
| core | Most common tools for Kubernetes management (Pods, Generic Resources, Events, etc.) | ✓ |
436
438
| kcp | Manage kcp workspaces and multi-tenancy features ||
@@ -448,6 +450,116 @@ In case multi-cluster support is enabled (default) and you have access to multip
448
450
449
451
<details>
450
452
453
+
<summary>code</summary>
454
+
455
+
-**evaluate_script** - Execute a JavaScript script with access to Kubernetes clients. Use this tool for complex operations that require multiple API calls, data transformation, filtering, or aggregation that would be inefficient with individual tool calls. The script runs in a sandboxed environment with access only to Kubernetes clients - no file system or network access.
456
+
457
+
458
+
## JavaScript SDK
459
+
460
+
**Note:** Full ES5.1 syntax support, partial ES6. Synchronous execution only (no async/await or Promises).
461
+
462
+
### Globals
463
+
-**k8s** - Kubernetes client (case-insensitive: coreV1, CoreV1, COREV1 all work)
464
+
-**ctx** - Request context for cancellation
465
+
-**namespace** - Default namespace
466
+
467
+
### k8s API Clients
468
+
- k8s.coreV1() - pods, services, configMaps, secrets, namespaces, nodes, etc.
0 commit comments