MCP / Config

Missing environment variable - MCP server startup

The MCP config references a server that needs secrets or settings, but the host process did not inherit them.

MCP missing env varMCP API key is requiredMCP server environment variables
Paste an error to match it against the wiki. / 粘贴报错后自动匹配。

Error text / 报错原文

  • Missing environment variable
  • env var is required
  • API key is required

What it means

The MCP config references a server that needs secrets or settings, but the host process did not inherit them.

Most common causes

  • Variable exists in an interactive shell but not in the IDE app
  • Windows environment variable not restarted into the process
  • Docker container lacks env mapping
  • Config uses the wrong variable name

Fastest fix

  • Print the variable from the same shell that starts the host
  • Restart the IDE after setting env vars
  • Add env mapping to the MCP server config
  • Validate variable names and casing

Safe fix

  • Use a secret manager or local untracked env file
  • Keep an example env file with placeholders
  • Fail closed with a clear error
  • Avoid logging full secret values

What not to do

  • Do not commit real .env files
  • Do not echo full tokens into public terminals
  • Do not set secrets globally when project scope is enough

How to confirm the fix

Run the smallest reproducible command first, then retry the agent task only after authentication, quota, and tool discovery are stable.

env | sort
node -e "console.log(process.env)"
git status --ignored --short

Related errors

Related tools

Sources