Skip to content

feat(code): add evaluate_script tool for JavaScript script execution#711

Open
manusa wants to merge 1 commit intocontainers:mainfrom
marcnuri-forks:poc/code-mode
Open

feat(code): add evaluate_script tool for JavaScript script execution#711
manusa wants to merge 1 commit intocontainers:mainfrom
marcnuri-forks:poc/code-mode

Conversation

@manusa
Copy link
Member

@manusa manusa commented Jan 29, 2026

Fixes #710

Demo: https://www.youtube.com/watch?v=IOBhSkA9NSE

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

@Cali0707
Copy link
Collaborator

This is really cool @manusa !!

Will dig into the code more later, just curious if you have any thoughts yet on how we can enforce the access controls we have on the rest of the tools through this code mode approach/if that is even something we should bother with

@manusa
Copy link
Member Author

manusa commented Jan 29, 2026

Will dig into the code more later, just curious if you have any thoughts yet on how we can enforce the access controls we have on the rest of the tools through this code mode approach/if that is even something we should bother with

:) That's already taken care of :)

Don't dig into the code yet, it needs a lot of polishing.

The main advantage of this code mode as opposed to using kubectl, ProDisco, or anything else, is that all of the features we built on top of the Kubernetes MCP server are leveraged by default (Logging, Access Control, Multi-Cluster, Telemetry...)

@manusa manusa force-pushed the poc/code-mode branch 17 times, most recently from d1cac85 to ecd21ae Compare January 30, 2026 15:17
@manusa manusa marked this pull request as ready for review January 30, 2026 16:34
@manusa manusa changed the title feat(code): add code_evaluate tool for JavaScript script execution feat(code): add evaluate_script tool for JavaScript script execution Jan 30, 2026
@manusa
Copy link
Member Author

manusa commented Jan 30, 2026

I believe this is ready enough for review and consideration.

As I keep trying new prompts I find there are areas with potential for further refinements, but these can be addressed in upcoming PRs if we find the feature interesting enough to include it in the server.

@manusa manusa added this to the 0.1.0 milestone Jan 31, 2026
@manusa manusa force-pushed the poc/code-mode branch 2 times, most recently from 7c3ed64 to 062a8f3 Compare February 16, 2026 10:55
@manusa manusa force-pushed the poc/code-mode branch 3 times, most recently from e3d0d06 to a4b0cb0 Compare February 23, 2026 14:08
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code Mode - Script Evaluation Tool for Dynamic LLM-Generated Code

2 participants