| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- """``hermes mcp`` subcommand parser."""
- from __future__ import annotations
- import argparse
- from typing import Callable
- def build_mcp_parser(subparsers, *, cmd_mcp: Callable) -> None:
- """Attach the ``mcp`` subcommand to ``subparsers``."""
- mcp_parser = subparsers.add_parser(
- "mcp", help="Manage MCP server connections",
- description="Manage MCP server connections.\n\n"
- "MCP servers provide additional tools via the Model Context Protocol.\n"
- "Use 'hermes mcp add' to connect to a new server. Running Hermes itself as an\n"
- "MCP server is the mcp-serve plugin: `hermes plugins install mcp-serve`.")
- mcp_sub = mcp_parser.add_subparsers(dest="mcp_action")
- mcp_add_p = mcp_sub.add_parser("add", help="Add an MCP server (discovery-first install)")
- mcp_add_p.add_argument("name", help="Server name (used as config key)")
- mcp_add_p.add_argument("--url", help="HTTP/SSE endpoint URL")
- # dest="mcp_command": the default dest="command" would clobber the top-level
- # subcommand name the dispatcher routes on (None when omitted → falls into chat).
- mcp_add_p.add_argument("--command", dest="mcp_command", help="Stdio command (e.g. npx)")
- mcp_add_p.add_argument(
- "--args", nargs=argparse.REMAINDER, default=[],
- help="Arguments for stdio command; must be the last option")
- 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="*", default=[], help="Environment variables for stdio servers (KEY=VALUE)")
- mcp_rm_p = mcp_sub.add_parser("remove", aliases=["rm"], help="Remove an MCP server")
- mcp_rm_p.add_argument("name", help="Server name to remove")
- mcp_sub.add_parser("list", aliases=["ls"], help="List configured MCP servers")
- mcp_test_p = mcp_sub.add_parser("test", help="Test MCP server connection")
- mcp_test_p.add_argument("name", help="Server name to test")
- mcp_cfg_p = mcp_sub.add_parser("configure", aliases=["config"], help="Toggle tool selection")
- mcp_cfg_p.add_argument("name", help="Server name to configure")
- mcp_login_p = mcp_sub.add_parser(
- "login", help="Force re-authentication for an OAuth-based MCP server")
- mcp_login_p.add_argument("name", help="Server name to re-authenticate")
- mcp_login_p.add_argument(
- "--flow", choices=["browser", "device"], default=None,
- help="OAuth flow (overrides oauth.flow): browser PKCE or RFC 8628 device code")
- mcp_reauth_p = mcp_sub.add_parser(
- "reauth", help="Re-authenticate one OAuth MCP server, or all of them (--all)")
- mcp_reauth_p.add_argument(
- "name", nargs="?", help="Server name to re-authenticate (omit with --all)")
- mcp_reauth_p.add_argument(
- "--all", action="store_true",
- help="Re-authenticate every OAuth server in config, one at a time")
- # Catalog (Nous-approved MCPs shipped with the repo)
- mcp_sub.add_parser(
- "picker", help="Interactive catalog picker (also the default for `hermes mcp`)")
- mcp_sub.add_parser("catalog", help="List Nous-approved MCPs available for one-click install")
- mcp_install_p = mcp_sub.add_parser(
- "install", help="Install a catalog MCP by name (e.g. `hermes mcp install deepwiki`)")
- mcp_install_p.add_argument("identifier", help="Catalog entry name (or `official/<name>`)")
- mcp_parser.set_defaults(func=cmd_mcp)
|