home / mcp / mcp code mode server

MCP Code Mode Server

code mode mcp

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "cexll-code-mode-mcp": {
      "command": "node",
      "args": [
        "/绝对路径/mcp-code-mode-demo/dist/server.js"
      ]
    }
  }
}

You can run and securely sandbox TypeScript code in this MCP server, exposing MCP tools through IPC so you can read, write, fetch, and interact with the filesystem or network from an isolated environment. This makes it easy to build tools that automate tasks while keeping execution safe.

How to use

Use this MCP server with your MCP client to execute TypeScript in a sandbox and call MCP tools like filesystem operations and network requests through IPC.

How to install

Prerequisites: make sure you have Node.js installed. The runtime configuration assumes Node is available on your system.

npm install

npm run generate-api

npm run build

npm test

Configuration and usage notes

Configure your environment so the MCP code mode server can be launched as part of your desktop tooling. The server runs in a sandbox and is integrated via IPC. Use an absolute path to the server entry when configuring the client.

{
  "mcpServers": {
    "code-mode": {
      "command": "node",
      "args": [
        "/绝对路径/mcp-code-mode-demo/dist/server.js"
      ],
      "description": "Execute TypeScript in sandbox with MCP tools"
    }
  }
}

Example usage patterns

Read a file from the sandboxed MCP server and parse JSON to access package details.

import * as fs from "./servers/filesystem/index.js";

const content = await fs.readFile({ path: "package.json" });
const pkg = JSON.parse(content);
console.log("Project:", pkg.name);

Write content to a file in the sandbox.

import * as fs from "./servers/filesystem/index.js";

await fs.writeFile({
  path: "output.txt",
  content: "Hello from Code Mode!"
});

List files in a directory inside the sandbox.

import * as fs from "./servers/filesystem/index.js";

const files = await fs.listDirectory({ path: "." });
console.log("Current directory:", files);

Make a network request from within the sandboxed environment.

import * as fetch from "./servers/fetch/index.js";

const response = await fetch.fetch({
  url: "https://api.github.com/repos/anthropics/claude-code"
});
const data = JSON.parse(response);
console.log("Stars:", data.stargazers_count);

Work principle

The Claude Desktop host communicates with a dedicated MCP server using a dedicated execute_code tool. The main and child processes coordinate via IPC to run user-provided TypeScript code in a sandbox, while MCP servers handle the actual tool calls like filesystem access or network requests.

Project structure

Key source files organize the MCP generator, sandbox, and server, with a generated API client in the generated-api folder.

Testing

Run the test suite to verify functionality and measure coverage.

npm test

npm run test:coverage

Core features

- IPC bridge for safe, inter-process MCP tool calls - Module resolution with automatic fallback for symlinks or copied directories - Full cross-platform support (macOS, Linux, Windows) - Extensive test coverage and production-grade isolation and cleanup - Ready for production with proper timeout handling and resource controls.

Troubleshooting

If the server cannot start, ensure the build was completed and that the entry file exists, and confirm you are using Node.js version 18 or newer.

If code execution fails, verify that the API was generated and that the generated API directory exists, and check import paths.

If the client cannot see the tools, confirm the configuration path is correct, absolute paths are used, and you have restarted the client after changes.

Sandbox safety

The sandbox restricts file system and network access to protect your system. Network access is limited to allowed domains, and sensitive files are protected from read or write operations.

Security notes and platform requirements

On macOS no extra dependencies are required. Linux requires bubblewrap, socat, and ripgrep. Always review and adjust sandbox permissions to fit your environment.

Available tools

readFile

Reads a file from the sandboxed filesystem and returns its contents as a string.

writeFile

Writes content to a file within the sandboxed filesystem.

listDirectory

Lists the contents of a directory inside the sandbox.

fetch

Performs a network request from within the sandbox and returns the response as a string.