MCPcopy Create free account
hub / github.com/IBM/mcp-cli / execute

Method execute

src/mcp_cli/commands/core/help.py:66–189  ·  view source on GitHub ↗

Execute the help command.

(self, **kwargs)

Source from the content-addressed store, hash-verified

64 return False
65
66 async def execute(self, **kwargs) -> CommandResult:
67 """Execute the help command."""
68 command_name = kwargs.get("command") or kwargs.get("args")
69
70 # Handle list arguments
71 if isinstance(command_name, list):
72 command_name = command_name[0] if command_name else None
73
74 # Get the registry singleton instance
75 registry = UnifiedCommandRegistry()
76
77 # Determine which mode we're in based on context
78 mode = kwargs.get("mode", CommandMode.CHAT)
79
80 try:
81 if command_name:
82 # Show help for specific command
83 command = registry.get(command_name, mode=mode)
84 if not command:
85 return CommandResult(
86 success=False,
87 error=f"Unknown command: {command_name}",
88 )
89
90 # Display command help directly
91 help_content = (
92 f"## {command.name}\n\n{command.help_text or command.description}"
93 )
94 output.panel(
95 help_content,
96 title="Command Help",
97 style="cyan",
98 )
99
100 if command.aliases:
101 output.print(f"\n[dim]Aliases: {', '.join(command.aliases)}[/dim]")
102 help_content += f"\n\nAliases: {', '.join(command.aliases)}"
103
104 return CommandResult(success=True, output=help_content)
105
106 else:
107 # List all available commands
108 commands = registry.list_commands(mode=mode)
109
110 if not commands:
111 return CommandResult(
112 success=True,
113 output="No commands available.",
114 )
115
116 # Format as table
117 table_data = []
118 for cmd in commands:
119 # Check if this is a command group with subcommands
120 from mcp_cli.commands.base import CommandGroup
121
122 has_subcommands = (
123 isinstance(cmd, CommandGroup)

Calls 4

getMethod · 0.95
list_commandsMethod · 0.95
CommandResultClass · 0.90