Six ${VAR} forms, five .mcp.json fields, two tiny servers: what Claude Code MCP expansion actually produced
I put six environment-variable forms into the args , env and command fields of one project .mcp.json (plus url and headers on a second, HTTP server) and read back what the server process actually received. On Claude Code 2.1.278, ${VAR} and ${VAR:-default} expanded everywhere, $VAR never expanded anywhere, an unset ${VAR} arrived as the literal text, and a nested ${A:-${B}} expanded only in…
Six environment-variable forms were applied to a single .mcp.json file, along with five potential fields for expansion: command, args, env, url, and headers. The experiment was conducted using Claude Code version 2.1.278, which supports ${VAR} and ${VAR:-default} syntaxes, but fails to expand $VAR and handle nested ${A:-${B}} expansions.
A simple stdio MCP server was created to test these behaviors by exposing process.argv and process.env. The server reported its own command line arguments and environment variables as newline-delimited JSON-RPC over stdin/stdout. Upon running the server through Claude Code, the results showed that ${VAR} and ${VAR:-default} expanded as intended, while $VAR remained unexpanded.
A nested ${A:-${B}} expansion only occurred in the headers field, demonstrating that not all five fields behaved identically in terms of variable expansion.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.