V8 JavaScript
STDIO支持持久化堆快照的V8 JavaScript执行环境
支持持久化堆快照的V8 JavaScript执行环境
A Rust-based Model Context Protocol (MCP) server that exposes a V8 JavaScript runtime as a tool for AI agents like Claude and Cursor. Supports persistent heap snapshots via S3 or local filesystem, and is ready for integration with modern AI development environments.
Install mcp-v8 using the provided install script:
curl -fsSL https://raw.githubusercontent.com/r33drichards/mcp-js/main/install.sh | sudo bash
This will automatically download and install the latest release for your platform to /usr/local/bin/mcp-v8 (you may be prompted for your password).
Advanced users: If you prefer to build from source, see the Build from Source section at the end of this document.
mcp-v8 supports the following command line arguments:
--s3-bucket <bucket>: Use AWS S3 for heap snapshots. Specify the S3 bucket name. (Conflicts with --stateless)--directory-path <path>: Use a local directory for heap snapshots. Specify the directory path. (Conflicts with --stateless)--stateless: Run in stateless mode - no heap snapshots are saved or loaded. Each JavaScript execution starts with a fresh V8 isolate. (Conflicts with --s3-bucket and --directory-path)--http-port <port>: Enable HTTP transport on the specified port. If not provided, the server uses stdio transport (default).--sse-port <port>: Enable SSE (Server-Sent Events) transport on the specified port. (Conflicts with --http-port)Note: For heap storage, if neither --s3-bucket, --directory-path, nor --stateless is provided, the server defaults to using /tmp/mcp-v8-heaps as the local directory.
After installation, you can run the server directly. Choose one of the following options:
# Use S3 for heap storage (recommended for cloud/persistent use) mcp-v8 --s3-bucket my-bucket-name # Use local filesystem directory for heap storage (recommended for local development) mcp-v8 --directory-path /tmp/mcp-v8-heaps # Use stateless mode - no heap persistence (recommended for one-off computations) mcp-v8 --stateless
The HTTP transport uses the HTTP/1.1 upgrade mechanism to switch from HTTP to the MCP protocol:
# Start HTTP server on port 8080 with local filesystem storage mcp-v8 --directory-path /tmp/mcp-v8-heaps --http-port 8080 # Start HTTP server on port 8080 with S3 storage mcp-v8 --s3-bucket my-bucket-name --http-port 8080 # Start HTTP server on port 8080 in stateless mode mcp-v8 --stateless --http-port 8080
The HTTP transport is useful for:
Server-Sent Events (SSE) transport for streaming responses:
# Start SSE server on port 8081 with local filesystem storage mcp-v8 --directory-path /tmp/mcp-v8-heaps --sse-port 8081 # Start SSE server on port 8081 in stateless mode mcp-v8 --stateless --sse-port 8081
--stateless)Stateless mode runs each JavaScript execution in a fresh V8 isolate without any heap persistence.
Benefits:
Example use case: Simple calculations, data transformations, or any scenario where you don't need to persist state between executions.
Stateful mode persists the V8 heap state between executions using either S3 or local filesystem storage.
Benefits:
Example use case: Building a data structure incrementally, maintaining session state, or reusing expensive computations.
claude_desktop_config.json:Stateful mode with S3:
{ "mcpServers": { "js": { "command": "/usr/local/bin/mcp-v8 --s3-bucket my-bucket-name" } } }
Stateless mode:
{ "mcpServers": { "js": { "command": "/usr/local/bin/mcp-v8 --stateless" } } }
.cursor/mcp.json in your project root:Stateful mode with local filesystem:
{ "mcpServers": { "js": { "command": "/usr/local/bin/mcp-v8 --directory-path /tmp/mcp-v8-heaps" } } }
Stateless mode:
{ "mcpServers": { "js": { "command": "/usr/local/bin/mcp-v8 --stateless" } } }
You can also use the hosted version on Railway without installing anything locally:
Option 1: Using Claude Settings
https://mcp-js-production.up.railway.app/sseOption 2: Using Claude Code CLI
claude mcp add mcp-v8 -t sse https://mcp-js-production.up.railway.app/sse
Then test by running claude and asking: "Run this JavaScript: [1,2,3].map(x => x * 2)"
1 + 2"You can configure heap storage using the following command line arguments:
--s3-bucket <bucket>
mcp-v8 --s3-bucket my-bucket-name--directory-path <path>
mcp-v8 --directory-path /tmp/mcp-v8-heaps--stateless
mcp-v8 --statelessNote: Only one storage option can be used at a time. If multiple are provided, the server will return an error.
While mcp-v8 provides a powerful and persistent JavaScript execution environment, there are limitations to its runtime.
async/await or Promises: Asynchronous JavaScript is not supported. All code must be synchronous.fetch or network access: There is no built-in way to make HTTP requests or access the network.console.log or standard output: Output from console.log or similar functions will not appear. To return results, ensure the value you want is the last line of your code.npm install or external packages: You cannot install or import npm packages. Only standard JavaScript (ECMAScript) built-ins are available.setTimeout and setInterval are not available.window, document, or other browser-specific objects.If you prefer to build from source instead of using the install script:
cd server cargo build --release
The built binary will be located at server/target/release/server. You can use this path in the integration steps above instead of /usr/local/bin/mcp-v8 if desired.