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

filter: Statementstmt 92.1% 47 / 51 Branchbran 62.5% 5 / 8 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 81.8% 9 / 11 Podpod 100% 4 / 4 totaltotal 83.7% 67 / 80 CC 8 SCAR 14.9
CC
8
Cov
86%
execute
8.5
description
2.0
abstract
2.0
CRAP 4.4
« blib/lib/App/MCP/CLI/Command/servers.pm ↑ Summary blib/lib/App/MCP/CLI/Command/version.pm »
1 package App::MCP::CLI::Command::list;
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::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 29 ▶use App::MCP::CLI::Config qw(load_config resolve_server_cmd);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 =encoding utf8
17  
18 =head1 NAME
19  
20 App::MCP::CLI::Command::list - List all tools available on an MCP server
21  
22 =head1 VERSION
23  
24 This module is distributed as part of L<App::MCP::CLI> v0.0.1.
25  
26 =head1 SYNOPSIS
27  
28 # Print a table of every tool the server exposes
29 mcpcli list --server perl-math-server
30  
31 # The only configured server is used when --server is omitted
32 mcpcli list
33  
34 # Use a script, a raw command, or an SSE URL instead of a config name
35 mcpcli list --server ./stdio_server.pl
36 mcpcli list --server "node server.js"
37 mcpcli list --server http://localhost:8080/sse
38  
39 =head1 DESCRIPTION
40  
41 C<App::MCP::CLI::Command::list> implements the C<list> sub-command of the
42 C<mcpcli> application. It connects to the MCP server over stdio or HTTP/SSE
43 (through L<App::MCP::CLI::Client>), completes the C<initialize> handshake,
44 sends C<tools/list> (following pagination), and renders the resulting tool
45 catalogue as a plain ASCII table using L<Text::Table::Tiny>.
46  
47 The table has two columns:
48  
49 =over 4
50  
51 =item * B<Tool Name> - the C<name> field from the tool descriptor.
52  
53 =item * B<Description> - the C<description> field, or C<N/A> when absent.
54  
55 =back
56  
57 If the server returns an empty tool list the message C<No tools found on the
58 server.> is printed instead.
59  
60 =head1 USAGE
61  
62 mcpcli list [--server <name|path|url|command>] [--config <file>] [--timeout <seconds>]
63  
64 =head1 OPTIONS
65  
66 =over 4
67  
68 =item C<--server|-s> I<name>
69  
70 Server name from the config file, a C<.pl> script, a URL, or a command. May be
71 omitted when the config file defines exactly one server.
72  
73 =item C<--config|-c> I<path>
74  
75 Path to the JSON configuration file. See L<App::MCP::CLI::Config>.
76  
77 =item C<--timeout|-t> I<seconds>
78  
79 How long to wait for the server (default 30; C<0> waits forever).
80  
81 =back
82  
83 =head1 EXIT STATUS
84  
85 C<0> on success, C<1> if the server could not be started or reached, did not
86 answer in time, or the configuration is invalid. Errors are printed to STDERR.
87  
88 =head1 INTERNAL METHODS
89  
90 =head2 opt_spec
91  
92 Defines the command-line option specification passed to L<Getopt::Long::Descriptive>
93 via L<App::Cmd>.
94  
95 =cut
96  
97 3 ▶sub opt_spec {
Subroutine opt_spec: called CC=1 SCAR=0.0
Pod documented
98 return (
99 3 [ 'server|s=s', 'server name, script path, URL or command' ],
100 [ 'config|c=s', 'path to config JSON file' ],
101 [ 'timeout|t=i', 'seconds to wait for the server (0 = forever)',
102 { default => 30 } ],
103 );
104 }
105  
106 =head2 description
107  
108 Returns a one-line description used in the top-level C<mcpcli help> listing.
109  
110 =cut
111  
112 0 ▶sub description { 'List all available tools provided by the MCP server' }
Subroutine description: not called CC=1 SCAR=6.9
Pod documented
113  
114 =head2 abstract
115  
116 Returns the same one-line description for the L<App::Cmd> abstract slot.
117  
118 =cut
119  
120 0 ▶sub abstract { 'List all available tools provided by the MCP server' }
Subroutine abstract: not called CC=1 SCAR=6.9
Pod documented
121  
122 =head2 execute( $opt, $args )
123  
124 Main entry point. Connects to the MCP server, retrieves the tool list, and
125 prints the ASCII table (or a "none found" notice).
126  
127 =cut
128  
129 3 ▶sub execute {
Subroutine execute: called CC=8 SCAR=21.4
Pod documented
130 3 my ($self, $opt, $args) = @_;
131  
132 3 my $tools = eval {
133 3 my $config_data = load_config($opt->config);
134 3 my ($cmd, $url, $env) = resolve_server_cmd($config_data, $opt->server);
135  
136 2 my $client = App::MCP::CLI::Client->new(
137 cmd => $cmd, url => $url, env => $env, timeout => $opt->timeout,
138 );
139 2 $client->connect;
140  
141 2 my $list = eval { $client->list_tools };
142 2 my $err = $@;
143 2 $client->close;
144 2 ▶ die $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 2 2
145 2 $list;
146 };
147  
148 3 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 1 2 3
149 1 ▶ $err .= "\n" unless $err =~ /\n\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $err =~ /\n\z/ 0 1 1
150 1 print STDERR "Error: $err";
151 1 exit 1;
152 }
153  
154 2 ▶ if (!@$tools) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$tools) 0 2 2
155 0 print "No tools found on the server.\n";
156 0 return;
157 }
158  
159 2 my @rows = (['Tool Name', 'Description']);
160 2 foreach my $tool (@$tools) {
161 10 ▶ push @rows, [ $tool->{name} // '', $tool->{description} // 'N/A' ];
Condition50%2/4
$tool->{"name"} // ""
l!l
100
$tool->{"description"} // "N/A"
l!l
100
MC/DC0%0/1
$tool->{"name"} // ""
$tool->{"name"}
MC/DC0%0/1
$tool->{"description"} // "N/A"
$tool->{"description"}
Truth table50%1/2
A
A= $tool->{"name"}
Aresult
11
00
Truth table50%1/2
A
A= $tool->{"description"}
Aresult
11
00
162 }
163  
164 2 print "\nAvailable MCP Tools:\n";
165 2 print generate_table(
166 rows => \@rows,
167 header_row => 1,
168 style => 'classic'), "\n";
169 }
170  
171 =head1 SEE ALSO
172  
173 =over 4
174  
175 =item * L<App::MCP::CLI>
176  
177 =item * L<App::MCP::CLI::Command::call>
178  
179 =item * L<App::MCP::CLI::Command::interactive>
180  
181 =item * L<Text::Table::Tiny>
182  
183 =back
184  
185 =head1 AUTHOR
186  
187 Mohammad Sajid Anwar, C<< <mohammad.anwar at yahoo.com> >>
188  
189 =head1 REPOSITORY
190  
191 L<https://github.com/manwar/App-MCP-CLI>
192  
193 =head1 BUGS
194  
195 Please report any bugs or feature requests through the web interface at L<https://github.com/manwar/App-MCP-CLI/issues>.
196 I will be notified and then you'll automatically be notified of progress on your
197 bug as I make changes.
198  
199 =head1 SUPPORT
200  
201 You can find documentation for this module with the perldoc command.
202  
203 perldoc App::MCP::CLI
204  
205 You can also look for information at:
206  
207 =over 4
208  
209 =item * BUG Report
210  
211 L<https://github.com/manwar/App-MCP-CLI/issues>
212  
213 =item * Search MetaCPAN
214  
215 L<http://metacpan.org/dist/App-MCP-CLI>
216  
217 =back
218  
219 =head1 LICENSE AND COPYRIGHT
220  
221 Copyright (C) 2026 Mohammad Sajid Anwar.
222  
223 This program is free software; you can redistribute it and / or modify it under
224 the terms of the the Artistic License (2.0). You may obtain a copy of the full
225 license at:
226  
227 L<http://www.perlfoundation.org/artistic_license_2_0>
228  
229 Any use, modification, and distribution of the Standard or Modified Versions is
230 governed by this Artistic License.By using, modifying or distributing the Package,
231 you accept this license. Do not use, modify, or distribute the Package, if you do
232 not accept this license.
233  
234 If your Modified Version has been derived from a Modified Version made by someone
235 other than you,you are nevertheless required to ensure that your Modified Version
236 complies with the requirements of this license.
237  
238 This license does not grant you the right to use any trademark, service mark,
239 tradename, or logo of the Copyright Holder.
240  
241 This license includes the non-exclusive, worldwide, free-of-charge patent license
242 to make, have made, use, offer to sell, sell, import and otherwise transfer the
243 Package with respect to any patent claims licensable by the Copyright Holder that
244 are necessarily infringed by the Package. If you institute patent litigation
245 (including a cross-claim or counterclaim) against any party alleging that the
246 Package constitutes direct or contributory patent infringement,then this Artistic
247 License to you shall terminate on the date that such litigation is filed.
248  
249 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
250 CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
251 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
252 NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
253 REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
254 INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
255 OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
256  
257 =cut
258  
259 29 1; # End of App::MCP::CLI::Command::list
« blib/lib/App/MCP/CLI/Command/servers.pm ↑ Summary blib/lib/App/MCP/CLI/Command/version.pm »