feat(cli): support env vars in mcp dev (#339)#2506
Open
GitAashishG wants to merge 2 commits intomodelcontextprotocol:mainfrom
Open
feat(cli): support env vars in mcp dev (#339)#2506GitAashishG wants to merge 2 commits intomodelcontextprotocol:mainfrom
mcp dev (#339)#2506GitAashishG wants to merge 2 commits intomodelcontextprotocol:mainfrom
Conversation
Add `--env-var/-v` and `--env-file/-f` options to the `mcp dev` command so the inspector subprocess inherits caller-provided environment variables — mirroring what `mcp install` already accepts. Inline `-v` flags override values loaded from `--env-file`. Extract the shared resolution logic into `_resolve_env` and refactor `mcp install` to use it (no behavior change). Document the new flags in README.v2.md and add unit tests for `_resolve_env`. Closes modelcontextprotocol#339
Add tests for the dotenv-missing, dotenv-raises, and malformed-`-v` branches so coverage stays at 100% on `src/mcp/cli/cli.py`. Also drop the now-obsolete `# pragma: no cover` from `_parse_env_var` (it's exercised through `_resolve_env`).
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
Closes #339.
mcp installalready accepts--env-var/-vand--env-file/-f, butmcp devdid not — so there was no way to pass environment variables to a server when iterating with the inspector. This PR adds the same two flags tomcp devand routes the resolved values into the inspector subprocess environment.Changes
--env-var/-vand--env-file/-foptions tomcp dev(mirrorsmcp install)._resolve_env(env_file, env_vars)helper; inline-vvalues override.envvalues.mcp installto use the helper (no behavior change, removes duplication).README.v2.md._resolve_envcovering: no inputs, inline vars, values containing=, dotenv loading, and inline-overrides-dotenv.Validation
uv run --frozen ruff format/ruff check— cleanuv run --frozen pyright src/mcp/cli/cli.py tests/cli/test_utils.py— 0 errorsuv run --frozen pytest tests/cli/test_utils.py— 14 passed