This JavaScript MCP Server provides a robust environment for AI models to execute JavaScript code through the Model Context Protocol (MCP). The server supports various execution modes including one-time script execution, stateful REPL sessions, and TypeScript support.
To get started with the JavaScript MCP Server, follow these steps:
# Clone the repository
git clone https://github.com/yannbam/fresh-js-mcp.git
cd fresh-js-mcp
# Install dependencies
npm install
# Build the project
npm run build
The server can be started in different modes depending on your needs:
# Start the MCP server in standard mode
npm start
# Start in interactive REPL mode
node dist/index.js --interactive
# Start with named pipe interface
node dist/index.js --pipe
# See all options
node dist/index.js --help
This is the default mode which communicates via stdio using the Model Context Protocol.
Provides a REPL (Read-Eval-Print Loop) interface for direct user interaction, making it easier to test and debug your JavaScript code.
Uses named pipes for communication with external processes, allowing for integration with other applications.
The MCP server provides several powerful tools:
Run one-time JavaScript code and get the results:
// Example of using the 'execute' tool
{
"name": "execute",
"parameters": {
"code": "const result = 2 + 3; return result;"
}
}
Create and maintain stateful REPL sessions:
// Create a new session
{
"name": "createSession",
"parameters": {
"id": "my-session"
}
}
// Execute code in the session
{
"name": "executeInSession",
"parameters": {
"sessionId": "my-session",
"code": "let counter = 1; counter;"
}
}
// Later execution in the same session
{
"name": "executeInSession",
"parameters": {
"sessionId": "my-session",
"code": "counter += 1; counter;"
}
}
Work with multiple REPL sessions:
// List all active sessions
{
"name": "listSessions"
}
// Delete a session when you're done
{
"name": "deleteSession",
"parameters": {
"sessionId": "my-session"
}
}
The server supports TypeScript code execution with automatic transpilation and can dynamically import and use npm packages:
// TypeScript example
{
"name": "execute",
"parameters": {
"code": "const greeting: string = 'Hello, TypeScript!'; return greeting;"
}
}
// Using NPM packages
{
"name": "execute",
"parameters": {
"code": "const _ = require('lodash'); return _.chunk(['a', 'b', 'c', 'd'], 2);"
}
}
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "fresh-js-mcp" '{"command":"node","args":["dist/index.js"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"fresh-js-mcp": {
"command": "node",
"args": [
"dist/index.js"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"fresh-js-mcp": {
"command": "node",
"args": [
"dist/index.js"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect