fix(providers): expand ${VAR_NAME} brace syntax in MCP config env vars#1728
Conversation
fixes #1612) Add two-group regex alternation to expandEnvVarsInRecord so both $VAR and ${VAR} forms are expanded in env/headers values. Add 5 tests for the new brace-form behavior and update MCP servers docs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis PR extends MCP environment variable expansion to support both ChangesMCP Environment Variable Expansion
Development Guidelines
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Review SummaryVerdict: ready-to-merge Clean, focused fix. The Blocking issuesNone. Suggested fixesNone. Minor / nice-to-have
Compliments
Reviewed via maintainer-review-pr workflow (Pi/Minimax). Aspects run: code-review, test-coverage, comment-quality, docs-impact. |
Summary
expandEnvVarsInRecordinpackages/providers/src/mcp/config.tsonly matched bare$VAR_NAMEsyntax via/\$([A-Z_][A-Z0-9_]*)/g. The${VAR_NAME}brace form — used in shell scripts, Docker Compose, and official MCP server documentation — was silently left unexpanded and never reported inmissingVars.${VAR}) get silent failures — the variable reference appears literally in the config instead of the env value, with no warning.${VAR}(group 1) and$VAR(group 2); 5 new tests added; MCP servers docs updated to show both forms; one CLAUDE.md planning-convention note added.envandheadersfields only —commandandargsare intentionally not expanded (security boundary preserved for both bare and brace forms).UX Journey
Before
After
Architecture Diagram
Before
After
Connection inventory:
dag-executormcp/config.ts::expandEnvVarsInRecorddag-executor.test.tsloadMcpConfigmcp-servers.mdCLAUDE.mdLabel Snapshot
risk: lowsize: Sprovidersproviders:mcpChange Metadata
bugprovidersLinked Issue
Validation Evidence (required)
All checks pass:
--max-warnings 0enforced)5 new targeted tests for brace-form expansion:
expands ${VAR_NAME} brace-form in env valuesexpands ${VAR_NAME} brace-form in headers valuesreplaces undefined brace-form vars with empty string and reports themexpands mixed bare and brace-form vars in the same stringdoes not expand brace-form vars in command or args fields(security boundary)Security Impact (required)
commandandargssecurity boundary is explicitly tested to confirm brace form is also NOT expanded thereCompatibility / Migration
$VAR_NAMEbehaviour is unchanged;${VAR_NAME}was previously a no-op (silently passed through), now it expandsHuman Verification (required)
missingVars; command/args field security boundary confirmed by testSide Effects / Blast Radius (required)
packages/providers/src/mcp/config.ts)missingVarsreporting is preserved and extended to brace form, so users get the same warnings they would for bare-form missing varsRollback Plan (required)
git revert ec328a23— single-commit revert, no migration needed${VAR}strings instead of resolved valuesRisks and Mitigations
(?:...)non-capturing outer group — linear time, no nested quantifiers. Reviewed and verified safe.Summary by CodeRabbit
Documentation
New Features
$VAR_NAMEand${VAR_NAME}formats for environment variable expansion in config values.