MCP Server Environment Variables Not Loading

Resolved 💬 3 comments Opened Nov 4, 2025 by BluesPrince Closed Nov 7, 2025

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Bug Report: MCP Server Environment Variables Not Loading

Reported Date: 2025-11-04
Claude Desktop Version: 1.0.211
Platform: macOS 24.6.0 (Darwin)
MCP Server: n8n-mcp (v2.22.8)

---

Summary

The n8n-mcp server does not properly load environment variables defined in claude_desktop_config.json. Despite having N8N_API_URL configured to point to a cloud instance (https://bluesprincemedia.app.n8n.cloud/), the MCP server continues to use the default localhost URL (http://localhost:5678).

---

Configuration

File Location

~/Library/Application Support/Claude/claude_desktop_config.json

MCP Server Configuration

{
  "n8n-mcp": {
    "command": "npx",
    "args": ["n8n-mcp"],
    "env": {
      "MCP_MODE": "stdio",
      "LOG_LEVEL": "error",
      "DISABLE_CONSOLE_OUTPUT": "true",
      "N8N_API_URL": "https://bluesprincemedia.app.n8n.cloud/",
      "N8N_API_KEY": "eyJhbG...xEwA"
    }
  }
}

Note: Config file has been validated as proper JSON syntax.

---

Steps to Reproduce

  1. Install n8n-mcp via npx n8n-mcp
  2. Configure claude_desktop_config.json with environment variables pointing to a cloud n8n instance
  3. Restart Claude Desktop completely (Cmd+Q and reopen)
  4. Attempt to use n8n MCP tools (e.g., n8n_health_check or n8n_get_execution)
  5. Run n8n_diagnostic to check configuration

---

Expected Behavior

The MCP server should:

  • Load environment variables from the env section of the config
  • Connect to https://bluesprincemedia.app.n8n.cloud/ as specified in N8N_API_URL
  • Successfully authenticate using the provided N8N_API_KEY
  • Return data from the cloud n8n instance

---

Actual Behavior

The MCP server:

  • Ignores environment variables in claude_desktop_config.json
  • Connects to http://localhost:5678 (default value)
  • Returns connection errors: "Unable to connect to n8n. Please check the server URL and ensure n8n is running."

Diagnostic Output

{
  "environment": {
    "N8N_API_URL": "http://localhost:5678",  // ❌ Should be cloud URL
    "N8N_API_KEY": "***configured***",
    "NODE_ENV": "production",
    "MCP_MODE": "stdio"
  },
  "apiConfiguration": {
    "configured": true,
    "status": {
      "configured": true,
      "connected": false,
      "error": "No response from n8n server"
    },
    "config": {
      "baseUrl": "http://localhost:5678"  // ❌ Wrong URL
    }
  }
}

---

Verification Tests

1. Config File is Valid JSON

python3 -c "import json; json.load(open('~/Library/Application Support/Claude/claude_desktop_config.json'))"
# Output: No errors - JSON is valid ✅

2. n8n-mcp Works with Environment Variables

N8N_API_URL="https://bluesprincemedia.app.n8n.cloud/" \
N8N_API_KEY="..." \
npx n8n-mcp --version

# Output: Successfully starts with cloud URL ✅

3. Cloud API is Accessible

curl -H "X-N8N-API-KEY: ..." \
  "https://bluesprincemedia.app.n8n.cloud/api/v1/workflows"

# Output: Returns workflow data ✅

4. No Shell Environment Variables Set

env | grep N8N
# Output: (empty) ✅ - No conflicting environment variables

---

Troubleshooting Attempted

  1. Validated config file syntax - JSON is valid
  2. Restarted Claude Desktop multiple times - No change
  3. Removed duplicate MCP server entries - Simplified to single n8n-mcp entry
  4. Checked shell profiles - No N8N environment variables set
  5. Verified n8n-mcp package works - Works when env vars passed directly to npx
  6. Tested API credentials - Cloud API works via curl
  7. Complete system restart - Not yet tested

---

MCP Server Logs

Log Location: ~/Library/Logs/Claude/mcp-server-n8n-mcp.log

Relevant Log Excerpt:

2025-11-04T02:32:35.284Z [n8n-mcp] [info] Using MCP server command: npx with args: ['n8n-mcp']
2025-11-04T02:32:35.285Z [n8n-mcp] [info] Server started and connected successfully
2025-11-04T02:32:36.407Z [n8n-mcp] [info] Message from server: {
  "serverInfo": {
    "name": "n8n-documentation-mcp",
    "version": "2.22.8"
  }
}

Observation: Logs do not show the environment variables being passed to the MCP server process.

---

Impact

  • Severity: Medium
  • Users Affected: Anyone using MCP servers that require environment-specific configuration (cloud vs local instances)
  • Workaround Available: Yes (see below)

---

Current Workaround

Since the MCP doesn't load environment variables properly, users can:

  1. Use API directly via scripts - Created bash helper script that uses curl with proper credentials
  2. Run local n8n instance - If using localhost:5678 (matches default)
  3. Use alternative MCP implementations - If available for the service

Example workaround script: /Users/deepspace9/n8n-cloud-helper.sh

---

Possible Root Causes

  1. Environment variable inheritance issue - Claude Desktop may not be passing the env object to spawned MCP processes
  2. Process isolation - MCP servers may be sandboxed in a way that prevents environment variable access
  3. Config parsing timing - Environment variables may not be set before the MCP server initializes
  4. npx caching - npx might be using a cached version of the package with stale configuration

---

Related Issues

This may be related to how Claude Desktop spawns MCP server processes and whether environment variables from the config are properly inherited by child processes.

---

Additional Context

Other MCP Servers in Config

  • firecrawl-mcp (uses env vars) - Not tested if working
  • filesystem, memory, postgres - No env-specific URLs needed
  • fetch - No configuration needed

System Details

  • Shell: zsh
  • Node.js: v22.20.0 (via nvm)
  • npx location: /Users/deepspace9/.nvm/versions/node/v22.20.0/bin/npx

---

Suggested Investigation

  1. Add debug logging in Claude Desktop to show what environment variables are being passed to MCP servers
  2. Verify the MCP server spawning code properly inherits the env object from config
  3. Test with other MCP servers that require environment variables
  4. Document whether environment variables in claude_desktop_config.json are officially supported

---

Attachments

  • Full config file: /Users/deepspace9/Library/Application Support/Claude/claude_desktop_config.json
  • MCP logs: ~/Library/Logs/Claude/mcp-server-n8n-mcp.log
  • Diagnostic output: Available via n8n_diagnostic tool
  • Workaround script: /Users/deepspace9/n8n-cloud-helper.sh

---

Contact Information

For follow-up questions or additional diagnostics, please reach out via the Claude Desktop feedback channels or GitHub issues.

---

Generated: 2025-11-04T02:40:00Z
Report Version: 1.0

What Should Happen?

The n8n-mcp server should load environment variables from the 'env' section
in claude_desktop_config.json and connect to the cloud n8n instance at
https://bluesprincemedia.app.n8n.cloud/

Error Messages/Logs

Diagnostic output from n8n_diagnostic:

  {
    "environment": {
      "N8N_API_URL": "http://localhost:5678",
      "N8N_API_KEY": "***configured***"
    },
    "apiConfiguration": {
      "status": {
        "connected": false,
        "error": "No response from n8n server"
      }
    }
  }

  Error when calling MCP tools:
  {
    "success": false,
    "error": "Unable to connect to n8n. Please check the server URL and ensure 
  n8n is running.",
    "code": "NO_RESPONSE"
  }

Steps to Reproduce

  1. Install the n8n-mcp package:

```bash
npx n8n-mcp --version

  1. Create/edit ~/Library/Application

Support/Claude/claude_desktop_config.json with this configuration:
{
"mcpServers": {
"n8n-mcp": {
"command": "npx",
"args": ["n8n-mcp"],
"env": {
"N8N_API_URL": "https://your-instance.app.n8n.cloud/",
"N8N_API_KEY": "your-api-key-here"
}
}
}
}

  1. Verify the JSON is valid:

python3 -c "import json; json.load(open('/Users/YOUR_USER/Library/Application
Support/Claude/claude_desktop_config.json'))"

  1. Completely restart Claude Desktop (Cmd+Q and reopen)
  2. In Claude Code, run the diagnostic tool:

Use the n8n_diagnostic tool with verbose: true

  1. Observe that the MCP reports:
  • N8N_API_URL: "http://localhost:5678" (default, not the cloud URL)
  • Connection error: "Unable to connect to n8n"
  1. Verify the cloud instance is accessible:

curl -H "X-N8N-API-KEY: your-key"
"https://your-instance.app.n8n.cloud/api/v1/workflows"

  1. (This should return data successfully)
  2. Verify n8n-mcp works when env vars are passed directly:

N8N_API_URL="https://your-instance.app.n8n.cloud/" N8N_API_KEY="your-key" npx
n8n-mcp --version

  1. (This should start successfully with the cloud URL)

Expected: MCP should use the cloud URL from config
Actual: MCP ignores the env vars and uses default localhost:5678

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.0.31

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

_No response_

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗