[BUG] claude mcp add doesn't work with environment variables for stdio transport
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?
When you try to add a new MCP server (stdio transport) with an environment variable, you get this error:
Invalid environment variable format: my-server, environment variables should be added as: -e KEY1=value1 -e KEY2=value2
Even when running the default stdio examples (from claude mcp add --help):
claude mcp add -e API_KEY=xxx my-server -- npx my-mcp-server
So it looks like something is broken.
What Should Happen?
The MCP server should be added, without errors related to environment variables.
Error Messages/Logs
Invalid environment variable format: my-server, environment variables should be added as: -e KEY1=value1 -e KEY2=value2
Steps to Reproduce
Run the default claude mcp add example:
claude mcp add -e API_KEY=xxx my-server -- npx my-mcp-server
It seems something changed between v2.0.77 and v2.1.0.
The pattern went from
claude mcp add --transport stdio airtable --env AIRTABLE_API_KEY=YOUR_KEY -- npx -y airtable-mcp-server
to
claude mcp add --transport stdio --env AIRTABLE_API_KEY=YOUR_KEY airtable -- npx -y airtable-mcp-server
but I couldn't find a single version that worked with this new pattern.
Claude Model
Not sure / Multiple models
Is this a regression?
Yes, this worked in a previous version
Last Working Version
v2.0.77
Claude Code Version
2.1.31
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
It's currently not possible to add a new MCP server with stdio transport and an environment variable (even using the default CLI examples). Please prioritize this issue because it's probably affecting a lot of MCP servers 🙏
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗