blib/lib/App/MCP/CLI/Command/servers.pm

filter: Statementstmt 86.9% 40 / 46 Branchbran 50.0% 2 / 4 Conditioncond 35.2% 6 / 17 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 80.0% 8 / 10 Podpod 100% 4 / 4 totaltotal 67.4% 60 / 89 CC 11 SCAR 23.7
CC
11
Cov
72%
execute
18.5
description
2.0
abstract
2.0
CRAP 10.7
« blib/lib/App/MCP/CLI/Client.pm ↑ Summary blib/lib/App/MCP/CLI/Command/list.pm »
1 package App::MCP::CLI::Command::servers;
2  
3 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 29 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 29 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 29 our $VERSION = qv('v0.0.1');
8 29 our $AUTHORITY = 'cpan:MANWAR';
9  
10 29 ▶use App::MCP::CLI -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 29 ▶use Text::Table::Tiny qw(generate_table);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 29 ▶use App::MCP::CLI::Config qw(load_config);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 =encoding utf8
16  
17 =head1 NAME
18  
19 App::MCP::CLI::Command::servers - List all servers defined in the config file
20  
21 =head1 VERSION
22  
23 This module is distributed as part of L<App::MCP::CLI> v0.0.1.
24  
25 =head1 SYNOPSIS
26  
27 # List all configured servers
28 mcpcli servers
29  
30 # Use a specific config file
31 mcpcli servers --config examples/server_config.json
32  
33 =head1 DESCRIPTION
34  
35 C<App::MCP::CLI::Command::servers> implements the C<servers> sub-command of
36 the C<mcpcli> application. It reads the configuration file and prints a table
37 of all server names and their transport type (stdio or SSE).
38  
39 =head1 INTERNAL METHODS
40  
41 =cut
42  
43 0 ▶sub description { 'List all servers defined in the configuration file' }
Subroutine description: not called CC=1 SCAR=6.9
Pod documented
44 0 ▶sub abstract { 'List all servers defined in the configuration file' }
Subroutine abstract: not called CC=1 SCAR=6.9
Pod documented
45  
46 =head2 opt_spec
47  
48 =cut
49  
50 1 ▶sub opt_spec {
Subroutine opt_spec: called CC=1 SCAR=0.0
Pod documented
51 return (
52 1 [ 'config|c=s', 'path to config JSON file' ],
53 );
54 }
55  
56 =head2 execute( $opt, $args )
57  
58 Loads the config file and prints a table of server names and transport types.
59  
60 =cut
61  
62 1 ▶sub execute {
Subroutine execute: called CC=11 SCAR=29.2
Pod documented
63 1 my ($self, $opt, $args) = @_;
64  
65 1 my $config_data = load_config($opt->config);
66  
67 1 ▶ if (!$config_data || !$config_data->{mcpServers} || !%{ $config_data->{mcpServers} }) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($config_data and $config_data->{"mcpServers"} and %{$config_data->{"mcpServers"};}) 0 1 1
Condition33%2/6
$config_data and $config_data->{"mcpServers"} and %{$config_data->{"mcpServers"};}
!ll&&!rl&&r
001
$config_data and $config_data->{"mcpServers"}
!ll&&!rl&&r
001
MC/DC0%0/3
$config_data and $config_data->{"mcpServers"} and %{$config_data->{"mcpServers"};}
$config_data $config_data->{"mcpServers"} %{$config_data->{"mcpServers"};}
Truth table25%1/4
A and B and C
A= $config_dataB= $config_data->{"mcpServers"}C= %{$config_data->{"mcpServers"};}
ABCresult
0XX0
10X0
1100
1111
68 0 print "No servers found in configuration.\n";
69 0 return;
70 }
71  
72 1 my $servers = $config_data->{mcpServers};
73 1 my @rows = (['Server Name', 'Transport', 'Command / URL']);
74  
75 1 foreach my $name (sort keys %$servers) {
76 1 my $srv = $servers->{$name};
77  
78 1 my ($transport, $endpoint);
79 1 ▶ if ($srv->{url} || (($srv->{transport} // '') eq 'sse')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($srv->{'url'} or ($srv->{'transport'} // '') eq 'sse') { } 0 1 1
Condition40%2/5
$srv->{"url"} or ($srv->{"transport"} // "") eq "sse"
l!l&&r!l&&!r
001
$srv->{"transport"} // ""
l!l
01
MC/DC0%0/2
$srv->{"url"} or ($srv->{"transport"} // "") eq "sse"
$srv->{"url"} $srv->{"transport"}
Truth table33%1/3
A or B
A= $srv->{"url"}B= $srv->{"transport"}
ABresult
1X1
011
000
80 0 $transport = 'SSE';
81 0 ▶ $endpoint = $srv->{url} // '(transport: sse)';
Condition0%0/2
$srv->{"url"} // "(transport: sse)"
l!l
00
MC/DC0%0/1
$srv->{"url"} // "(transport: sse)"
$srv->{"url"}
Truth table0%0/2
A
A= $srv->{"url"}
Aresult
11
00
82 } else {
83 1 $transport = 'stdio';
84 1 ▶ my @parts = ($srv->{command} // '');
Condition50%1/2
$srv->{"command"} // ""
l!l
10
MC/DC0%0/1
$srv->{"command"} // ""
$srv->{"command"}
Truth table50%1/2
A
A= $srv->{"command"}
Aresult
11
00
85 1 ▶ push @parts, @{ $srv->{args} // [] };
Condition50%1/2
$srv->{"args"} // []
l!l
10
MC/DC0%0/1
$srv->{"args"} // []
$srv->{"args"}
Truth table50%1/2
A
A= $srv->{"args"}
Aresult
11
00
86 1 $endpoint = join(' ', @parts);
87 }
88  
89 1 push @rows, [$name, $transport, $endpoint];
90 }
91  
92 1 print "\nConfigured MCP Servers:\n";
93 1 print generate_table(
94 rows => \@rows,
95 header_row => 1,
96 style => 'classic'), "\n";
97 }
98  
99 =head1 SEE ALSO
100  
101 =over 4
102  
103 =item * L<App::MCP::CLI>
104  
105 =item * L<App::MCP::CLI::Command::list>
106  
107 =item * L<App::MCP::CLI::Command::interactive>
108  
109 =back
110  
111 =head1 AUTHOR
112  
113 Mohammad Sajid Anwar, C<< <mohammad.anwar at yahoo.com> >>
114  
115 =head1 REPOSITORY
116  
117 L<https://github.com/manwar/App-MCP-CLI>
118  
119 =head1 BUGS
120  
121 Please report any bugs or feature requests through the web interface at L<https://github.com/manwar/App-MCP-CLI/issues>.
122 I will be notified and then you'll automatically be notified of progress on your
123 bug as I make changes.
124  
125 =head1 SUPPORT
126  
127 You can find documentation for this module with the perldoc command.
128  
129 perldoc App::MCP::CLI
130  
131 You can also look for information at:
132  
133 =over 4
134  
135 =item * BUG Report
136  
137 L<https://github.com/manwar/App-MCP-CLI/issues>
138  
139 =item * Search MetaCPAN
140  
141 L<http://metacpan.org/dist/App-MCP-CLI>
142  
143 =back
144  
145 =head1 LICENSE AND COPYRIGHT
146  
147 Copyright (C) 2026 Mohammad Sajid Anwar.
148  
149 This program is free software; you can redistribute it and / or modify it under
150 the terms of the the Artistic License (2.0). You may obtain a copy of the full
151 license at:
152  
153 L<http://www.perlfoundation.org/artistic_license_2_0>
154  
155 Any use, modification, and distribution of the Standard or Modified Versions is
156 governed by this Artistic License.By using, modifying or distributing the Package,
157 you accept this license. Do not use, modify, or distribute the Package, if you do
158 not accept this license.
159  
160 If your Modified Version has been derived from a Modified Version made by someone
161 other than you,you are nevertheless required to ensure that your Modified Version
162 complies with the requirements of this license.
163  
164 This license does not grant you the right to use any trademark, service mark,
165 tradename, or logo of the Copyright Holder.
166  
167 This license includes the non-exclusive, worldwide, free-of-charge patent license
168 to make, have made, use, offer to sell, sell, import and otherwise transfer the
169 Package with respect to any patent claims licensable by the Copyright Holder that
170 are necessarily infringed by the Package. If you institute patent litigation
171 (including a cross-claim or counterclaim) against any party alleging that the
172 Package constitutes direct or contributory patent infringement,then this Artistic
173 License to you shall terminate on the date that such litigation is filed.
174  
175 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
176 CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
177 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
178 NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
179 REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
180 INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
181 OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
182  
183 =cut
184  
185 29 1; # End of App::MCP::CLI::Command::servers
« blib/lib/App/MCP/CLI/Client.pm ↑ Summary blib/lib/App/MCP/CLI/Command/list.pm »