Skip to content

fix(gateway): refresh cached agent tools on /reload-mcp#32815

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-d33e9fef
May 26, 2026
Merged

fix(gateway): refresh cached agent tools on /reload-mcp#32815
teknium1 merged 1 commit into
mainfrom
hermes/hermes-d33e9fef

Conversation

@teknium1

@teknium1 teknium1 commented May 26, 2026

Copy link
Copy Markdown
Contributor

Summary

/reload-mcp now updates the running session's tool list — no /new required.

Previously the gateway reconnected MCP servers but kept the stale tool list on every cached AIAgent. Users had to also start a new session to actually call the newly-available tools, losing their conversation history.

Changes

  • gateway/run.py::_execute_mcp_reload — after discover_mcp_tools() returns, walk _agent_cache and overwrite each agent's .tools + .valid_tool_names via get_tool_definitions(). Per-agent enabled_toolsets / disabled_toolsets are preserved.
  • tests/gateway/test_mcp_reload_refreshes_cached_agents.py — 3 new tests covering: cached agents are refreshed, empty cache is a no-op, and per-agent toolset scopes survive the reload.
  • scripts/release.py — AUTHOR_MAP entry for @fujinice.

What did NOT change

The slash-confirm gate (Approve Once / Always Approve / Cancel) stays exactly as it was — /reload-mcp still prompts before invalidating the prompt cache. The cache-refresh is just the missing piece of what "yes" already meant.

The auto-reload-on-config-change watcher from #23812 is intentionally not included/reload-mcp remains explicit.

Validation

Before After
New session sees added MCP tools ✓ (after /new)
Existing session sees added MCP tools after /reload-mcp
tests/gateway/ (5923 tests) pass pass
3 new regression tests n/a pass

Credit

Original diagnosis + initial cache-refresh implementation by @fujinice in #23812 (Co-Authored-By preserved). Closes #23812.

Infographic

PR #32815 — /reload-mcp refreshes cached agents

When the gateway processes /reload-mcp, it reconnects MCP servers and
updates the global _servers registry, but cached AIAgent instances in
_agent_cache keep the tools list they were built with. The user had to
also run /new (discarding conversation history) before the agent could
see the new tools — even though /reload-mcp had succeeded.

This patch refreshes each cached agent's .tools and .valid_tool_names
in _execute_mcp_reload after discovery returns, so existing sessions
pick up new MCP tools on their next turn. The slash-confirm gate in
_handle_reload_mcp_command already obtains user consent for the
implied prompt-cache invalidation before this code runs.

Mirrors the equivalent behaviour the CLI already does in cli.py
_reload_mcp. Per-agent enabled_toolsets and disabled_toolsets are
preserved so an agent that was scoped to a subset of toolsets does
not silently gain disabled tools after the reload.

Original diagnosis + initial implementation in #23812 from @fujinice.
The auto-reload watcher half of that PR is intentionally dropped —
users want /reload-mcp to remain explicit.

Co-authored-by: fujinice <45688690+fujinice@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/hermes-d33e9fef 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: 9376 on HEAD, 9373 on base (🆕 +3)

🆕 New issues (2):

Rule Count
invalid-argument-type 1
unresolved-import 1
First entries
gateway/run.py:13363: [invalid-argument-type] invalid-argument-type: Argument to function `get_tool_definitions` is incorrect: Expected `list[str]`, found `Any | None`
tests/gateway/test_mcp_reload_refreshes_cached_agents.py:20: [unresolved-import] unresolved-import: Cannot resolve imported module `pytest`

✅ Fixed issues: none

Unchanged: 4967 pre-existing issues carried over.

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

@teknium1 teknium1 merged commit f05a473 into main May 26, 2026
26 checks passed
@teknium1 teknium1 deleted the hermes/hermes-d33e9fef branch May 26, 2026 21:28
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery tool/mcp MCP client and OAuth labels May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists 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.

2 participants