App-MCP-CLI

 view release on metacpan or  search on metacpan

lib/App/MCP/CLI/Command/servers.pm  view on Meta::CPAN


App::MCP::CLI::Command::servers - List all servers defined in the config file

=head1 VERSION

This module is distributed as part of L<App::MCP::CLI> v0.0.1.

=head1 SYNOPSIS

    # List all configured servers
    mcpcli servers

    # Use a specific config file
    mcpcli servers --config examples/server_config.json

=head1 DESCRIPTION

C<App::MCP::CLI::Command::servers> implements the C<servers> sub-command of
the C<mcpcli> application. It reads the configuration file and prints a table
of all server names and their transport type (stdio or SSE).

=head1 INTERNAL METHODS

=cut

sub description { 'List all servers defined in the configuration file' }
sub abstract    { 'List all servers defined in the configuration file' }

=head2 opt_spec

=cut

sub opt_spec {
    return (
        [ 'config|c=s', 'path to config JSON file' ],
    );
}

=head2 execute( $opt, $args )

Loads the config file and prints a table of server names and transport types.

=cut

sub execute {
    my ($self, $opt, $args) = @_;

    my $config_data = load_config($opt->config);

    if (!$config_data || !$config_data->{mcpServers} || !%{ $config_data->{mcpServers} }) {
        print "No servers found in configuration.\n";
        return;
    }

    my $servers = $config_data->{mcpServers};
    my @rows    = (['Server Name', 'Transport', 'Command / URL']);

    foreach my $name (sort keys %$servers) {
        my $srv = $servers->{$name};

        my ($transport, $endpoint);
        if ($srv->{url} || (($srv->{transport} // '') eq 'sse')) {
            $transport = 'SSE';
            $endpoint  = $srv->{url} // '(transport: sse)';
        } else {
            $transport = 'stdio';
            my @parts  = ($srv->{command} // '');
            push @parts, @{ $srv->{args} // [] };
            $endpoint  = join(' ', @parts);
        }

        push @rows, [$name, $transport, $endpoint];
    }

    print "\nConfigured MCP Servers:\n";
    print generate_table(
        rows       => \@rows,
        header_row => 1,
        style      => 'classic'), "\n";
}

=head1 SEE ALSO

=over 4

=item * L<App::MCP::CLI>

=item * L<App::MCP::CLI::Command::list>

=item * L<App::MCP::CLI::Command::interactive>

=back

=head1 AUTHOR

Mohammad Sajid Anwar, C<< <mohammad.anwar at yahoo.com> >>

=head1 REPOSITORY

L<https://github.com/manwar/App-MCP-CLI>

=head1 BUGS

Please report any bugs or feature requests through the web interface at L<https://github.com/manwar/App-MCP-CLI/issues>.
I will be notified and then you'll automatically be notified of progress on your
bug as I make changes.

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc App::MCP::CLI

You can also look for information at:

=over 4

=item * BUG Report

L<https://github.com/manwar/App-MCP-CLI/issues>

=item * Search MetaCPAN

L<http://metacpan.org/dist/App-MCP-CLI>

=back

=head1 LICENSE AND COPYRIGHT

Copyright (C) 2026 Mohammad Sajid Anwar.

This program  is  free software; you can redistribute it and / or modify it under



( run in 1.274 second using v1.01-cache-2.11-cpan-eb134014566 )