Skip to content

fix: prevent nested subparser commands from falling through to chat REPL - #18469

Closed
gruuna-bannert wants to merge 1 commit into
NousResearch:mainfrom
gruuna-bannert:fix/mcp-subparser-dispatch-4184
Closed

fix: prevent nested subparser commands from falling through to chat REPL#18469
gruuna-bannert wants to merge 1 commit into
NousResearch:mainfrom
gruuna-bannert:fix/mcp-subparser-dispatch-4184

Conversation

@gruuna-bannert

Copy link
Copy Markdown

Summary

Fixes #4184hermes mcp add (and other nested subparser commands) incorrectly falling through to the chat REPL instead of executing the intended subcommand.

Root Cause

On Python 3.11, argparse's nested subparser handling may leave args.func set to the parent parser's default (cmd_chat) instead of propagating the child subparser's set_defaults(func=...). The existing dispatch logic checked args.func but didn't distinguish between a genuine bare invocation and a nested-subparser bug.

Fix

When args.func == cmd_chat, check for subcommand-specific attributes (mcp_action, cron_command, gateway_command) that indicate a real subcommand was parsed. If found, dispatch to the correct handler instead of falling through to chat.

Additionally, when args.func points to a real subcommand handler (not cmd_chat), dispatch it immediately without further checks.

When using nested subparsers (e.g. `hermes mcp add`), Python 3.11's
argparse may leave args.func set to the parent parser's default (cmd_chat)
instead of propagating the child subparser's func. This caused MCP, cron,
and gateway subcommands to incorrectly enter the chat REPL.

Fix: check for subcommand-specific attributes (mcp_action, cron_command,
gateway_command) when args.func == cmd_chat, and dispatch to the correct
handler if one is found.

Closes NousResearch#4184
@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/cli CLI entry point, hermes_cli/, setup wizard labels May 1, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #4189 — both fix nested subparser dispatch falling through to chat REPL (#4184).

1 similar comment
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #4189 — both fix nested subparser dispatch falling through to chat REPL (#4184).

@gruuna-bannert

Copy link
Copy Markdown
Author

@alt-glitch But #4189 is extremely bloated and includes many unrelated changes.

@teknium1

Copy link
Copy Markdown
Contributor

This appears to be implemented on current main. Automated hermes-sweeper review found that the reported hermes mcp add fall-through to the chat REPL has been fixed by a later focused parser change.

Evidence:

  • hermes_cli/subcommands/mcp.py:45 now declares the MCP add --command flag with dest="mcp_command", with an inline note that this avoids clobbering the top-level args.command and falling through to interactive chat.
  • hermes_cli/subcommands/mcp.py:104 keeps the mcp parser routed through func=cmd_mcp.
  • hermes_cli/mcp_config.py:286 reads args.mcp_command, so the user-facing --command flag still works.
  • tests/hermes_cli/test_mcp_add_command_dest.py:49 covers hermes mcp add foo --url ... and asserts args.command == "mcp" instead of None.
  • Fix commit: 4f364c4e99d46a0c50d3ea1d5ad179f54348f9f7 (fix(mcp): give 'mcp add --command' a distinct argparse dest), contained in v2026.5.7 and later tags.

Thanks for the focused PR and for the follow-up discussion about #4189 being broader than necessary; the narrower behavior this PR targeted is now covered on main.

@teknium1 teknium1 closed this Jun 10, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P1 High — major feature broken, no workaround sweeper:implemented-on-main Sweeper: behavior already present on current main type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hermes mcp add falls through to chat REPL due to nested subparser dispatch bug

3 participants