fix(mcp): pre-compile env-var regex and unify interpolation across mcp_tool and mcp_config - #2719
Closed
amethystani wants to merge 1 commit into
Closed
amethystani wants to merge 1 commit into
amethystani wants to merge 1 commit into
Conversation
Remove redundant inner `import re` and regex recompilation on every call in _interpolate_env_vars. Add module-level _ENV_VAR_PATTERN compiled once. Replace the separate _interpolate_value() in mcp_config.py (which used \w+ and would silently fail on env vars containing hyphens or dots) with the shared _ENV_VAR_PATTERN from mcp_tool.py. Remove now-unused import re.
Contributor
|
Note: #2728 (same refactor) was closed. This appears to be a replacement. |
Collaborator
|
Merged via #26240 — your commit was cherry-picked onto current main with your authorship preserved in git log. Thanks @amethystani! |
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
Fixes two related code quality issues in MCP env-var interpolation:
Changes
tools/mcp_tool.py_ENV_VAR_PATTERN = re.compile(r"\$\{([^}]+)\}")after_CREDENTIAL_PATTERNimport reinside_interpolate_env_vars()(module-level import already exists)hermes_cli/mcp_config.py_interpolate_value()which used\w+and would silently fail on env vars with hyphens or dots (e.g.MY-VAR,my.var)_ENV_VAR_PATTERNfrommcp_tool.pyimport reImpact
Pure code hygiene — no behavior change for standard
[a-zA-Z0-9_]env var names. Fixes a subtle inconsistency wherehermes mcp testcould show unresolved auth headers for env vars with hyphens/dots that work correctly at runtime.Closes #2711
Closes #2712