Skip to content

Commit 7d385e6

Browse files
author
LittleCoinCoin
committed
feat(cli): enhance mcp configure command argument structure
Improve usability by converting positional arguments to flags and adding mutual exclusivity validation: - Make server_name the only positional argument - Convert host to required --host flag - Create mutually exclusive group for --command and --url - Add optional --args flag for command arguments - Implement proper validation for conflicting arguments This change makes the CLI more intuitive and prevents user errors by clearly separating local server (--command) and remote server (--url) configuration options. Examples: hatch mcp configure weather-server --host claude-desktop --command python --args weather_server.py hatch mcp configure api-service --host cursor --url https://api.example.com/mcp Addresses user feedback on CLI usability and follows object-action pattern for improved command structure consistency.
1 parent 505ad2b commit 7d385e6

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

hatch/cli_hatch.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,15 @@ def handle_mcp_configure(host: str, server_name: str, command: str, args: list,
525525
print(f"Error: Invalid host '{host}'. Supported hosts: {[h.value for h in MCPHostType]}")
526526
return 1
527527

528+
# Validate argument dependencies
529+
if command and headers:
530+
print("Error: --headers can only be used with --url (remote servers), not with --command (local servers)")
531+
return 1
532+
533+
if url and args:
534+
print("Error: --args can only be used with --command (local servers), not with --url (remote servers)")
535+
return 1
536+
528537
# Parse environment variables and headers
529538
env_dict = parse_env_vars(env)
530539
headers_dict = parse_headers(headers)
@@ -1006,13 +1015,17 @@ def main():
10061015

10071016
# MCP direct management commands
10081017
mcp_configure_parser = mcp_subparsers.add_parser("configure", help="Configure MCP server directly on host")
1009-
mcp_configure_parser.add_argument("host", help="Host platform to configure (e.g., claude-desktop, cursor)")
10101018
mcp_configure_parser.add_argument("server_name", help="Name for the MCP server")
1011-
mcp_configure_parser.add_argument("server_command", help="Command to execute the MCP server")
1012-
mcp_configure_parser.add_argument("args", nargs="*", help="Arguments for the MCP server command")
1019+
mcp_configure_parser.add_argument("--host", required=True, help="Host platform to configure (e.g., claude-desktop, cursor)")
1020+
1021+
# Create mutually exclusive group for server type
1022+
server_type_group = mcp_configure_parser.add_mutually_exclusive_group(required=True)
1023+
server_type_group.add_argument("--command", help="Command to execute the MCP server (for local servers)")
1024+
server_type_group.add_argument("--url", help="Server URL for remote MCP servers")
1025+
1026+
mcp_configure_parser.add_argument("--args", nargs="*", help="Arguments for the MCP server command (only with --command)")
10131027
mcp_configure_parser.add_argument("--env", "-e", action="append", help="Environment variables (format: KEY=VALUE)")
1014-
mcp_configure_parser.add_argument("--url", help="Server URL for remote MCP servers")
1015-
mcp_configure_parser.add_argument("--headers", action="append", help="HTTP headers for remote servers (format: KEY=VALUE)")
1028+
mcp_configure_parser.add_argument("--headers", action="append", help="HTTP headers for remote servers (format: KEY=VALUE, only with --url)")
10161029
mcp_configure_parser.add_argument("--no-backup", action="store_true", help="Skip backup creation before configuration")
10171030
mcp_configure_parser.add_argument("--dry-run", action="store_true", help="Preview configuration without execution")
10181031
mcp_configure_parser.add_argument("--auto-approve", action="store_true", help="Skip confirmation prompts")
@@ -1553,7 +1566,7 @@ def main():
15531566

15541567
elif args.mcp_command == "configure":
15551568
return handle_mcp_configure(
1556-
args.host, args.server_name, args.server_command, args.args,
1569+
args.host, args.server_name, args.command, args.args,
15571570
args.env, args.url, args.headers, args.no_backup,
15581571
args.dry_run, args.auto_approve
15591572
)

0 commit comments

Comments
 (0)