Skip to main content
Glama

js_exec

Execute JavaScript code in Node.js to manipulate JSON, use npm packages, and maintain persistent state across invocations.

Instructions

Execute JavaScript code in a full Node.js environment. Returns an object with keys: success (bool), output (combined stdout/stderr), stdout, stderr, exitCode, and outputTruncated (bool if output exceeded 100KB). Use this tool when: (1) manipulating JSON data where JavaScript's native handling is cleaner than Python, (2) testing algorithms where JS syntax is preferred, (3) using npm packages not available in Python, (4) working with Node.js-specific APIs. Do NOT use this tool when: (1) generating visualizations - Node.js has no DOM, canvas, or browser APIs (use python_exec with matplotlib instead), (2) the task is equally achievable in Python (prefer python_exec for consistency). The tool provides persistent state across calls via a state object that is automatically loaded from and saved to .shell0_js_state.json in the working directory. Assign values to state.myKey to persist them between invocations. Limitations: 30-second default timeout (configurable up to 600s), 100K character source limit, 2000 line limit, 100KB output cap. On timeout the process is killed. Syntax errors return in stderr with line numbers. Requires Node.js on PATH.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesJavaScript source code to execute. Supports require(), async/await, and ES6+ syntax. Use console.log() for output. Access persistent state via the `state` object (auto-loaded/saved). Example: `const data = require('fs').readFileSync('file.json'); console.log(JSON.parse(data));`
timeoutNoExecution timeout in seconds. Default: 30. Maximum: 600.
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description fully discloses behavior: return object structure, persistent state mechanism, timeouts, source/line limits, output cap, error handling, and requirement for Node.js on PATH. This is comprehensive.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Well-structured with clear sections (purpose, output, usage, state, limitations), but slightly verbose. Could tighten some examples, but overall effective.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no output schema and two parameters, the description covers all critical aspects: purpose, usage, output, state handling, and limitations, leaving no significant gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, but the description adds value by explaining state persistence and providing an example for the 'code' parameter, going beyond what the schema descriptions offer.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states that it 'Execute JavaScript code in a full Node.js environment' and provides four specific use cases (JSON manipulation, algorithms, npm packages, Node.js APIs) that distinguish it from siblings like python_exec and fs.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly tells when to use (four bullet points) and when NOT to use (two bullet points, e.g., visualizations and Python-preferred tasks), giving clear guidance on tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/cutlerbenjamin1-cmd/shell-0'

If you have feedback or need assistance with the MCP directory API, please join our Discord server