Many plugin and user MCP servers start with command: "node" or command: "npx". On a desktop
machine without Node.js these servers fail with spawn ENOENT. The desktop agent already runs on
the Node runtime inside Electron (docs/runtime-tools/agent-electron-node-runtime.md). This spec
lets stdio MCP servers use that same runtime, plus a bundled npm, when the machine has no Node.
The user's own Node, npm and npx always win. The fallback only fills a gap.
In scope:
node, npm and npx, at the top level (command) and inside the server's own
process tree (shebangs such as #!/usr/bin/env node, sh -c "node ...", npm bin shims).node fallback only
(see Bundled npm).Out of scope:
prependRunningNodeDirectory (the agent's real Node directory goes on PATH when PATH has no node).uvx, python, bun, deno).Desktop host (Electron utilityProcess)
└─ agent: <Electron> zcode.cjs app-server (ELECTRON_RUN_AS_NODE=1)
└─ MCP stdio spawn (MCP SDK → cross-spawn; resolves PATH + PATHEXT from the child env)
env.PATH = <user PATH> <delimiter> <cliStorageRoot>/node-fallback/v1
env.ZCODE_NODE_FALLBACK_EXEC_PATH = <Electron executable>
env.ZCODE_NODE_FALLBACK_NPM_ROOT = <bundled npm package root>
"node server.js" ─ user node on PATH? ── yes → user node
└─ no → shim node → <Electron> server.js
"npx -y pkg" ─ user npx on PATH? ── yes → user npx
└─ no → shim npx → <Electron> <npm>/bin/npx-cli.js
└─ pkg bin "#!/usr/bin/env node" → PATH → node (same rule)
process.versions.electron is defined). Otherwise the MCP adapter gets no provider and the env
is unchanged.CreateMcpAdapterOptions.nodeFallback).
The adapter does not detect Electron itself.timeoutMs
and its cancel signal. A timeout or a cancel fails the connection through the normal failure
path. A connection never stays connecting because preparation does not finish.warn and returns no fallback. Connections continue
with the unchanged env, so the user sees the normal spawn ENOENT failure.Location: <cliStorageRoot>/node-fallback/v1/. The v1 segment is the shim layout version. A
change to shim content must bump it, so a running shim file is never rewritten with new content.
Files:
| Platform | Files | Mode |
|---|---|---|
| POSIX | node, npm, npx |
0755 |
| Windows | node.cmd, npm.cmd, npx.cmd |
- |
Rules:
rename.npm/npx shims fail with
a clear message instead of ENOENT.Each shim:
ELECTRON_RUN_AS_NODE=1, then replaces itself with the Electron executable
(exec on POSIX; the last batch command on Windows, so the exit code passes through).npm/npx shims also set npm_config_update_notifier=false when the user has not set it. The
bundled npm must not ask the user to upgrade a global npm that does not exist.ELECTRON_RUN_AS_NODE=1 stays in the env of the MCP server's children on purpose. Node's
child_process.fork() and many tools spawn process.execPath, which is the Electron executable.
Without the variable those children would start a full Electron app.
The agent adds these variables only to stdio MCP child envs. The agent never reads them itself, and users do not configure them.
| Variable | Value | Used by | Missing |
|---|---|---|---|
ZCODE_NODE_FALLBACK_EXEC_PATH |
Absolute path of the agent's process.execPath (Electron) |
all shims | shim exits 127 |
ZCODE_NODE_FALLBACK_NPM_ROOT |
Absolute path of the bundled npm package root | npm, npx shims |
shim exits 127 |
ZCODE_NODE_FALLBACK_NPM_ROOT is omitted when no bundled npm is found.
Merge order for the stdio child env:
buildMcpStdioEnv (sanitized agent env, network passthrough, remote Node directory rule).env from its config.Step 3 runs after the server env, so a server that sets its own PATH still gets the fallback at
the end. The entry is not added twice.
PATH key on Windows: environment names are case-insensitive, so Path and PATH are the same
variable. Step 3 starts from the variant that was merged last (the server's value when it sets one),
removes every case variant, and writes exactly one key, PATH. The uppercase spelling is required:
{ PATH: process.env.PATH, ...env }. If the env still held only Path,
the child env would carry both keys.Path), but Node passes the
first key in sorted order (PATH, without the shim directory) to the child. The top-level command
starts, and every nested node (for example a package bin started by npx) fails.On POSIX only the exact key PATH is used.
packages/desktop/scripts/bundled-npm-assets.mjs
(npm@12.2.0). Its engines.node must accept the Electron Node version.node-linker=hoisted, so an npm package would
link npm/npx into the root node_modules/.bin and shadow every developer's own npm.prepare:agent-bundle downloads the registry tarball, checks its sha512, caches it in
node_modules/.cache/zcode-bundled-npm/, and copies the package into
bundled-agents/<platform>/glm/node-runtime/npm (resources glm/node-runtime/npm in the app).
The top-level docs/ and man/ directories are left out (npm help is not supported). License
files of npm and of its bundled dependencies stay in the copied tree.<dir>/node-runtime/npm for the entry file directory, then for the bundle
directory. There is no cwd candidate, so a workspace cannot inject its own npm.bin/npm-cli.js and bin/npx-cli.js exist.apps/zcode-cli/packages/cli/dist/zcode.cjs, which has no staged npm.
There the node shim works and the npm/npx shims exit 127 with the missing-variable message.info mcp.node_fallback.ready once per provider: binDir, hasNpm.warn mcp.node_fallback.unavailable once per provider: error message.spawn("node") without a shell. CreateProcess finds only node.exe, not
node.cmd. Top-level commands work (cross-spawn), and shells, npm bin shims and .cmd chains work.ELECTRON_RUN_AS_NODE=1 and
runs that app as plain Node.THIRD-PARTY-NOTICES.md inventory is generated from the pnpm
lockfile, so it does not list the bundled npm yet. The staged tree carries the license files.PATH override, and is a no-op without a provider. On Windows the merge writes one PATH key, and
both the command lookup (last key) and the child env (first sorted key) see the shim directory,
also when a host Path and a server PATH both exist.timeoutMs, and a cancel
during preparation fails it too.node, the shims run a script, run
npx --version and npm --version from the real npm package, and exit 127 when the env var is
missing. A real stdio MCP connection with command: "node" succeeds through the fallback.docs//man/, and fails when the npm entry files are missing.