CLI command for starting MCP servers.
This module defines the StartServersCmd class, which implements a
command-line interface (CLI) command for starting one or more MCP
servers. It integrates with the main argument parser, allowing users
to specify a configuration file, an optional list of server names, and
an optional state file for tracking server status. The command invokes
server management logic to start the specified servers.
StartServersCmd
Bases: BaseCmd
Command to start one or more MCP servers via the CLI.
This class adds the "start-servers" command to the main argument
parser, allowing users to specify which servers to start and which
configuration and state files to use. When executed, it invokes the
server management logic to start the selected servers.
Methods:
| Name |
Description |
add_parser |
Adds the "start-servers" subcommand and its arguments to the CLI parser.
|
process_command |
Executes the start logic using the parsed CLI arguments.
|
Source code in src/mada_tools/cli/commands/start_servers.py
| class StartServersCmd(BaseCmd):
"""
Command to start one or more MCP servers via the CLI.
This class adds the "start-servers" command to the main argument
parser, allowing users to specify which servers to start and which
configuration and state files to use. When executed, it invokes the
server management logic to start the selected servers.
Methods:
add_parser:
Adds the "start-servers" subcommand and its arguments to the CLI parser.
process_command:
Executes the start logic using the parsed CLI arguments.
"""
def add_parser(self, subparsers: ArgumentParser):
"""
Add the parser for this command to the main `ArgumentParser`.
Args:
subparsers (ArgumentParser): A subparser object to add this command to.
"""
start_servers: ArgumentParser = subparsers.add_parser(
"start-servers",
help="Start MCP servers.",
formatter_class=ArgumentDefaultsHelpFormatter,
)
start_servers.set_defaults(func=self.process_command)
start_servers.add_argument(
"config",
action="store",
type=Path,
help="Path to a server configuration file.",
)
start_servers.add_argument(
"-s",
"--servers",
action="store",
nargs="+",
type=str,
help="An optional, space-delimited list of servers to start. "
"If none are provided all servers will be started.",
)
start_servers.add_argument(
"-f",
"--state-file",
action="store",
type=Path,
default=Path.home() / ".mada" / "server_statuses.json",
help="Path to a file tracking server state.",
)
def process_command(self, args: Namespace):
"""
Execute the logic for this CLI command.
Args:
args (Namespace): Parsed CLI arguments from the user.
"""
# Create ServerManager
manager = ServerManager(state_file=args.state_file)
manager.start_servers(config_file=args.config, server_names=args.servers)
|
add_parser(subparsers)
Add the parser for this command to the main ArgumentParser.
Parameters:
| Name |
Type |
Description |
Default |
subparsers
|
ArgumentParser
|
A subparser object to add this command to.
|
required
|
Source code in src/mada_tools/cli/commands/start_servers.py
| def add_parser(self, subparsers: ArgumentParser):
"""
Add the parser for this command to the main `ArgumentParser`.
Args:
subparsers (ArgumentParser): A subparser object to add this command to.
"""
start_servers: ArgumentParser = subparsers.add_parser(
"start-servers",
help="Start MCP servers.",
formatter_class=ArgumentDefaultsHelpFormatter,
)
start_servers.set_defaults(func=self.process_command)
start_servers.add_argument(
"config",
action="store",
type=Path,
help="Path to a server configuration file.",
)
start_servers.add_argument(
"-s",
"--servers",
action="store",
nargs="+",
type=str,
help="An optional, space-delimited list of servers to start. "
"If none are provided all servers will be started.",
)
start_servers.add_argument(
"-f",
"--state-file",
action="store",
type=Path,
default=Path.home() / ".mada" / "server_statuses.json",
help="Path to a file tracking server state.",
)
|
process_command(args)
Execute the logic for this CLI command.
Parameters:
| Name |
Type |
Description |
Default |
args
|
Namespace
|
Parsed CLI arguments from the user.
|
required
|
Source code in src/mada_tools/cli/commands/start_servers.py
| def process_command(self, args: Namespace):
"""
Execute the logic for this CLI command.
Args:
args (Namespace): Parsed CLI arguments from the user.
"""
# Create ServerManager
manager = ServerManager(state_file=args.state_file)
manager.start_servers(config_file=args.config, server_names=args.servers)
|