MCP server can't see my API key (env vars not passed)
Claude DesktopCursorClaude CodeVS Code
The error
401 Unauthorized • "API key is required" • "Missing environment variable"
Why it happens
MCP clients start servers with a minimal environment. Variables exported in your shell profile are usually not inherited, so the key has to be put in the server's env block (or passed with the client's CLI flag).
How to fix it
- Add an env block next to command/args
Keys go inside the server entry, not at the top level.{ "mcpServers": { "brave-search": { "command": "npx", "args": ["-y", "@brave/brave-search-mcp-server"], "env": { "BRAVE_API_KEY": "your-key" } } } } - Claude Code: use -e
Pass variables with--env/-ewhen adding the server.claude mcp add brave -e BRAVE_API_KEY=your-key -- npx -y @brave/brave-search-mcp-server - VS Code: use inputs for secrets
VS Code'smcp.jsonsupports${input:…}prompts so you don't hardcode keys.{ "inputs": [{ "type": "promptString", "id": "brave-key", "description": "Brave API key", "password": true }], "servers": { "brave": { "command": "npx", "args": ["-y", "@brave/brave-search-mcp-server"], "env": { "BRAVE_API_KEY": "${input:brave-key}" } } } } - Restart and avoid committing keys
Restart the client. Add project-level config files that contain keys to.gitignore.
Related servers
Web & Search● Maintained
Brave Search
An MCP server that integrates the Brave Search API: web, local business, image, video and news search, plus AI summarization. Supports STDIO and HTTP
★ 1.5k · updated 2026-10-05 · 🔑 auth
Web & Search● Maintained
Firecrawl
🔥 Official Firecrawl MCP Server - Adds powerful web scraping and search to Cursor, Claude and any other LLM clients.
★ 7.6k · updated 2026-10-15 · 🔑 auth
Dev Tools● Maintained
GitHub
GitHub's official MCP Server
★ 33.6k · updated 2026-10-15 · 🔑 auth