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

Method execute

src/mcp_cli/commands/tools/tools.py:80–190  ·  view source on GitHub ↗

Execute the tools command.

(self, **kwargs)

Source from the content-addressed store, hash-verified

78 ]
79
80 async def execute(self, **kwargs) -> CommandResult:
81 """Execute the tools command."""
82 # Get context and tool manager
83 context = get_context()
84 if not context or not context.tool_manager:
85 return CommandResult(
86 success=False,
87 error="No tool manager available. Please connect to a server first.",
88 )
89
90 tm = context.tool_manager
91
92 # Get parameters
93 filter_arg = kwargs.get("filter")
94 if not filter_arg and "args" in kwargs:
95 args_val = kwargs["args"]
96 if isinstance(args_val, list) and args_val:
97 filter_arg = args_val[0]
98 elif isinstance(args_val, str):
99 filter_arg = args_val
100
101 show_raw = kwargs.get("raw", False)
102 show_full_desc = kwargs.get("details", False)
103
104 try:
105 # Get all tools
106 all_tools = await tm.get_unique_tools()
107
108 if not all_tools:
109 return CommandResult(
110 success=True,
111 output="No tools available.",
112 )
113
114 # If filter provided, check if it's a server or tool name
115 if filter_arg:
116 # First check if it's a tool name (exact match)
117 tool_match = None
118 for tool in all_tools:
119 if (
120 tool.name == filter_arg
121 or tool.fully_qualified_name == filter_arg
122 ):
123 tool_match = tool
124 break
125
126 if tool_match:
127 # Show detailed tool information
128 return self._show_tool_details(tool_match)
129
130 # Helper to get actual server name (reuse the function)
131 def get_server_name(tool):
132 tool_server_map = {
133 "read_query": "sqlite",
134 "write_query": "sqlite",
135 "create_table": "sqlite",
136 "list_tables": "sqlite",
137 "describe_table": "sqlite",

Callers

nothing calls this directly

Calls 6

_show_tool_detailsMethod · 0.95
_show_tools_tableMethod · 0.95
get_contextFunction · 0.90
CommandResultClass · 0.90
getMethod · 0.45
get_unique_toolsMethod · 0.45

Tested by

no test coverage detected