MCP Server Environment Variables Not Loading
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
- Install n8n-mcp via
npx n8n-mcp - Configure
claude_desktop_config.jsonwith environment variables pointing to a cloud n8n instance - Restart Claude Desktop completely (Cmd+Q and reopen)
- Attempt to use n8n MCP tools (e.g.,
n8n_health_checkorn8n_get_execution) - Run
n8n_diagnosticto check configuration
---
Expected Behavior
The MCP server should:
- Load environment variables from the
envsection of the config - Connect to
https://bluesprincemedia.app.n8n.cloud/as specified inN8N_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
- ✅ Validated config file syntax - JSON is valid
- ✅ Restarted Claude Desktop multiple times - No change
- ✅ Removed duplicate MCP server entries - Simplified to single n8n-mcp entry
- ✅ Checked shell profiles - No N8N environment variables set
- ✅ Verified n8n-mcp package works - Works when env vars passed directly to npx
- ✅ Tested API credentials - Cloud API works via curl
- ❌ 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:
- Use API directly via scripts - Created bash helper script that uses curl with proper credentials
- Run local n8n instance - If using localhost:5678 (matches default)
- Use alternative MCP implementations - If available for the service
Example workaround script: /Users/deepspace9/n8n-cloud-helper.sh
---
Possible Root Causes
- Environment variable inheritance issue - Claude Desktop may not be passing the
envobject to spawned MCP processes - Process isolation - MCP servers may be sandboxed in a way that prevents environment variable access
- Config parsing timing - Environment variables may not be set before the MCP server initializes
- 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
- Add debug logging in Claude Desktop to show what environment variables are being passed to MCP servers
- Verify the MCP server spawning code properly inherits the
envobject from config - Test with other MCP servers that require environment variables
- Document whether environment variables in
claude_desktop_config.jsonare 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_diagnostictool - 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
- Install the n8n-mcp package:
```bash
npx n8n-mcp --version
- 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"
}
}
}
}
- Verify the JSON is valid:
python3 -c "import json; json.load(open('/Users/YOUR_USER/Library/Application
Support/Claude/claude_desktop_config.json'))"
- Completely restart Claude Desktop (Cmd+Q and reopen)
- In Claude Code, run the diagnostic tool:
Use the n8n_diagnostic tool with verbose: true
- Observe that the MCP reports:
- N8N_API_URL: "http://localhost:5678" (default, not the cloud URL)
- Connection error: "Unable to connect to n8n"
- Verify the cloud instance is accessible:
curl -H "X-N8N-API-KEY: your-key"
"https://your-instance.app.n8n.cloud/api/v1/workflows"
- (This should return data successfully)
- 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
- (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_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗