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

Method execute

src/mcp_cli/commands/core/clear.py:56–116  ·  view source on GitHub ↗

Execute the clear command.

(self, **kwargs)

Source from the content-addressed store, hash-verified

54 return False
55
56 async def execute(self, **kwargs) -> CommandResult:
57 """Execute the clear command."""
58 # Import needed modules
59 from chuk_term.ui import clear_screen, display_chat_banner
60 from mcp_cli.context import get_context
61 from mcp_cli.model_management import ModelManager
62
63 # Clear the screen first
64 clear_screen()
65
66 # Try to get context for banner information
67 provider = None
68 model = None
69 additional_info = {}
70
71 try:
72 context = get_context()
73 if context:
74 # Get provider and model from context's model_manager
75 if hasattr(context, "model_manager") and context.model_manager:
76 provider = context.model_manager.get_active_provider()
77 model = context.model_manager.get_active_model()
78
79 # Get tool count if available
80 if hasattr(context, "tool_manager") and context.tool_manager:
81 tool_manager = context.tool_manager
82 if hasattr(tool_manager, "get_tool_count"):
83 tool_count = tool_manager.get_tool_count()
84 elif hasattr(tool_manager, "list_tools"):
85 tools = tool_manager.list_tools()
86 tool_count = len(tools) if tools else 0
87 elif hasattr(tool_manager, "_tools"):
88 tool_count = len(tool_manager._tools)
89 else:
90 tool_count = None
91
92 if tool_count is not None and tool_count > 0:
93 additional_info["Tools"] = str(tool_count)
94 except Exception as e:
95 # Context not available, use ModelManager directly
96 logger.debug("Context not available for banner: %s", e)
97 try:
98 model_manager = ModelManager()
99 provider = model_manager.get_active_provider()
100 model = model_manager.get_active_model()
101 except Exception as e2:
102 # Even ModelManager failed, use defaults
103 logger.debug("ModelManager fallback also failed: %s", e2)
104
105 # Display the welcome banner if we have provider and model
106 if provider and model:
107 display_chat_banner(
108 provider=provider,
109 model=model,
110 additional_info=additional_info if additional_info else None,
111 )
112
113 return CommandResult(

Callers

nothing calls this directly

Calls 9

get_active_providerMethod · 0.95
get_active_modelMethod · 0.95
get_contextFunction · 0.90
ModelManagerClass · 0.90
CommandResultClass · 0.90
get_tool_countMethod · 0.80
list_toolsMethod · 0.80
get_active_providerMethod · 0.45
get_active_modelMethod · 0.45

Tested by

no test coverage detected