fix: preserve Claude stdio MCP env#1224
Open
imk1t wants to merge 4 commits intomicrosoft:mainfrom
Open
Conversation
Author
|
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a Claude Code-specific regression where self-defined stdio MCP servers lost their declared env when generating .mcp.json, by teaching the legacy (literal-resolution) env resolver to handle the self-defined env dict shape.
Changes:
- Extend
_resolve_environment_variablesto resolveenvprovided as a plain{NAME: value}dict when runtime env substitution is disabled (Claude Code path). - Add a unit regression test asserting that
.mcp.jsonpreservesenvfor a self-defined stdio server.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
tests/unit/test_claude_mcp.py |
Adds regression coverage for preserving env in Claude Code .mcp.json for self-defined stdio servers. |
src/apm_cli/adapters/client/copilot.py |
Updates legacy env-variable resolution to support dict-shaped env inputs used by self-defined stdio MCP entries. |
Comment on lines
+791
to
+802
| if isinstance(env_vars, dict): | ||
| resolved = {} | ||
| for name, value in env_vars.items(): | ||
| if not name: | ||
| continue | ||
| if isinstance(value, str): | ||
| resolved[name] = self._resolve_env_variable( | ||
| name, value, env_overrides=env_overrides | ||
| ) | ||
| elif value is not None: | ||
| resolved[name] = value | ||
| return resolved |
This was referenced May 10, 2026
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.
Description
Preserve
envvalues for self-defined stdio MCP servers when generating Claude Code.mcp.json.Root cause: self-defined stdio MCP entries pass
envinto the shared adapter formatting path as a plain dictionary. The Copilot runtime-substitution path already handled that shape, but the legacy literal-resolution path used by Claude Code only handled registry-style environment variable lists, so the dictionary resolved to an empty object.This keeps the fix scoped to that literal-resolution path and adds a Claude Code regression test proving that
.mcp.jsonpreserves the declared environment variable.Fixes #1222
Type of change
Testing
Validation run:
The CLI smoke test used a generic self-defined stdio MCP entry with
DEMO_ENV=demo-valueand verified that the generated.mcp.jsoncontains: