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

Class ExecuteToolCommand

src/mcp_cli/commands/tools/execute_tool.py:30–519  ·  view source on GitHub ↗

Command to execute a tool with parameters.

Source from the content-addressed store, hash-verified

28
29
30class ExecuteToolCommand(UnifiedCommand):
31 """Command to execute a tool with parameters."""
32
33 def __init__(self) -> None:
34 """Initialize the execute tool command."""
35 super().__init__()
36 self._name: str = "execute"
37 self._description: str = "Execute a tool with parameters"
38 self._modes: CommandMode = CommandMode.INTERACTIVE | CommandMode.CHAT
39 self._aliases: list[str] = ["exec", "run"]
40 self._parameters: list[CommandParameter] = [
41 CommandParameter(
42 name="tool",
43 type=str,
44 help="Name of the tool to execute",
45 required=False,
46 ),
47 CommandParameter(
48 name="params",
49 type=str,
50 help="Tool parameters as JSON string",
51 required=False,
52 ),
53 CommandParameter(
54 name="server",
55 type=str,
56 help="Server to use (if multiple available)",
57 required=False,
58 ),
59 ]
60 self._help_text: str = """
61Execute a tool with JSON parameters.
62
63Usage:
64 execute # List all available tools
65 execute <tool_name> # Show tool parameters and format
66 execute <tool_name> '<json>' # Execute tool with parameters
67
68IMPORTANT: Parameters must be in JSON format!
69
70Examples:
71 execute # See what tools are available
72 execute echo_text # See what parameters echo_text needs
73 execute echo_text '{"message": "Hello"}' # Execute with JSON parameters
74 execute list_tables '{}' # Execute tool with no parameters
75
76Common Mistakes to Avoid:
77 ❌ execute echo_text "hello" # Wrong: Not JSON format
78 ✅ execute echo_text '{"message": "hello"}' # Correct: Proper JSON
79
80Tips:
81 • Always use JSON format: '{"key": "value"}'
82 • Use single quotes around JSON to avoid escaping
83 • Use '{}' for tools with no required parameters
84 • Check parameters first with: execute <tool_name>
85"""
86 self._requires_context: bool = True
87

Callers 6

register_all_commandsFunction · 0.90
execute_commandFunction · 0.90
execute_commandFunction · 0.90
execute_commandFunction · 0.90

Calls

no outgoing calls

Tested by 5

execute_commandFunction · 0.72
execute_commandFunction · 0.72
execute_commandFunction · 0.72