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

Class InteractiveCommandAdapter

src/mcp_cli/adapters/interactive.py:26–293  ·  view source on GitHub ↗

Adapts unified commands for use in interactive shell mode. Handles: - Command parsing without slash prefix - Shell-style argument parsing - Tab completion

Source from the content-addressed store, hash-verified

24
25
26class InteractiveCommandAdapter:
27 """
28 Adapts unified commands for use in interactive shell mode.
29
30 Handles:
31 - Command parsing without slash prefix
32 - Shell-style argument parsing
33 - Tab completion
34 """
35
36 @staticmethod
37 async def handle_command(command_line: str) -> bool:
38 """
39 Handle an interactive command.
40
41 Args:
42 command_line: The full command line (e.g., "servers --detailed").
43
44 Returns:
45 True if command was handled, False otherwise.
46 """
47 if not command_line.strip():
48 return False
49
50 # Parse command line using shell-style parsing
51 try:
52 parts = shlex.split(command_line)
53 except ValueError as e:
54 output.error(f"Invalid command syntax: {e}")
55 return False
56
57 if not parts:
58 return False
59
60 command_name = parts[0]
61
62 # Handle slash commands - strip the leading slash if present
63 if command_name.startswith("/"):
64 command_name = command_name[1:]
65
66 args = parts[1:] if len(parts) > 1 else []
67
68 logger.debug(f"Parsed command: {command_name}, args: {args}")
69
70 # Look up command in registry
71 command = registry.get(command_name, mode=CommandMode.INTERACTIVE)
72 if not command:
73 # Not a registered command, might be a shell command
74 return False
75
76 # Parse arguments into kwargs
77 kwargs = InteractiveCommandAdapter._parse_arguments(command, args)
78
79 # Add context if the command needs it
80 if command.requires_context:
81 context = get_context()
82 if context:
83 kwargs["tool_manager"] = context.tool_manager

Callers 1

setup_methodMethod · 0.90

Calls

no outgoing calls

Tested by 1

setup_methodMethod · 0.72