Skip to content

fix: .env loading no longer overrides already-set environment variables - #138

Open
mattpodwysocki wants to merge 1 commit into
mainfrom
fix/dotenv-no-override
Open

fix: .env loading no longer overrides already-set environment variables#138
mattpodwysocki wants to merge 1 commit into
mainfrom
fix/dotenv-no-override

Conversation

@mattpodwysocki

Copy link
Copy Markdown
Contributor

Summary

  • .env loading previously applied every key onto process.env with override semantics, so a .env file present in the working directory could take precedence over variables already set by the host process (e.g. MAPBOX_API_ENDPOINT, MAPBOX_ACCESS_TOKEN).
  • Extracted the loading logic into src/utils/loadDotEnv.ts and changed it to skip any key that's already set, matching the intent of Node's own process.loadEnvFile(). Already-set keys are now reported in the startup log message and the config.load_env tracing span instead of being silently skipped.
  • Matches the equivalent fix in mapbox/mcp-server.

Test plan

  • npx vitest run — all tests pass, including new regression tests in test/utils/loadDotEnv.test.ts covering override precedence
  • npm run build succeeds
  • Live-verified against the real built server with a real MCP client: with a .env in the working directory pointing MAPBOX_API_ENDPOINT elsewhere, and the host already having set both variables, a real tool call (list_styles_tool) still reached the host-configured api.mapbox.com, not the .env-supplied value
  • CHANGELOG.md updated

🤖 Generated with Claude Code

.env loading previously applied every key onto process.env with override
semantics, so a .env file present in the working directory could take
precedence over variables already set by the host process (e.g.
MAPBOX_API_ENDPOINT, MAPBOX_ACCESS_TOKEN).

Extracted the loading logic into src/utils/loadDotEnv.ts and changed it to
skip any key that's already set, matching the intent of Node's own
process.loadEnvFile(). Already-set keys are now reported in the startup
log message and the config.load_env tracing span instead of being
silently skipped.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@mattpodwysocki
mattpodwysocki requested a review from a team as a code owner August 25, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant