11"""Main CLI entry point for MCP Agent."""
22
3+ import importlib
4+
5+ import click
36import typer
4- from rich .table import Table
7+ import typer .main
8+ from typer .core import TyperGroup
59
6- from fast_agent .cli .commands import acp , auth , check_config , go , quickstart , serve , setup
710from fast_agent .cli .terminal import Application
811from fast_agent .ui .console import console as shared_console
912
13+ LAZY_SUBCOMMANDS : dict [str , str ] = {
14+ "go" : "fast_agent.cli.commands.go:app" ,
15+ "serve" : "fast_agent.cli.commands.serve:app" ,
16+ "acp" : "fast_agent.cli.commands.acp:app" ,
17+ "setup" : "fast_agent.cli.commands.setup:app" ,
18+ "check" : "fast_agent.cli.commands.check_config:app" ,
19+ "auth" : "fast_agent.cli.commands.auth:app" ,
20+ "quickstart" : "fast_agent.cli.commands.quickstart:app" ,
21+ "bootstrap" : "fast_agent.cli.commands.quickstart:app" ,
22+ }
23+
24+
25+ class LazyGroup (TyperGroup ):
26+ lazy_subcommands : dict [str , str ] = {}
27+
28+ def list_commands (self , ctx : click .Context ) -> list [str ]:
29+ return sorted (self .lazy_subcommands )
30+
31+ def get_command (self , ctx : click .Context , cmd_name : str ) -> click .Command | None :
32+ target = self .lazy_subcommands .get (cmd_name )
33+ if not target :
34+ return None
35+ module_path , app_name = target .split (":" , 1 )
36+ module = importlib .import_module (module_path )
37+ typer_app = getattr (module , app_name )
38+ command = typer .main .get_command (typer_app )
39+ command .name = cmd_name
40+ return command
41+
42+
1043app = typer .Typer (
44+ cls = LazyGroup ,
1145 help = "Use `fast-agent go --help` for interactive shell arguments and options." ,
1246 add_completion = False , # We'll add this later when we have more commands
1347)
14-
15- # Subcommands
16- app .add_typer (go .app , name = "go" , help = "Run an interactive agent directly from the command line" )
17- app .add_typer (serve .app , name = "serve" , help = "Run FastAgent as an MCP server" )
18- app .add_typer (acp .app , name = "acp" , help = "Run FastAgent as an ACP stdio server" )
19- app .add_typer (setup .app , name = "setup" , help = "Set up a new agent project" )
20- app .add_typer (check_config .app , name = "check" , help = "Show or diagnose fast-agent configuration" )
21- app .add_typer (auth .app , name = "auth" , help = "Manage OAuth authentication for MCP servers" )
22- app .add_typer (quickstart .app , name = "bootstrap" , help = "Create example applications" )
23- app .add_typer (quickstart .app , name = "quickstart" , help = "Create example applications" )
48+ LazyGroup .lazy_subcommands = LAZY_SUBCOMMANDS
2449
2550# Shared application context
2651application = Application ()
@@ -32,6 +57,7 @@ def show_welcome() -> None:
3257 """Show a welcome message with available commands, using new styling."""
3358 from importlib .metadata import version
3459
60+ from rich .table import Table
3561 from rich .text import Text
3662
3763 try :
0 commit comments