| 1 | package Claude::Agent::MCP::StdioServer; | ||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||
| 9 | 8 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 8 | Object::Proto::define('Claude::Agent::MCP::StdioServer', | |||||||||||||||||||||||||||
| 11 | 'command:Str:required', | ||||||||||||||||||||||||||||
| 12 | 'args:ArrayRef:default([])', | ||||||||||||||||||||||||||||
| 13 | 'env:HashRef:default({})', | ||||||||||||||||||||||||||||
| 14 | 'type:Str:readonly:default(stdio)', | ||||||||||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 8 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=13 SCAR=27.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | 8 | my ($self) = @_; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 8 | ▶ | die "Command must be absolute path" unless $self->command =~ m{^/}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 7 | require Cwd; | |||||||||||||||||||||||||||
| 23 | 7 | my $canon = Cwd::abs_path($self->command); | |||||||||||||||||||||||||||
| 24 | 7 | ▶ | die "Invalid command path" unless $canon && $canon =~ m{^/}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$canon and $canon =~ m[^/]u
MC/DC0%0/2
$canon and $canon =~ m[^/]u
$canon
$canon =~ m[^/]u
Truth table33%1/3
A and B
A= $canonB= $canon =~ m[^/]u
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 7 | for my $arg (@{$self->args}) { | |||||||||||||||||||||||||||
| 27 | 5 | ▶ | next unless defined $arg; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 5 | ▶ | die "Invalid arg: contains null byte" if $arg =~ /\0/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 5 | ▶ | die "Invalid arg: contains shell metacharacters" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | if $arg =~ /[`\$\(\)\{\};\|<>\\\n\r]/; | ||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 6 | for my $key (keys %{$self->env}) { | |||||||||||||||||||||||||||
| 34 | 1 | ▶ | die "Invalid env var name '$key': must match [A-Za-z_][A-Za-z0-9_]*" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | unless $key =~ /^[A-Za-z_][A-Za-z0-9_]*$/; | ||||||||||||||||||||||||||||
| 36 | 1 | my $value = $self->env->{$key}; | |||||||||||||||||||||||||||
| 37 | 1 | ▶ | next unless defined $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 1 | ▶ | die "Invalid env var value for '$key': contains null byte" if $value =~ /\0/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 1 | ▶ | die "Invalid env var value for '$key': contains control characters" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | if $value =~ /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/; | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | 6 | return; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 2 | ▶ | sub to_hash { | ||||||||||||||||||||||||||
|
Subroutine
to_hash: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 47 | return { | ||||||||||||||||||||||||||||
| 48 | 2 | type => 'stdio', | |||||||||||||||||||||||||||
| 49 | command => $self->command, | ||||||||||||||||||||||||||||
| 50 | args => $self->args, | ||||||||||||||||||||||||||||
| 51 | env => $self->env, | ||||||||||||||||||||||||||||
| 52 | }; | ||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 8 | 1; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | __END__ | ||||||||||||||||||||||||||||