[BUG] .env variable substitution in .mcp.json works in Cursor but not VS Code
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?
Cursor: using Claude Code for VS Code extension 2.0.62 - 6 days ago (current) VS Code: using Claude Code for VS Code extension 2.0.65 - 4 days ago (current)
Both IDEs are pointed to the same local project folder. I started with the following in .mcp.json: { "mcpServers": { "supabase": { "type": "http", "url": "https://mcp.supabase.com/mcp?project_ref=${SUPABASE_PROJECT_REF}", "headers": { "Authorization": "Bearer ${SUPABASE_ACCESS_TOKEN}" } } } }
Claude Code extension for VS Code in Cursor is able to connect to Supabase and read the tables, but Claude Code extension for VS Code in VS Code is not. Tells me I need to auth. Even when it says it can now see the env variables and I need to do a developr refresh or restart, and subsequently do both, it still says not connected to supabase. IT suggested I hardcode the variable values in .msp.json and then it connected to Supabase right away. This is not ideal because it means specifying the value of these variables in multiple places and not having a single source of truth for their values. Not a hypothetical issue because we did in fact just change our Supabase instance.
What Should Happen?
Not sure if this is simply a limitation of VS Code, or something extra Claude Code needs to do in VS Code to get this to work, but Claude Code extension in VS Code should hopefully work the same way as Claude Code extension in Cursor when it comes to being able to specify env variables in .mcp.json instead of having to hardcode them.
Error Messages/Logs
Steps to Reproduce
- Use variable references in your .mcp.json file for and mcp server (for example, supabase, using the following, or any other mcp config)
{ "mcpServers": { "supabase": { "type": "http", "url": "https://mcp.supabase.com/mcp?project_ref=${SUPABASE_PROJECT_REF}", "headers": { "Authorization": "Bearer ${SUPABASE_ACCESS_TOKEN}" } } } }
-
attempt to access the mcp server using Claude Code extensions in both Cursor and VS Code
-
Verify it successfully connects in Cursor but not in VS Code
-
Attempt to get VS Code to read the .env file and know that it should replace the referenced variables with their values from the .env file when acessing the mcp server defined, and do a developer refresh, and then restart VS code. Try again and see if you can connect to the mcp server (you probably won't).
-
Hardcode the values in .mcp.json now and test mcp connection. It should work. This proves that Claude Code extension in Cursor can successfully deal with env variable references in .mcp.json but Claude Code extension in VS Code can not.
Claude Model
Sonnet (default)
Is this a regression?
I don't know
Last Working Version
No response
Claude Code Version
2.0.65
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
VS Code integrated terminal
Additional Information
No response
Found 3 possible duplicate issues:
- https://github.com/anthropics/claude-code/issues/9427
- https://github.com/anthropics/claude-code/issues/6204
- https://github.com/anthropics/claude-code/issues/1254
This issue will be automatically closed as a duplicate in 3 days.
- If your issue is a duplicate, please close it and 👍 the existing issue instead
- To prevent auto-closure, add a comment or 👎 this comment
🤖 Generated with Claude Code
Found 3 possible duplicate issues:
- [BUG] env variable expansion not working in plugin .mcp.json #9427
- [BUG] MCP headers with environment variable substitution not being sent from .mcp.json #6204
- [BUG] Environment variables from
envsection not passed to MCP servers #1254This issue will be automatically closed as a duplicate in 3 days.
- If your issue is a duplicate, please close it and 👍 the existing issue instead
- To prevent auto-closure, add a comment or 👎 this comment
🤖 Generated with Claude Code
Related but not exactly the same, if those are fixed it won't necessarily fix it in VS Code, especially cause it works in Cursor already.
I've run into this issue as well. It seems that the HTTPS or SSE transports aren't supporting environment variable substitution for plugins. This makes it really difficult to distribute MCPs that require static tokens, but where we don't want to share those tokens through a marketplace.
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
not fixed, please don't close due to inactivty
Also having this issue with Ghostty + VSCode terminals
Have this exact same issue on Windows. Variable expansion on .mcp.json not working creates scenarios where teams using vscode for their claude code interface (and there's many reasons to do this like native copy/paste, lsp/ide features, etc) must not share their .mcp.json in repo as setting api keys directly in the file is the only way to get them working.
If you open vscode by first opening bash at the project directory and then:
source .env code .
Variable expansion for extensions does work and .mcp.json works with said variables.