Skip to content

MCP tools discovered but not exposed to agent in TUI mode #41625

Description

@xinfengz194-cpu

Bug Description

MCP server tools are successfully discovered by hermes mcp test (3 tools found), but they do not appear in the agent's available tool list during a TUI session. The agent cannot call MCP tools even though the server is connected and tools are registered.

Steps to Reproduce

  1. Configure an MCP server in ~/.hermes/config.yaml with HTTP transport (url-based)
  2. Start the MCP server (confirm the port is listening)
  3. Run hermes mcp test <name> → succeeds, discovers tools
  4. Start a TUI session (hermes)
  5. The agent does not see or cannot call MCP tools

Expected Behavior

MCP tools should be available as first-class tools in the agent session after successful discovery.

Investigation

Looking at the source code, I suspect a race condition in the TUI startup path:

  1. hermes_cli/main.py:_prepare_agent_startup() skips inline MCP discovery for TUI launches (_is_tui_chat_launch returns True → _run_inline_mcp_discovery = False)
  2. The comment says: "The TUI launcher hands off to a dedicated startup path that already backgrounds MCP discovery with a bounded join before the first tool snapshot."
  3. In hermes_cli/mcp_startup.py, wait_for_mcp_discovery() has a timeout of only 0.75 seconds
  4. If the MCP server takes longer than 0.75s to connect and enumerate tools, the tool snapshot is taken before MCP tools are registered
  5. hermes mcp test works because it runs synchronously with its own timeout

The 0.75s timeout in wait_for_mcp_discovery() is likely too short for HTTP-based MCP servers, especially on first connection.

Environment

  • OS: Windows 10
  • Hermes Agent: latest (via hermes update)
  • MCP server: HTTP transport (url-based config)
  • Shell: git-bash / MSYS

Possible Fix

Either increase wait_for_mcp_discovery() timeout (e.g. to 5-10s), or add a mechanism to inject MCP tools into an already-running agent session after late discovery completes (similar to what /reload-mcp does).

Activity

  1. added
    type/bugSomething isn't working
    P2Medium — degraded but workaround exists
    tool/mcpMCP client and OAuth
    comp/tuiTerminal UI (ui-tui/ + tui_gateway/)
    on Jun 8, 2026
  2. liuhao1024 commented on Jun 8, 2026

    @liuhao1024

    This is fixed by #41630 — increases wait_for_mcp_discovery timeout from 0.75s to 3.0s so MCP tools register before the first tool snapshot.

  3. dsgvo-dev commented on Jun 8, 2026

    @dsgvo-dev

    I updated to upstream 4219a91 and also verified/patched the TUI discovery timeout manually.

    Before patch:
    ~/.hermes/hermes-agent/tui_gateway/entry.py:
    def wait_for_mcp_discovery(timeout: float = 0.75) -> None:

    After local patch:
    def wait_for_mcp_discovery(timeout: float = 3.0) -> None:

    Gateway was restarted. However, the issue persists.

    One-shot still fails as well:

    hermes -t "hermes-cli,dsms-knowledge" -z "Du darfst kein Terminal, kein Python, kein Execute Code, kein Write File und kein Read File verwenden. Rufe ausschließlich das MCP-Tool search_knowledge des Servers dsms-knowledge auf mit query='Volkszählungsurteil', collection='urteile', n_results=5. Wenn nicht verfügbar, antworte exakt MCP_TOOL_NOT_AVAILABLE."

    Actual result:
    MCP_TOOL_NOT_AVAILABLE

    So increasing the TUI wait_for_mcp_discovery timeout is not sufficient in this setup.

    Environment:

    • macOS
    • Hermes v0.16.0 (2026.6.5), upstream 4219a91
    • MCP transport: stdio via uvx
    • MCP server: dsms-knowledge
    • hermes mcp test dsms-knowledge succeeds in ~1.5s and discovers search_knowledge/list_collections
    • hermes tools list shows: dsms-knowledge all tools enabled
    • config.yaml contains dsms-knowledge in both toolsets and platform_toolsets.cli
    • actual agent tool schema still does not expose the MCP tools
  4. dsgvo-dev commented on Jun 9, 2026

    @dsgvo-dev

    Confirming this bug on macOS with two findings that broaden the scope beyond TUI: the same failure mode occurs in the headless -z path, and a --toolsets override using the documented mcp-<server> dynamic name is rejected by the resolver as unknown.

    Environment

    • OS: macOS (Apple Silicon)
    • Hermes Agent: v0.16.0 (2026.6.5), current after hermes update (as of 2026-06-09)
    • MCP server: local stdio via uvx, with a non-trivial cold start (~1 s measured via hermes mcp test)

    MCP server is fully healthy

    • hermes mcp list shows the server as ✓ enabled, all tools.
    • hermes mcp test <server> connects in ~1 s and reports ✓ Tools discovered: <N>.
    • Inside a TUI session, /tools list lists the server under MCP servers: <server> all tools enabled.
    • Direct invocation of the underlying MCP server process outside Hermes works correctly.

    So discovery and registration succeed at every layer except the model's function-call schema.

    Finding 1: -z (headless) is affected, not just --tui

    When the agent is run with hermes -z and prompted to call an MCP tool — with explicit instructions that bypass mechanisms (Terminal, Python, execute_code, write_file, read_file) are forbidden, and that the agent must reply with a specific sentinel if the tool is missing from its schema — the agent reports the sentinel. The MCP tool name (mcp_<server>_<tool>) is not in the agent's tool list.

    This rules out the TUI-only race-condition hypothesis (wait_for_mcp_discovery() with 0.75 s timeout in the TUI startup path) as a complete explanation: the -z path should run discovery synchronously before snapshotting tools, yet it produces the same outcome. Either the same race exists there, or a separate injection path drops MCP tools regardless of timing.

    Finding 2: mcp-<server> toolset name is rejected as unknown by -t

    When invoking with hermes -t "hermes-cli,mcp-<server>" -z "...", Hermes emits:

    hermes -z: ignoring unknown --toolsets entries: mcp-<server>
    

    …and falls back to hermes-cli. This contradicts the Toolsets Reference and the MCP guide:

    "Each configured MCP server also creates a runtime toolset when it contributes at least one registered tool: mcp-<server>."

    The warning means the dynamic toolset is either not registered under that name by the time -t is parsed, or never registered at all. Either way, this is a documentation/implementation mismatch that every operator following the docs will hit.

    Suggested broader scope

    In addition to the TUI startup-path fix already proposed in this issue:

    • Apply the same fix to the headless (-z) path: either block schema construction until MCP discovery completes, or rebuild the schema after late discovery.
    • Either register mcp-<server> toolsets synchronously at config-load time (before -t is validated), or accept mcp-<server> lazily without warning when the server entry exists in mcp_servers.
    • Add a regression test that runs hermes -z -t "hermes-cli,mcp-<server>" "..." with a stdio MCP server whose cold start exceeds 750 ms, asserting that the MCP tools appear in the agent's tool schema.

    Direct invocation of the MCP server process (outside Hermes) succeeds with the same query that fails inside Hermes, so the bug is strictly on the Hermes side between MCP registration and model tool-schema injection.

  5. dwest-mmc commented on Jun 12, 2026

    @dwest-mmc

    Corroborating from the stdio side: hermes-agent v0.16.0, macOS, local stdio server — cold spawn + handshake exceeded 0.75 s during bring-up (first discoveries in the 1–3 s range). Two notes:

  6. Xande-p commented on Jun 19, 2026

    @Xande-p

    I would say the severity of this bug is greater then P2 (medium). I have exactly one MCP server (deapi) and had given up on tui because of this bug. The docs say the TUI is the main client, so maybe this bug report should be bumped.

    My workaround is, in tui_gateway/entry.py, remove the background Thread target structure _discover_mcp_background and replace it with a direct call to discover_mcp_tools() at startup. A second slower, but works.

  7. added a commit that references this issue on Sep 10, 2026
    5bf5991
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existscomp/tuiTerminal UI (ui-tui/ + tui_gateway/)tool/mcpMCP client and OAuthtype/bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions