Skip to content

fix: reconnect stale MCP tool wrappers - #50162

Closed
gitgrooves wants to merge 1 commit into
NousResearch:mainfrom
gitgrooves:fix/mcp-stale-wrapper-reconnect
Closed

fix: reconnect stale MCP tool wrappers#50162
gitgrooves wants to merge 1 commit into
NousResearch:mainfrom
gitgrooves:fix/mcp-stale-wrapper-reconnect

Conversation

@gitgrooves

Copy link
Copy Markdown

Summary

  • attempt in-process MCP rediscovery when a generated MCP tool wrapper has lost its server session
  • preserve the existing MCP server '<name>' is not connected error when rediscovery cannot recover the session
  • add regression coverage for stale wrapper recovery and failed reconnect behavior

Test Plan

  • uv run pytest tests/cron/test_scheduler_mcp_init.py tests/tools/test_mcp_stale_wrapper_reconnect.py -q

Context

A long-running Hermes gateway can keep generated MCP tool wrappers after the underlying client session has gone stale/disconnected. Raw MCP endpoint health can be green while the active wrapper still returns not connected. This adds a best-effort reconnect path at wrapper invocation time before surfacing the error.

@alt-glitch alt-glitch added type/bug Something isn't working tool/mcp MCP client and OAuth P2 Medium — degraded but workaround exists duplicate This issue or pull request already exists labels Jun 21, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #23540 — both add the same lazy/best-effort in-process MCP reconnect at the _handler tool-invocation site in tools/mcp_tool.py. When not server or not server.session, both introduce a helper (here _try_reconnect_disconnected_server; #23540's _get_connected_server_for_call) that pops the stale _servers entry and calls discover_mcp_tools() to reconnect before surfacing the MCP server '<name>' is not connected error. Same file, same edit site, same mechanism. #23540 is the earlier still-open version, so consolidating there.

@gitgrooves

Copy link
Copy Markdown
Author

Closed: opened in error; withdrawing this patch from public review.

@gitgrooves gitgrooves closed this Jun 21, 2026
@gitgrooves
gitgrooves deleted the fix/mcp-stale-wrapper-reconnect branch June 21, 2026 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists 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