| 1 | package Claude::Agent::MCP::ToolDefinition; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use 5.020; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use Object::Proto (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 8 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use Future; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 8 | ▶ | use Claude::Agent::Logger '$log'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 8 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 8 | Object::Proto::define('Claude::Agent::MCP::ToolDefinition', | |||||||||||||||||||||||||||
| 14 | 'name:Str:required', | ||||||||||||||||||||||||||||
| 15 | 'description:Str:required', | ||||||||||||||||||||||||||||
| 16 | 'input_schema:HashRef:required', | ||||||||||||||||||||||||||||
| 17 | 'handler:CodeRef:required', | ||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 9 | ▶ | sub to_hash { | ||||||||||||||||||||||||||
|
Subroutine
to_hash: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | 9 | my ($self) = @_; | |||||||||||||||||||||||||||
| 23 | return { | ||||||||||||||||||||||||||||
| 24 | 9 | name => $self->name, | |||||||||||||||||||||||||||
| 25 | description => $self->description, | ||||||||||||||||||||||||||||
| 26 | inputSchema => $self->input_schema, | ||||||||||||||||||||||||||||
| 27 | }; | ||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 19 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 19 | my ($self, $args, $loop) = @_; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 19 | my $result; | |||||||||||||||||||||||||||
| 34 | 19 | my $ok = eval { $result = $self->handler->($args, $loop); 1 }; | |||||||||||||||||||||||||||
| 35 | 19 | ▶ | if (!$ok) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 3 | ▶ | $log->debug(sprintf("Tool execution error: %s", $@ // 'unknown')); | ||||||||||||||||||||||||||
|
Condition50%1/2
$@ // "unknown"
MC/DC0%0/1
$@ // "unknown"
$@
Truth table50%1/2
A
A= $@
| |||||||||||||||||||||||||||||
| 37 | 3 | return Future->done($self->_error_result); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 16 | ▶ | if (blessed($result) && $result->isa('Future')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($result) and $result->isa("Future")
MC/DC50%1/2
builtin::blessed($result) and $result->isa("Future")
builtin::blessed($result)
$result->isa("Future")
Truth table66%2/3
A and B
A= builtin::blessed($result)B= $result->isa("Future")
| |||||||||||||||||||||||||||||
| 41 | 1 | ▶ | return $result->else(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 42 | 1 | my ($error) = @_; | |||||||||||||||||||||||||||
| 43 | 1 | ▶ | $log->debug(sprintf("Async tool execution error: %s", $error // 'unknown')); | ||||||||||||||||||||||||||
|
Condition50%1/2
$error // "unknown"
MC/DC0%0/1
$error // "unknown"
$error
Truth table50%1/2
A
A= $error
| |||||||||||||||||||||||||||||
| 44 | 1 | return Future->done($self->_error_result); | |||||||||||||||||||||||||||
| 45 | 4 | }); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 12 | return Future->done($result); | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 4 | ▶ | sub _error_result { | ||||||||||||||||||||||||||
|
Subroutine
_error_result: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 52 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||
| 53 | return { | ||||||||||||||||||||||||||||
| 54 | 4 | content => [{ type => 'text', text => "Error executing tool: " . $self->name }], | |||||||||||||||||||||||||||
| 55 | is_error => 1, | ||||||||||||||||||||||||||||
| 56 | }; | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 8 | 1; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | __END__ | ||||||||||||||||||||||||||||