How to Configure Environment Variables for MCP Servers: A Complete Guide

MCP servers read configuration from standard Node.js process.env at startup, allowing you to customize file paths, ports, and behavior via environment variables passed through VS Code settings, Docker flags, or command-line prefixes.

Configuring environment variables for MCP servers is essential when deploying Model Context Protocol implementations from the modelcontextprotocol/servers repository. Whether you need to change the persistence path for the Memory server, disable verbose logging in Sequential-Thinking, or customize the HTTP port for the Everything server, understanding how these Node.js processes consume environment variables ensures smooth integration with Claude Desktop, VS Code, or containerized deployments.

Core Environment Variables in MCP Servers

Memory Server Persistence Path

The Memory server uses MEMORY_FILE_PATH to determine where to store the knowledge-graph JSONL file. In src/memory/index.ts, the server reads this variable to override the default memory.jsonl location, accepting both absolute and relative paths resolved against the server's source folder.

Sequential-Thinking Logging Control

For the Sequential-Thinking server, set DISABLE_THOUGHT_LOGGING to "true" (case-insensitive) to suppress the colorful console rendering of each thought. This is defined in src/sequentialthinking/lib.ts and proves useful for CI/CD pipelines where console noise should be minimized.

Everything Server Transport and Security Settings

The Everything server exposes multiple environment variables across its transport and tool implementations:

How to Configure Environment Variables for MCP Servers

VS Code and Claude Desktop Configuration

When running MCP servers through VS Code or Claude Desktop, define the env map within your server configuration. As shown in src/memory/README.md, this object merges variables into process.env before the server starts:

{
  "servers": {
    "memory": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-memory"],
      "env": {
        "MEMORY_FILE_PATH": "/data/custom-memory.jsonl"
      }
    }
  }
}

Docker Deployment

For containerized deployments, pass environment variables using the -e flag or Docker Compose. The servers read process.env directly, so any standard Docker method works:

docker run -i \
  -e MEMORY_FILE_PATH=/mnt/memory/custom.jsonl \
  -e PORT=8080 \
  -v $(pwd)/memory:/mnt/memory \
  --rm mcp/memory

NPX and Command Line Execution

When running servers directly via NPX or Node, prefix the command with variable assignments. This works cross-platform on Unix-like systems:

MEMORY_FILE_PATH=/tmp/memory.jsonl npx @modelcontextprotocol/server-memory

For Windows PowerShell:

$env:MEMORY_FILE_PATH="/tmp/memory.jsonl"; npx @modelcontextprotocol/server-memory

Verifying Your Configuration

To confirm that environment variables are correctly injected, use the Everything server's built-in get-env tool. Located in src/everything/tools/get-env.ts, this tool returns the entire process.env object as pretty-printed JSON:

npx @modelcontextprotocol/server-everything get-env

This outputs all active variables, allowing you to verify that MEMORY_FILE_PATH, PORT, or DISABLE_THOUGHT_LOGGING are set as expected before connecting your MCP client.

Summary

  • MCP servers consume environment variables through standard Node.js process.env at startup, with no built-in .env file support.
  • Key variables include MEMORY_FILE_PATH for persistence, DISABLE_THOUGHT_LOGGING for CI-friendly output, and PORT for transport configuration.
  • Configuration methods vary by deployment: use the env map in VS Code/Claude Desktop settings, -e flags in Docker, or command-line prefixes for NPX.
  • Verification is available through the Everything server's get-env tool, which exposes the active environment for debugging.

Frequently Asked Questions

Can MCP servers read .env files directly?

No. According to the source code in modelcontextprotocol/servers, the implementations read only from process.env populated by the host process. They do not include dotenv or similar loaders, so you must inject variables through your orchestration tool (Docker, VS Code settings, or shell exports).

What is the default port for the MCP Everything server?

The default port is 3001. In src/everything/transports/streamableHttp.ts and src/everything/transports/sse.ts, the server checks process.env.PORT and falls back to 3001 if the variable is undefined.

How do I disable logging in the Sequential-Thinking server?

Set the environment variable DISABLE_THOUGHT_LOGGING to "true" (case-insensitive). The check in src/sequentialthinking/lib.ts evaluates this variable and suppresses the colorful console rendering of thoughts when enabled, making it ideal for CI/CD environments.

Where is the memory file stored by default?

By default, the Memory server stores data in memory.jsonl relative to the server's source folder. You can override this by setting MEMORY_FILE_PATH to an absolute or relative path, as implemented in src/memory/index.ts.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →