blib/lib/Langertha/Raider/Hall/MCP.pm

filter: Statementstmt 61.5% 24 / 39 Branchbran 27.2% 6 / 22 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 66.6% 4 / 6 Podpod 0.0% 0 / 2 totaltotal 47.2% 34 / 72 CC 13 SCAR 37.5
CC
13
Cov
48%
handle_tool_call
58.2
_build_socket_path
2.0
tools
2.0
CRAP 42.4
« blib/lib/Langertha/Raider/CLI/Main.pm ↑ Summary blib/lib/Langertha/Raider/ACP/Client.pm »
1 package Langertha::Raider::Hall::MCP;
2 73 our $VERSION = '0.503';
3 # ABSTRACT: Internal MCP tool adapter exposing the raider hall
4  
5  
6 73 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 73 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 73 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 73 has hall => (
11 is => 'ro',
12 isa => 'Langertha::Raider::Hall',
13 required => 1,
14 weak_ref => 1,
15 );
16  
17 73 has socket_path => (
18 is => 'ro',
19 lazy => 1,
20 builder => '_build_socket_path',
21 );
22  
23 0 ▶sub _build_socket_path {
Subroutine _build_socket_path: not called CC=1 SCAR=6.9
24 0 my ($self) = @_;
25 0 $self->hall->root->child('.raider-hall.mcp')->stringify;
26 }
27  
28 0 ▶sub tools {
Subroutine tools: not called CC=1 SCAR=6.9
Pod undocumented
29 0 my ($self) = @_;
30 return {
31 0 spawn_raider => {
32 description => 'Spawn a raider in the hall',
33 input => {
34 type => 'object',
35 properties => {
36 name => { type => 'string' },
37 mission => { type => 'string' },
38 },
39 required => [qw(name mission)],
40 },
41 },
42 list_raiders => {
43 description => 'List running raiders in the hall',
44 input => { type => 'object', properties => {} },
45 },
46 schedule_raid => {
47 description => 'Schedule a cron raid',
48 input => {
49 type => 'object',
50 properties => {
51 name => { type => 'string' },
52 cron => { type => 'string' },
53 mission => { type => 'string' },
54 coalesce => { type => 'boolean' },
55 },
56 required => [qw(name cron mission)],
57 },
58 },
59 cancel_job => {
60 description => 'Cancel a scheduled job',
61 input => {
62 type => 'object',
63 properties => { id => { type => 'string' } },
64 required => [qw(id)],
65 },
66 },
67 send_telegram => {
68 description => 'Send a Telegram message',
69 input => {
70 type => 'object',
71 properties => {
72 bot => { type => 'string' },
73 chat_id => { type => 'integer' },
74 text => { type => 'string' },
75 },
76 required => [qw(bot chat_id text)],
77 },
78 },
79 hall_status => {
80 description => 'Get hall status',
81 input => { type => 'object', properties => {} },
82 },
83 };
84 }
85  
86 1 ▶sub handle_tool_call {
Subroutine handle_tool_call: called CC=13 SCAR=40.6
Pod undocumented
87 1 my ($self, $tool, $input) = @_;
88 1 my $hall = $self->hall;
89  
90 1 ▶ if ($tool eq 'spawn_raider') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tool eq "spawn_raider") 0 1 1
91 0 return $hall->spawn(name => $input->{name}, mission => $input->{mission});
92 }
93 1 ▶ if ($tool eq 'list_raiders') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tool eq "list_raiders") 0 1 1
94 0 return { raiders => [$hall->ps] };
95 }
96 1 ▶ if ($tool eq 'schedule_raid') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tool eq "schedule_raid") 0 1 1
97 $hall->cron_scheduler->add_job(
98 id => $input->{name},
99 cron => $input->{cron},
100 name => $input->{name},
101 mission => $input->{mission},
102 0 ▶ coalesce => $input->{coalesce} // 0,
Branch: 1 branch
BranchTrueFalseTotal
if $hall->can("cron_scheduler") 0 0 0
Condition0%0/2
$input->{"coalesce"} // 0
l!l
00
MC/DC0%0/1
$input->{"coalesce"} // 0
$input->{"coalesce"}
Truth table0%0/2
A
A= $input->{"coalesce"}
Aresult
11
00
103 ) if $hall->can('cron_scheduler');
104 0 return { scheduled => 1, name => $input->{name} };
105 }
106 1 ▶ if ($tool eq 'cancel_job') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tool eq "cancel_job") 0 1 1
107 0 ▶ $hall->cron_scheduler->cancel_job($input->{id}) if $hall->can('cron_scheduler');
Branch: 1 branch
BranchTrueFalseTotal
if $hall->can("cron_scheduler") 0 0 0
108 0 return { cancelled => 1, id => $input->{id} };
109 }
110 1 ▶ if ($tool eq 'send_telegram') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tool eq "send_telegram") 0 1 1
111 my $result = $hall->telegram->send_message(
112 bot => $input->{bot},
113 chat_id => $input->{chat_id},
114 text => $input->{text},
115 0 ▶ ) if $hall->can('telegram');
Branch: 1 branch
BranchTrueFalseTotal
if $hall->can("telegram") 0 0 0
116 0 ▶ delete $result->{future} if $result;
Branch: 1 branch
BranchTrueFalseTotal
if $result 0 0 0
117 0 ▶ return $result if $result;
Branch: 1 branch
BranchTrueFalseTotal
if $result 0 0 0
118 0 return { error => 'telegram not configured' };
119 }
120 1 ▶ if ($tool eq 'hall_status') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tool eq "hall_status") 1 0 1
121 return {
122 1 running => scalar(keys %{$hall->raiders}),
123 root => $hall->root->stringify,
124 slots => $hall->_running_slots,
125 };
126 }
127 0 return { error => "unknown tool: $tool" };
128 }
129  
130 73 __PACKAGE__->meta->make_immutable;
131  
132 73 1;
133  
134 __END__
135  
136 =pod
137  
138 =encoding UTF-8
139  
140 =head1 NAME
141  
142 Langertha::Raider::Hall::MCP - Internal MCP tool adapter exposing the raider hall
143  
144 =head1 VERSION
145  
146 version 0.503
147  
148 =head1 DESCRIPTION
149  
150 B<Internal module.> Its interface may change without notice.
151  
152 Describes and dispatches the hall management tools (spawn, list, schedule,
153 cancel, Telegram, status) of a L<Langertha::Raider::Hall>.
154  
155 No transport serves these tools yet: the hall opens no C<.raider-hall.mcp>
156 socket, so nothing outside the hall process can call them.
157  
158 =head1 SUPPORT
159  
160 =head2 Issues
161  
162 Please report bugs and feature requests on GitHub at
163 L<https://github.com/Getty/langertha-raider/issues>.
164  
165 =head2 IRC
166  
167 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
168  
169 =head1 CONTRIBUTING
170  
171 Contributions are welcome! Please fork the repository and submit a pull request.
172  
173 =head1 AUTHOR
174  
175 Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/>
176  
177 =head1 COPYRIGHT AND LICENSE
178  
179 This software is copyright (c) 2026 by Torsten Raudssus.
180  
181 This is free software; you can redistribute it and/or modify it under
182 the same terms as the Perl 5 programming language system itself.
183  
184 =cut
« blib/lib/Langertha/Raider/CLI/Main.pm ↑ Summary blib/lib/Langertha/Raider/ACP/Client.pm »