refactor(mcp): unify env-var interpolation and pre-compile regex - #2728
Closed
kagura-agent wants to merge 1 commit into
Closed
refactor(mcp): unify env-var interpolation and pre-compile regex#2728kagura-agent wants to merge 1 commit into
kagura-agent wants to merge 1 commit into
Conversation
Two env-var interpolation functions existed with different regex patterns:
- mcp_tool.py used $\{([^}]+)\} (matches any chars — correct)
- mcp_config.py used $\{(\w+)\} (word chars only — fails on dots/hyphens)
This meant 'hermes mcp test' could show unresolved values for headers
that work correctly at runtime.
Changes:
- Pre-compile regex as _ENV_VAR_PATTERN at module level in mcp_tool.py
(removes redundant inner 'import re' on every call)
- Rewrite mcp_config.py's _interpolate_value to reuse _ENV_VAR_PATTERN
- Remove unused 'import re' from mcp_config.py
Fixes NousResearch#2711, fixes NousResearch#2712
Contributor
Author
|
Hi team — checking in on this one. Let me know if there are any concerns or changes needed. Will close in a week if no response. Thanks! |
Contributor
Author
|
Gentle ping — any thoughts on this refactor? Happy to adjust if needed. 🙏 |
Contributor
Author
|
Closing — no response after two pings over 9 days. Feel free to reopen or cherry-pick if this becomes relevant. Thanks! 🙏 |
1 task
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
Two separate env-var interpolation functions existed with inconsistent regex patterns, causing
hermes mcp testto potentially show different results than runtime.Fixes #2711 and #2712.
Root Cause
tools/mcp_tool.py\$\{([^}]+)\}${...}✅hermes_cli/mcp_config.py\$\{(\w+)\}-or.❌Changes
tools/mcp_tool.py(+3/-2):_ENV_VAR_PATTERNat module levelimport rein_interpolate_env_vars()hermes_cli/mcp_config.py(+2/-4):_interpolate_value()to reuse_ENV_VAR_PATTERNfrommcp_toolimport reTesting
[a-zA-Z0-9_])