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.6k · updated 2026-11-24 · 🔑 auth
Web & Search● Maintained
Firecrawl
Official Firecrawl MCP server, the context API for AI agents: search, scrape, and interact with the web, plus parse, crawl, map, Agent and Monitor, fr
★ 8.0k · updated 2026-11-29 · 🔑 auth
Dev Tools● Maintained
GitHub
GitHub's official MCP server for repositories, issues, pull requests, Actions and more (local Docker image or the hosted api.githubcopilot.com/mcp/ en
★ 34.9k · updated 2026-11-27 · 🔑 auth