From d52d2973a113d7891b8cc188d40de68550a62985 Mon Sep 17 00:00:00 2001 From: Sam Beran Date: Sun, 5 Jul 2026 15:21:00 -0700 Subject: [PATCH] feat(cli): add --connect-timeout flag to hermes mcp add Persists as the server's connect_timeout in config, which the probe now honors. CLI-flag portion of PR #54494; the probe-wrapper portion was superseded by resolving connect_timeout inside _probe_single_server. --- hermes_cli/mcp_config.py | 3 +++ hermes_cli/subcommands/mcp.py | 5 +++++ tests/hermes_cli/test_mcp_add_command_dest.py | 20 +++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/hermes_cli/mcp_config.py b/hermes_cli/mcp_config.py index 5304935b8e9..6c6db1bdc83 100644 --- a/hermes_cli/mcp_config.py +++ b/hermes_cli/mcp_config.py @@ -397,6 +397,7 @@ def cmd_mcp_add(args): auth_type = getattr(args, "auth", None) preset_name = getattr(args, "preset", None) raw_env = getattr(args, "env", None) + raw_connect_timeout = getattr(args, "connect_timeout", None) server_config: Dict[str, Any] = {} try: @@ -442,6 +443,8 @@ def cmd_mcp_add(args): server_config["args"] = cmd_args if explicit_env: server_config["env"] = explicit_env + if raw_connect_timeout is not None: + server_config["connect_timeout"] = raw_connect_timeout issues = validate_mcp_server_entry(name, server_config) if issues: diff --git a/hermes_cli/subcommands/mcp.py b/hermes_cli/subcommands/mcp.py index c21a635b86e..387a88e85ad 100644 --- a/hermes_cli/subcommands/mcp.py +++ b/hermes_cli/subcommands/mcp.py @@ -60,6 +60,11 @@ def build_mcp_parser(subparsers, *, cmd_mcp: Callable) -> None: ) mcp_add_p.add_argument("--auth", choices=["oauth", "header"], help="Auth method") mcp_add_p.add_argument("--preset", help="Known MCP preset name") + mcp_add_p.add_argument( + "--connect-timeout", + type=float, + help="Timeout in seconds for initial connection and tool discovery", + ) mcp_add_p.add_argument( "--env", nargs="*", diff --git a/tests/hermes_cli/test_mcp_add_command_dest.py b/tests/hermes_cli/test_mcp_add_command_dest.py index 2e7a3f2de0c..6fbd95510cc 100644 --- a/tests/hermes_cli/test_mcp_add_command_dest.py +++ b/tests/hermes_cli/test_mcp_add_command_dest.py @@ -41,6 +41,7 @@ def _build_parser(): mcp_add.add_argument("name") mcp_add.add_argument("--url") mcp_add.add_argument("--command", dest="mcp_command") + mcp_add.add_argument("--connect-timeout", type=float) mcp_add.add_argument("--args", nargs=argparse.REMAINDER, default=[]) return parser @@ -87,6 +88,25 @@ class TestMcpAddCommandDest: assert args.mcp_command is None assert args.url is None + def test_connect_timeout_flag_sets_probe_timeout(self): + """`--connect-timeout` exposes the per-server discovery timeout.""" + parser = _build_parser() + args = parser.parse_args( + [ + "mcp", + "add", + "slow", + "--url", + "https://example.com/mcp", + "--connect-timeout", + "180", + ] + ) + + assert args.command == "mcp" + assert args.mcp_action == "add" + assert args.connect_timeout == 180 + def test_args_passthrough_keeps_nested_option_flags(self): """`--args` must keep command flags like Docker MCP's --profile.""" parser = _build_parser()