fix: .env loading no longer overrides already-set environment variables - #138
Open
mattpodwysocki wants to merge 1 commit into
Open
fix: .env loading no longer overrides already-set environment variables#138mattpodwysocki wants to merge 1 commit into
mattpodwysocki wants to merge 1 commit into
Conversation
.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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
.envloading previously applied every key ontoprocess.envwith override semantics, so a.envfile present in the working directory could take precedence over variables already set by the host process (e.g.MAPBOX_API_ENDPOINT,MAPBOX_ACCESS_TOKEN).src/utils/loadDotEnv.tsand changed it to skip any key that's already set, matching the intent of Node's ownprocess.loadEnvFile(). Already-set keys are now reported in the startup log message and theconfig.load_envtracing span instead of being silently skipped.mapbox/mcp-server.Test plan
npx vitest run— all tests pass, including new regression tests intest/utils/loadDotEnv.test.tscovering override precedencenpm run buildsucceeds.envin the working directory pointingMAPBOX_API_ENDPOINTelsewhere, and the host already having set both variables, a real tool call (list_styles_tool) still reached the host-configuredapi.mapbox.com, not the.env-supplied value🤖 Generated with Claude Code