Skip to content

fix(tui-gateway): scope MCP discovery to the selected profile (Desktop/dashboard) - #72219

Merged
teknium1 merged 4 commits into
mainfrom
hermes/hermes-be2de496
Jul 26, 2026
Merged

teknium1 merged 4 commits into
mainfrom
hermes/hermes-be2de496

Conversation

@teknium1

Copy link
Copy Markdown
Collaborator

Summary

MCP tools now load for the selected profile in the Desktop app / dashboard chat, instead of silently discovering the launch profile's (often empty) mcp_servers. Fixes the MCP half of #67605; salvage of #72135 by @LionGateOS with follow-up hardening.

Root cause: the WS sidecar started one process-global discovery thread gated on the process home's config, and the ContextVar profile override (set_hermes_home_override) never propagated into the bare discovery thread — so a dashboard launched under a profile without mcp_servers served zero MCP tools to every profile.

Changes

  • tui_gateway/ws.py: WS transport no longer owns MCP discovery startup (contributor).
  • tui_gateway/server.py: _start_agent_build starts discovery AFTER binding the session profile's HERMES_HOME; verification.status gains @_profile_scoped (contributor).
  • tui_gateway/entry.py: ensure_mcp_discovery_started() routes through the shared owner in hermes_cli.mcp_startup (keeps start lock, retry-after-zero-connected, OAuth suppression); stdio TUI main() startup discovery and the _mcp_discovery_enabled retry gate are restored (follow-up).
  • hermes_cli/mcp_startup.py: the shared owner captures the caller's context-local HERMES_HOME override and re-installs it inside the discovery thread (follow-up).
  • Tests: contributor's profile-scoped regression tests adapted to the shared-owner path; 3 WSTransport regression tests the original branch deleted are restored.

Known limitation (documented in-code): MCP registration is process-global, so the first profile to build an agent wins the discovery slot. Full per-profile registries stay tracked in #67605, which remains open for the secrets/${VAR}/MoA halves.

Validation

Check Result
tests/test_tui_gateway_server.py (466) pass
tests/test_tui_gateway_ws.py, tests/hermes_cli/test_mcp_startup.py, tests/tui_gateway/ (983 total) pass
Sabotage run (fix reverted) regression test fails as expected
E2E (real imports, temp HERMES_HOME, launch profile without / selected profile with mcp_servers) 5/5 scenarios pass, incl. caller-resets-override race and no-override CLI path unchanged

Infographic

Profile-scoped MCP discovery

LionGateOS and others added 4 commits July 26, 2026 14:02
…y owner; restore stdio startup + WSTransport tests

Follow-up to @LionGateOS's #72135 salvage:
- Route ensure_mcp_discovery_started through hermes_cli.mcp_startup's
  shared owner instead of a hand-rolled bare thread, keeping the start
  lock, retry-after-zero-connected allowance, and interactive-OAuth
  suppression. The shared owner now captures the caller's context-local
  HERMES_HOME override and re-installs it inside the discovery thread,
  so discovery reads the selected profile's mcp_servers (#67605).
- Restore stdio TUI startup discovery in main() and the
  _mcp_discovery_enabled retry gate in wait_for_mcp_discovery, both
  dropped by the original branch.
- Restore the 3 WSTransport regression tests (send serialization,
  cross-batch ordering, drained-token ordering) deleted by the PR.
- Harden the profile-scoped discovery test against sibling-state leaks.
@github-actions

github-actions Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

૮ >ﻌ< ა ci review

ran on d55feae

all good!

@alt-glitch alt-glitch added type/bug Something isn't working comp/cli CLI entry point, hermes_cli/, setup wizard comp/tui Terminal UI (ui-tui/ + tui_gateway/) tool/mcp MCP client and OAuth area/profiles Multi-profile isolation, HERMES_HOME scoping P2 Medium — degraded but workaround exists labels Jul 26, 2026
@LionGateOS

LionGateOS commented Jul 26, 2026 via email

Copy link
Copy Markdown
Contributor

@LionGateOS

LionGateOS commented Jul 26, 2026 via email

Copy link
Copy Markdown
Contributor

@LionGateOS

Copy link
Copy Markdown
Contributor

Thanks for the review and for carrying this through. I'm glad the profile-scoped MCP discovery fix made it into main.

I appreciate preserving the original work and the additional hardening around the shared discovery owner, profile HERMES_HOME propagation, and regression coverage.

I'll keep an eye on the remaining #67605 items as they progress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/profiles Multi-profile isolation, HERMES_HOME scoping comp/cli CLI entry point, hermes_cli/, setup wizard comp/tui Terminal UI (ui-tui/ + tui_gateway/) 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.

3 participants