node-code-mode MCP server
Commit Oct 23, 2026Reduces LLM context usage by allowing models to execute JavaScript programs to interact with multiple MCP servers through a single tool.
Also known as a-saeedia/node-code-mode
- Stars
- 0
- Tools
- —
- Downloads, 30 days
- —
- Latest version
- —
- Last commit
- Oct 23, 2026
- License
- MIT
What is node-code-mode MCP?
node-code-mode reduces LLM context usage by allowing models to execute JavaScript programs to interact with multiple MCP servers through a single tool.
Summary generated from the project's README
About node-code-mode MCP server
Developers using multiple MCP servers can reduce context window usage by using this tool to execute JavaScript programs instead of loading every tool schema into every request. By providing a single code tool, it allows an AI client to interact with various connected servers through a unified sandbox. This approach prevents the massive token inflation that occurs when dozens of tools from different servers are advertised to the model simultaneously.
The server runs locally via npx and integrates with Claude Desktop, Claude Code, OpenCode, Cursor, and VS Code. It uses a node:vm sandbox to provide a controlled environment where the model can use functions like fs_read, fs_glob, and mcp_call to perform complex tasks. While it hides most servers from the model's immediate context to save tokens, those servers remain reachable through explicit calls. Users can configure environment variables like CLOUDFLARE_API_TOKEN to enable specific network capabilities within the execution environment.
What you can do with it
- 1Minimize token consumptionReduce the number of tokens sent to the model by replacing many tool schemas with a single execution tool.
- 2Batch file operationsWrite a small JavaScript program to scan a directory and identify specific files based on their content.
- 3Audit MCP configurationsMeasure exactly how many tokens and bytes your current MCP server setup is consuming.
- 4Execute multi-step workflowsPerform a sequence of file reads and JSON parsing in a single round trip to the model.
Written from the project's README. Every use case is checked against a quote from it.
README
View on GitHubnode-code-mode
One MCP tool in front of all your MCP servers. Cloudflare's Code Mode pattern, running on Node instead of Workers.
npx -y node-code-mode --stats
Status: published on npm, running on my own machine. Unpolished in places, but every number below was measured on a real config.
The problem
Every MCP server you connect gets its schemas pasted into the context on every request. From my own config, with four servers turned off:
8 MCP servers 113 tools 174,406 bytes ~43,602 tokens
node-code-mode 1 tool 6,524 bytes ~1,631 tokens
43k tokens before the model has done anything, and it grows with each server you install (github alone was 120 KB). The --stats command below measures your own config instead of trusting mine.
With the code tool the model writes one program per task:
const files = await codemode.fs_glob({ pattern: '*/package.json' });
const stale = [];
for (const f of files) {
const pkg = JSON.parse(await codemode.fs_read({ path: f }));
if (!pkg.description) stale.push(f);
}
return { total: files.length, stale };
One round trip, one small object back. Everything else stays on disk and in the process.
Install
npx -y node-code-mode
Claude Desktop / Claude Code:
{
"mcpServers": {
"codemode": {
"command": "npx",
"args": ["-y", "node-code-mode"]
}
}
}
OpenCode:
{
"mcp": {
"codemode": {
"type": "local",
"command": ["npx", "-y", "node-code-mode"],
"enabled": true
}
}
}
Cursor and VS Code take the same shape (servers in .vscode/mcp.json, mcpServers in .mcp.json).
Then stop advertising the servers you don't want in context. They remain reachable through codemode.mcp_call({ server, tool, args }). Disabled means hidden, not gone.
The audit
--stats reads your real config, boots each server, and counts what you're actually sending:
server tools bytes tokens
----------------------------------------------------------------------------
· higgsfield 48 182757 45689 ██████████████████████████████
github 44 120572 30143 ████████████████████
director 26 19725 4931 ███
· playwright 24 18502 4626 ███
----------------------------------------------------------------------------
TOTAL POOLED 282 441280 110320
· = not advertised (still reachable through codemode.mcp_call)
ADVERTISED: 113 tools, 174,406 bytes ≈ 43,602 tokens
WITH CODEMODE: 1 tool ≈ 1,631 tokens
You are paying ~43,602 tokens per turn for tools you did not call.
--stats --json for anything that isn't a human.
Sandbox API
Every function takes one object. All of it hangs off a single codemode namespace inside the sandbox.
| group | functions |
|---|---|
| shell / files | shell, fs_read, fs_write, fs_append, fs_exists, fs_stat, fs_list, fs_glob, fs_grep, fs_remove, fs_mkdir |
| network | http, http_json |
| MCP | mcp_list, mcp_tools, mcp_call |
| Cloudflare | cf_get, cf_post, cf_patch, cf_put, cf_del, cf_request (only with CLOUDFLARE_API_TOKEN) |
| Moli | moli_fetch (only with MOLI_BIN) |
| globals | sleep(ms), env, ROOT, log() |
Whatever the program returns is the only thing sent back. console.log is captured in logs, never returned to the model, so progress has to be part of the return value.
Config
Looks for the first of these:
--config <path>orCODEMODE_CONFIG./.mcp.json~/.config/opencode/opencode.jsonc- Claude Desktop config, any platform
It reads mcpServers (Claude), mcp (OpenCode) and servers (VS Code), including JSONC comments and {env:VAR} interpolation.
npx -y node-code-mode --print-config
| env | effect |
|---|---|
CODEMODE_ROOT |
base directory for relative fs paths (default: home) |
CODEMODE_TIMEOUT_MS |
wall clock limit per call (default 120000) |
CODEMODE_DEBUG=1 |
forward pooled-server stderr |
CLOUDFLARE_API_TOKEN, CLOUDFLARE_ACCOUNT_ID |
enables cf_* |
MOLI_BIN |
enables moli_fetch |
Security
Each call gets a fresh Node child process that exits afterwards. The sandbox is node:vm with no require, import, process or filesystem; the proxies above are its entire capability set.
node:vm is not a security boundary. Escapes exist, and the proxies are real: shell runs commands, fs_write writes files, http opens sockets. The model can do anything you can do in a terminal, which is the same deal every coding agent offers. If that's not acceptable, run the whole thing in a container.
No credentials are read from disk. They come from the environment.
Numbers
Same task both ways, three runs, median, Windows 11 / Node 22:
| round trips | bytes to the model | tokens | wall time | |
|---|---|---|---|---|
| 5 tool calls | 5 | 41,812 | 10,453 | 2,240 ms |
1 code call |
1 | 145 | 36 | 2,733 ms |
About half a second slower locally, 288× less context. Each skipped round trip is a full model call, so on a real task the difference is seconds, not milliseconds.
Limitations
- No streaming. One result at the end; long jobs look like a hang.
- Plain JavaScript. No TypeScript, no imports.
- Cold start around 1.5 s, then 250 to 500 ms per call from process spawn and IPC.
- stdio on the server side only. Upstream servers can be stdio or HTTP.
- Pinned to
@cloudflare/codemode@0.5.5. Upstream is Workers-first and a minor bump can add acloudflare:workersimport that Node cannot load (#2142). Upgrade deliberately and run the tests.
Prior art
@cloudflare/codemode supplies the type generation, tool description, result unwrapping and truncation. This repo supplies the executor and the server. The protocol idea comes from UTCP's code-mode, which is more ambitious and framework-agnostic.
MIT.
node-code-mode MCP questions
Is the execution environment secure?
The sandbox uses node:vm, but it is not a complete security boundary because the provided proxies allow shell, filesystem, and network access.
What are the programming limitations in the sandbox?
The sandbox supports plain JavaScript only; it does not support TypeScript or imports.