Skip to content

fix(mcp): pre-compile env-var regex and unify interpolation - #26240

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-adfec1f5
May 15, 2026
Merged

teknium1 merged 2 commits into
mainfrom
hermes/hermes-adfec1f5

Conversation

@teknium1

Copy link
Copy Markdown
Collaborator

Salvage of #2719 by @amethystani onto current main.

Summary

Pre-compiles the ${VAR} regex once at module level in tools/mcp_tool.py and replaces the diverged \w+ copy in hermes_cli/mcp_config.py with the shared pattern. Fixes #2711 and #2712.

Changes

  • tools/mcp_tool.py: add _ENV_VAR_PATTERN = re.compile(r"\$\{([^}]+)\}") near _CREDENTIAL_PATTERN; _interpolate_env_vars uses it.
  • hermes_cli/mcp_config.py: delete _interpolate_value() (its \w+ pattern silently dropped env vars with - or .), reuse _ENV_VAR_PATTERN at the single call site in cmd_mcp_test. Kept import re (still used by _ENV_VAR_NAME_RE on current main).
  • Moved the from tools.mcp_tool import ... to the first-party import group (PEP 8 grouping).

Validation

  • Targeted mcp tests: 259/259 passing.
  • E2E: both runtime and CLI display paths share the same compiled pattern; ${MY-VAR} / ${my.var} now resolve correctly in the CLI test masking path (previously dropped silently).

Original PR: #2719
Closes #2711
Closes #2712

Co-authored-by: amethystani 108541149+amethystani@users.noreply.github.com

amethystani and others added 2 commits May 15, 2026 01:42
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.
@teknium1
teknium1 merged commit 59c7cc6 into main May 15, 2026
13 of 16 checks passed
@teknium1
teknium1 deleted the hermes/hermes-adfec1f5 branch May 15, 2026 08:43
@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/hermes-adfec1f5 vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 8269 on HEAD, 8269 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 4317 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@alt-glitch alt-glitch added type/bug Something isn't working tool/mcp MCP client and OAuth comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have labels May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have tool/mcp MCP client and OAuth type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unify env-var interpolation between mcp_tool.py and mcp_config.py Pre-compile env-var interpolation regex in mcp_tool.py

3 participants