Skip to content

The agent that grows with you

fix(mcp): `hermes mcp test` exits non-zero on connection failure and unknown server

lofibrainwava34cd92a89c6
diff --git a/hermes_cli/main.py b/hermes_cli/main.py
index 54eff5e9095..36d83e206f0 100644
--- a/hermes_cli/main.py
+++ b/hermes_cli/main.py
@@ -1865,7 +1865,7 @@ def _forward_command(name: str, module: str, attr: str, *, forward_return: bool
Imports at CALL time so fast paths never pay for it and
``patch("<module>.<attr>")`` keeps intercepting. ``forward_return``
- surfaces the return code to ``main()`` (only kanban/project propagate).
+ surfaces the return code to ``main()`` (kanban/project/mcp propagate).
"""
def _cmd(args):
@@ -1899,7 +1899,7 @@ cmd_gateway_enroll = _forward_command("cmd_gateway_enroll", "hermes_cli.gateway_
cmd_prompt_size = _forward_command("cmd_prompt_size", "hermes_cli.prompt_size", "cmd_prompt_size", doc='Show a byte/char breakdown of the system prompt + tool schemas.')
cmd_pairing = _forward_command("cmd_pairing", "hermes_cli.pairing", "pairing_command")
cmd_plugins = _forward_command("cmd_plugins", "hermes_cli.plugins_cmd", "plugins_command")
-cmd_mcp = _forward_command("cmd_mcp", "hermes_cli.mcp_config", "mcp_command")
+cmd_mcp = _forward_command("cmd_mcp", "hermes_cli.mcp_config", "mcp_command", forward_return=True)
cmd_claw = _forward_command("cmd_claw", "hermes_cli.claw", "claw_command")
cmd_import_agent = _forward_command("cmd_import_agent", "hermes_cli.agent_import", "import_agent_command")
diff --git a/hermes_cli/mcp_config.py b/hermes_cli/mcp_config.py
index 32bc7247c33..2216a45bd02 100644
--- a/hermes_cli/mcp_config.py
+++ b/hermes_cli/mcp_config.py
@@ -759,11 +759,16 @@ def _probe_failure_next_step(name: str, exc: BaseException) -> str:
def cmd_mcp_test(args):
- """Test connection to an MCP server."""
+ """Test connection to an MCP server.
+
+ Returns the process exit code so health probes and watchdogs can branch on ``$?`` instead of
+ parsing the output: 0 connected, 1 connection failed, 3 server not in the config (argparse
+ already owns 2 for usage errors, so "no such server" stays distinguishable from "bad flags").
+ """
name = args.name
cfg = _lookup_server(name, _get_mcp_servers(), "Available")
if cfg is None:
- return
+ return 3
print()
print(color(f" Testing '{name}'...", Colors.CYAN))
if "url" in cfg:
@@ -790,13 +795,14 @@ def cmd_mcp_test(args):
elapsed = time.monotonic() - start
_error(f"Connection failed ({elapsed:.1f}s): {_probe_failure_reason(exc)}")
_info(_probe_failure_next_step(name, exc))
- return
+ return 1
_success(f"Connected ({(time.monotonic() - start) * 1000:.0f}ms)")
_success(f"Tools discovered: {len(tools)}")
if tools:
print()
_print_tools(tools, 36, 55)
print()
+ return 0
def _reauth_oauth_server(name: str, server_config: dict, *, flow: str | None = None) -> bool:
@@ -1080,8 +1086,8 @@ def mcp_command(args):
"config": cmd_mcp_configure, "login": cmd_mcp_login, "reauth": cmd_mcp_reauth,
}.get(action)
if handler:
- handler(args)
- return
+ # A handler's int return is the process exit code (``main()`` exits non-zero on it).
+ return handler(args)
# No subcommand — drop the user into the catalog picker (same UX as `hermes plugin`).
from hermes_cli.mcp_picker import run_picker
run_picker()