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

> Learn how to configure environment variables for MCP servers. Customize file paths, ports, and behavior using process.env with VS Code, Docker, or CLI.

- Repository: [Model Context Protocol/servers](https://github.com/modelcontextprotocol/servers)
- Tags: how-to-guide
- Published: 2026-03-01

---

**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`](https://github.com/modelcontextprotocol/servers/blob/main/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`](https://github.com/modelcontextprotocol/servers/blob/main/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:

- **`PORT`**: Configures the HTTP or SSE transport listening port (default `3001`), referenced in both [`src/everything/transports/streamableHttp.ts`](https://github.com/modelcontextprotocol/servers/blob/main/src/everything/transports/streamableHttp.ts) and [`src/everything/transports/sse.ts`](https://github.com/modelcontextprotocol/servers/blob/main/src/everything/transports/sse.ts).
- **`GZIP_MAX_FETCH_SIZE`**, **`GZIP_MAX_FETCH_TIME_MILLIS`**, **`GZIP_ALLOWED_DOMAINS`**: Security and performance tunables for the gzip-as-resource helper in [`src/everything/tools/gzip-file-as-resource.ts`](https://github.com/modelcontextprotocol/servers/blob/main/src/everything/tools/gzip-file-as-resource.ts), limiting fetch size, timeout, and allowed domains.

## 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`](https://github.com/modelcontextprotocol/servers/blob/main/src/memory/README.md), this object merges variables into `process.env` before the server starts:

```json
{
  "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:

```bash
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:

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

```

For Windows PowerShell:

```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`](https://github.com/modelcontextprotocol/servers/blob/main/src/everything/tools/get-env.ts), this tool returns the entire `process.env` object as pretty-printed JSON:

```bash
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`](https://github.com/modelcontextprotocol/servers/blob/main/src/everything/transports/streamableHttp.ts) and [`src/everything/transports/sse.ts`](https://github.com/modelcontextprotocol/servers/blob/main/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`](https://github.com/modelcontextprotocol/servers/blob/main/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`](https://github.com/modelcontextprotocol/servers/blob/main/src/memory/index.ts).