mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-31 19:16:29 +00:00
fix(acp): allow hosts to skip configured MCP startup
This commit is contained in:
parent
615a0d9141
commit
366242e479
2 changed files with 52 additions and 5 deletions
|
|
@ -32,6 +32,7 @@ else:
|
|||
import argparse
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from hermes_constants import get_hermes_home
|
||||
|
|
@ -251,11 +252,13 @@ def main(argv: list[str] | None = None) -> None:
|
|||
# MCP servers dynamically via asyncio.to_thread inside the event
|
||||
# loop; that path is unaffected.) Moved from model_tools.py module
|
||||
# scope to avoid freezing the gateway's loop on lazy import (#16856).
|
||||
try:
|
||||
from tools.mcp_tool import discover_mcp_tools
|
||||
discover_mcp_tools()
|
||||
except Exception:
|
||||
logger.debug("MCP tool discovery failed at ACP startup", exc_info=True)
|
||||
# Metadata-only hosts can opt out of unrelated global MCP startup.
|
||||
if os.environ.get("HERMES_ACP_SKIP_CONFIGURED_MCP", "").strip() != "1":
|
||||
try:
|
||||
from tools.mcp_tool import discover_mcp_tools
|
||||
discover_mcp_tools()
|
||||
except Exception:
|
||||
logger.debug("MCP tool discovery failed at ACP startup", exc_info=True)
|
||||
|
||||
agent = HermesACPAgent()
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -23,6 +23,50 @@ def test_main_enables_unstable_protocol(monkeypatch):
|
|||
assert calls["kwargs"]["use_unstable_protocol"] is True
|
||||
|
||||
|
||||
def test_main_skips_configured_mcp_discovery_when_requested(monkeypatch):
|
||||
discovery_calls = []
|
||||
|
||||
async def fake_run_agent(agent, **kwargs):
|
||||
pass
|
||||
|
||||
monkeypatch.setattr(entry, "_setup_logging", lambda: None)
|
||||
monkeypatch.setattr(entry, "_load_env", lambda: None)
|
||||
monkeypatch.setenv("HERMES_ACP_SKIP_CONFIGURED_MCP", "1")
|
||||
monkeypatch.setattr(
|
||||
"tools.mcp_tool.discover_mcp_tools",
|
||||
lambda: discovery_calls.append(True),
|
||||
)
|
||||
monkeypatch.setattr(acp, "run_agent", fake_run_agent)
|
||||
|
||||
entry.main([])
|
||||
|
||||
assert discovery_calls == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize("skip_value", [None, "", "0", "false"])
|
||||
def test_main_discovers_configured_mcp_when_skip_is_not_enabled(monkeypatch, skip_value):
|
||||
discovery_calls = []
|
||||
|
||||
async def fake_run_agent(agent, **kwargs):
|
||||
pass
|
||||
|
||||
monkeypatch.setattr(entry, "_setup_logging", lambda: None)
|
||||
monkeypatch.setattr(entry, "_load_env", lambda: None)
|
||||
if skip_value is None:
|
||||
monkeypatch.delenv("HERMES_ACP_SKIP_CONFIGURED_MCP", raising=False)
|
||||
else:
|
||||
monkeypatch.setenv("HERMES_ACP_SKIP_CONFIGURED_MCP", skip_value)
|
||||
monkeypatch.setattr(
|
||||
"tools.mcp_tool.discover_mcp_tools",
|
||||
lambda: discovery_calls.append(True),
|
||||
)
|
||||
monkeypatch.setattr(acp, "run_agent", fake_run_agent)
|
||||
|
||||
entry.main([])
|
||||
|
||||
assert discovery_calls == [True]
|
||||
|
||||
|
||||
def test_main_version_prints_without_starting_server(monkeypatch, capsys):
|
||||
monkeypatch.setattr(entry, "_setup_logging", lambda: (_ for _ in ()).throw(AssertionError("started server")))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue