Overview
The JavaScript tools allow you to run arbitrary JavaScript code, install packages, execute npm modules, and manage long-running background JavaScript processes.Supported Runtimes
- Node.js - Always available (uses
process.execPath) - Bun - Automatically detected if installed
- Auto detection - Prefers Bun if available, falls back to Node.js
Package Managers
- bun -
bun add,bun x - pnpm -
pnpm add,pnpm dlx - yarn -
yarn add,yarn dlx - npm -
npm install,npx
run_js
Run arbitrary JavaScript code in a local runtime (Node.js or Bun) and return stdout/stderr/exit details.Parameters
The full JavaScript code to execute.
Optional argv passed to the script (accessible via
process.argv).Optional working directory for script execution.
Optional timeout in seconds (max 1200).
Keep generated script file on disk for debugging.
Runtime:
auto, node, or bun.Script format:
module (ESM) or commonjs (CJS).Usage Examples
install_js_packages
Install JavaScript packages using available package managers.Parameters
Package names to install (e.g.,
["express", "[email protected]"]).Extra package-manager-specific arguments.
Install as dev dependencies.
Package manager:
auto, bun, pnpm, yarn, or npm.Optional working directory.
Optional timeout in seconds (max 1200).
Usage Examples
run_js_module
Run a JavaScript module or binary with package-manager executors (bunx/pnpm dlx/yarn dlx/npx).Parameters
Module or package binary to run (e.g.,
prettier, eslint, create-next-app).Optional arguments passed to the module.
Executor manager:
auto, bun, pnpm, yarn, or npm.Optional working directory.
Optional timeout in seconds (max 1200).
Usage Examples
Background JavaScript Execution
start_background_js
Start a JavaScript script in the background and return a session ID for later interaction.Parameters
Full JavaScript code to execute in the background.
Optional argv passed to the script.
Optional working directory for script execution.
Keep generated script file on disk after process exit.
Runtime:
auto, node, or bun.Script format:
module or commonjs.Optional friendly label for this background session.
When true, reuse an existing running session with the same
session_name and cwd.Usage Example
read_background_js
Read buffered stdout/stderr from a running or exited background JS session.Parameters
Session ID returned by
start_background_js.Max characters per stream to return (max 120000).
Stream selector:
both, stdout, or stderr.When true, do not advance the internal read cursor.
Usage Example
write_background_js
Write input text to stdin of a running background JS session.Parameters
Session ID returned by
start_background_js.Text to write to stdin.
Append newline to input before writing.
Usage Example
stop_background_js
Stop a background JS session.Parameters
Session ID returned by
start_background_js.When true, send SIGKILL. Default false (SIGTERM).
Usage Example
list_background_js
List known background JS sessions and their state.Parameters
Include exited sessions.
Usage Example
Stream Management
Background JavaScript sessions buffer output in circular buffers:- Max buffer size: 300,000 characters per stream
- Default read size: 8,000 characters
- Max read size: 120,000 characters
- Read cursor: Tracks position in stream, only returns new data on subsequent reads
- Peek mode: Read without advancing cursor
Session Reuse
Whenreuse_session: true (default) and a session_name is provided, start_background_js will:
- Check for an existing running session with the same name and cwd
- Return the existing session ID instead of starting a new process
- Prevent duplicate processes when called multiple times