MCP server exits on start: missing environment variable

20 local (stdio) MCP servers we list exited at launch because an environment variable was not set, and each one printed what it wanted. Two more that we tested but did not list, Alpaca MCP and PagerDuty MCP, did the same.

Short answer

Put the variable the message names into the server's env block in your MCP config, then restart the client. A variable exported in one terminal is not there when a desktop client starts the server.

Last tested 2026-11-11

How we test: methodology. Context cost: lowest context cost MCP servers. Not tested by us: security, output quality, and behaviour with real credentials.

Symptom

The client shows the server as disconnected, or reports MCP error -32000: Connection closed, right after you add it. Run by hand, the server prints one line naming a variable such as an API key or token, then exits.

The exact errors we saw

ServerWhat it printed (verbatim)Where we saw itTested
Aiven MCP (official)
mcp-aiven 1.18.1
mcp-aiven: Fatal error: AIVEN_TOKEN environment variable is required.stderr at launch with no env vars set (process exited)2026-11-01
Apify (official)
@apify/actors-mcp-server 0.21.5
ERROR APIFY_TOKEN is required but not set in the environment variables or in ~/.apify/auth.jsonstderr at launch with no env vars set (process exited)2026-11-10
Appwrite MCP (official)
mcp-server-appwrite 2.2.3
[appwrite-mcp] ERROR: APPWRITE_PROJECT_ID and APPWRITE_API_KEY must be set in environment variablesstderr at launch with no env vars set (process exited)2026-10-31
Brave Search (legacy reference)
@modelcontextprotocol/server-brave-search 0.6.2
Error: BRAVE_API_KEY environment variable is requiredstderr at launch with no env vars set (process exited)2026-11-10
Brave Search (official)
@brave/brave-search-mcp-server 2.1.4
Error: A Brave API key is required via --brave-api-key, BRAVE_API_KEY, --brave-api-key-file, or BRAVE_API_KEY_FILE. You can get one at https://brave.com/search/api/.stderr at launch with no env vars set (process exited)2026-11-10
Currents
@currents/mcp 2.7.0
CURRENTS_API_KEY is not set. Add your Currents API key to the environment (for example: export CURRENTS_API_KEY=<your-key>).stderr at launch with no env vars set (process exited)2026-11-10
Datadog
@winor30/mcp-server-datadog 1.8.0
Error: DATADOG_API_KEY and DATADOG_APP_KEY must be setstderr at launch with no env vars set (process exited)2026-11-10
EduBase MCP (official)
@edubase/mcp 2.0.10
Error: EDUBASE_API_APP environment variable is required with this transport modestderr at launch with no env vars set (process exited)2026-11-01
ElevenLabs MCP (official, repo archived)
elevenlabs-mcp 0.12.2
ValueError: ELEVENLABS_API_KEY environment variable is requiredstderr at launch with no env vars set (process exited)2026-11-10
EverArt (legacy reference)
@modelcontextprotocol/server-everart 0.6.2
EVERART_API_KEY environment variable is not setstderr at launch with no env vars set (process exited)2026-11-10
Figma Context MCP (Framelink)
figma-developer-mcp 0.13.2
Either FIGMA_API_KEY or FIGMA_OAUTH_TOKEN is required (via CLI argument or .env file)stderr at launch with no env vars set (process exited)2026-11-10
GitLab (legacy reference)
@modelcontextprotocol/server-gitlab 2025.4.25
GITLAB_PERSONAL_ACCESS_TOKEN environment variable is not setstderr at launch with no env vars set (process exited)2026-11-10
GitLab (zereight)
@zereight/mcp-gitlab 2.3.22
GITLAB_PERSONAL_ACCESS_TOKEN environment variable is not setstderr at launch with no env vars set (process exited)2026-11-10
Google Maps (legacy reference)
@modelcontextprotocol/server-google-maps 0.6.2
GOOGLE_MAPS_API_KEY environment variable is not setstderr at launch with no env vars set (process exited)2026-11-10
LINE Bot (official)
@line/line-bot-mcp-server 0.5.0
Please set CHANNEL_ACCESS_TOKENstderr at launch with no env vars set (process exited)2026-11-10
Obsidian
mcp-obsidian 0.2.3
ValueError: OBSIDIAN_API_KEY environment variable required.stderr at launch with no env vars set (process exited)2026-11-10
Perplexity (official)
@perplexity-ai/mcp-server 1.3.0
Error: PERPLEXITY_API_KEY environment variable is requiredstderr at launch with no env vars set (process exited)2026-11-10
Postman MCP Server (official)
@postman/postman-mcp-server 2.15.0
Invalid environment variables for Postman MCP server: { _errors: [], POSTMAN_API_KEY: { _errors: [ 'Required' ] } }stderr at launch with no env vars set (process exited)2026-10-30
Slack (legacy reference)
@modelcontextprotocol/server-slack 2025.4.25
Please set SLACK_BOT_TOKEN and SLACK_TEAM_ID environment variablesstderr at launch with no env vars set (process exited)2026-11-10
Webflow MCP Server (official)
webflow-mcp-server 1.0.0
Error: WEBFLOW_TOKEN is missingfirst stderr line, recaptured by re-running the same launch command with no env vars (process exited)2026-10-28
Alpaca MCP (not listed on TestedMCP)
alpaca-mcp-server 2.4.1
Error: ALPACA_API_KEY and ALPACA_SECRET_KEY must be set.stderr at launch (exited code 1)2026-11-11
PagerDuty MCP (not listed on TestedMCP)
pagerduty-mcp 1.1.0
RuntimeError: An API key is required to call the PagerDuty API.last stderr line at launch (exited code 1)2026-11-11

Bitbucket MCP 5.0.6 (not listed on TestedMCP) also exits at start without credentials. Our test note: exits at start without BITBUCKET_TOKEN or username/password. Its stored stderr kept only the stack trace, so it has no row here.

Cause

These servers check for credentials before the MCP handshake and exit if one is missing. An MCP client starts a local server as a child process and talks to it over stdin and stdout (MCP spec, stdio transport). The server only sees the environment the client gives it, so a variable you exported in a terminal is not there when a desktop client starts the server.

Fix

  1. Add an env block to the server's entry in your MCP config, using the exact name from the message:
    {
      "mcpServers": {
        "example": {
          "command": "npx",
          "args": [
            "-y",
            "<package>"
          ],
          "env": {
            "EXAMPLE_API_KEY": "<your key>"
          }
        }
      }
    }
    not tested by us: we have not run these servers with real keys.
  2. Restart the client so it starts the server again with the new environment, then check that tools are listed. not tested by us
  3. Keep keys out of git. See how to protect AI API keys, which covers the scanners and vaults we did test.

Affected listings

Each listing's setup section names its variables. All servers that stop at a credential check: MCP servers that need an API key.

More troubleshooting: all troubleshooting pages · MCP error -32000: Connection closed · MCP servers that need an API key or sign-in. Quotes are verbatim from our own test logs (colour codes removed; a trailing … marks a shortened line). We have not run these servers inside Claude Code, Claude Desktop or Cursor.

FAQ

Why does my MCP server exit right after it starts?

Often because a required environment variable is missing. In our tests, 20 stdio servers we list exited at launch and printed the variable they wanted, such as an API key or token.

Where do I put the API key for a local MCP server?

In the env block of that server's entry in your MCP client config. The client passes it to the server process when it starts it.

Have you tested these servers with the variables set?

No. We test without credentials, so we can only confirm what each server asked for, not that it works once the key is set.