|
4 | 4 | from typing import Optional |
5 | 5 |
|
6 | 6 | import typer |
7 | | -from typer import Context |
8 | 7 |
|
9 | 8 | from code_assistant_manager.config import ConfigManager |
10 | 9 | from code_assistant_manager.tools import ( |
11 | 10 | display_all_tool_endpoints, |
12 | 11 | display_tool_endpoints, |
13 | 12 | ) |
14 | 13 |
|
15 | | -from .server_commands import app as server_app |
| 14 | +# Import individual commands from server_commands |
| 15 | +from .server_commands import ( |
| 16 | + add, |
| 17 | + list as list_servers, |
| 18 | + remove, |
| 19 | + search, |
| 20 | + show, |
| 21 | + update, |
| 22 | +) |
16 | 23 |
|
17 | 24 | logger = logging.getLogger(__name__) |
18 | 25 |
|
|
21 | 28 | ) |
22 | 29 |
|
23 | 30 |
|
24 | | -@app.callback() |
25 | | -def mcp_callback( |
26 | | - ctx: Context, |
27 | | - endpoints: Optional[str] = typer.Option( |
| 31 | +@app.command() |
| 32 | +def endpoints( |
| 33 | + tool: Optional[str] = typer.Argument( |
28 | 34 | None, |
29 | | - "--endpoints", |
30 | | - help="Display endpoint information for all tools or a specific tool", |
| 35 | + help="Display endpoint information for a specific tool, or use 'all' for all tools", |
31 | 36 | ), |
32 | 37 | ): |
33 | | - """MCP callback to handle endpoints option.""" |
34 | | - logger.debug(f"MCP callback invoked with endpoints: {endpoints}") |
35 | | - # Store endpoints in app context |
36 | | - ctx.ensure_object(dict) |
37 | | - ctx.obj["endpoints"] = endpoints |
38 | | - |
39 | | - # If endpoints is specified, display and exit |
40 | | - if endpoints: |
41 | | - logger.debug(f"Handling endpoints option: {endpoints}") |
42 | | - # We need config for this, but since this is a subcommand, we might not have config_path |
43 | | - # For now, assume default config |
44 | | - try: |
45 | | - config = ConfigManager() |
46 | | - if endpoints == "all": |
47 | | - logger.debug("Displaying all tool endpoints") |
48 | | - display_all_tool_endpoints(config) |
49 | | - else: |
50 | | - logger.debug(f"Displaying endpoints for tool: {endpoints}") |
51 | | - display_tool_endpoints(config, endpoints) |
52 | | - raise typer.Exit() |
53 | | - except Exception as e: |
54 | | - logger.error(f"Error displaying endpoints: {e}") |
55 | | - typer.echo(f"Error displaying endpoints: {e}") |
56 | | - raise typer.Exit(1) |
57 | | - |
58 | | - |
59 | | -# Add server commands as subcommand |
60 | | -app.add_typer(server_app, name="server") |
| 38 | + """Display endpoint information for MCP-enabled tools.""" |
| 39 | + logger.debug(f"Endpoints command invoked with tool: {tool}") |
| 40 | + try: |
| 41 | + config = ConfigManager() |
| 42 | + if tool is None or tool == "all": |
| 43 | + logger.debug("Displaying all tool endpoints") |
| 44 | + display_all_tool_endpoints(config) |
| 45 | + else: |
| 46 | + logger.debug(f"Displaying endpoints for tool: {tool}") |
| 47 | + display_tool_endpoints(config, tool) |
| 48 | + except Exception as e: |
| 49 | + logger.error(f"Error displaying endpoints: {e}") |
| 50 | + typer.echo(f"Error displaying endpoints: {e}") |
| 51 | + raise typer.Exit(1) |
| 52 | + |
| 53 | + |
| 54 | +@app.command() |
| 55 | +def status( |
| 56 | + client: Optional[str] = typer.Option( |
| 57 | + None, "--client", "-c", help="Show status for specific client (or 'all')" |
| 58 | + ), |
| 59 | +): |
| 60 | + """Show MCP server installation status across clients.""" |
| 61 | + from rich.console import Console |
| 62 | + from rich.table import Table |
| 63 | + |
| 64 | + from .manager import MCPManager |
| 65 | + |
| 66 | + console = Console() |
| 67 | + manager = MCPManager() |
| 68 | + |
| 69 | + if client: |
| 70 | + # Show detailed status for specific client(s) |
| 71 | + if client.lower() == "all": |
| 72 | + clients = manager.get_available_tools() |
| 73 | + else: |
| 74 | + clients = [c.strip() for c in client.split(",")] |
| 75 | + |
| 76 | + for client_name in clients: |
| 77 | + client_obj = manager.get_client(client_name) |
| 78 | + if not client_obj: |
| 79 | + console.print(f"[red]Error:[/] Client '{client_name}' not supported.") |
| 80 | + continue |
| 81 | + |
| 82 | + console.print(f"\n[bold]{client_name} MCP Status:[/]") |
| 83 | + client_obj.list_servers() |
| 84 | + else: |
| 85 | + # Show summary status for all clients |
| 86 | + table = Table(title="MCP Status Summary") |
| 87 | + table.add_column("Client", style="cyan") |
| 88 | + table.add_column("Status", style="green") |
| 89 | + table.add_column("Servers Count", style="yellow") |
| 90 | + |
| 91 | + for tool_name in manager.get_available_tools(): |
| 92 | + client_obj = manager.get_client(tool_name) |
| 93 | + if client_obj: |
| 94 | + # This is a simplified status - could be enhanced |
| 95 | + table.add_row(tool_name, "Available", "-") |
| 96 | + |
| 97 | + console.print(table) |
| 98 | + |
| 99 | + |
| 100 | +# Add all server management commands directly to mcp app |
| 101 | +app.command(name="list")(list_servers) |
| 102 | +app.command(name="search")(search) |
| 103 | +app.command(name="show")(show) |
| 104 | +app.command(name="add")(add) |
| 105 | +app.command(name="remove")(remove) |
| 106 | +app.command(name="update")(update) |
0 commit comments