| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # PODNAME: mcp-run-bash | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: MCP server that executes shell commands via bash over stdio | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 19 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 19 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 19 | ▶ | use MCP::Run::Bash; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 19 | my %args; | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 19 | ▶ | if (my $allowed = $ENV{MCP_RUN_ALLOWED_COMMANDS}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | $args{allowed_commands} = [ grep { length } split /\s*,\s*/, $allowed ]; | |||||||||||||||||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 19 | ▶ | if (my $wd = $ENV{MCP_RUN_WORKING_DIRECTORY}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | $args{working_directory} = $wd; | |||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | # Configuration a human wrote into a client config, not an argument the model | ||||||||||||||||||||||||||||||||||||||||||
| 20 | # passes per call - so a bad value is a mistake worth stopping for. `+ 0` took | ||||||||||||||||||||||||||||||||||||||||||
| 21 | # any string ('30s' became 30, 'abc' became 0, '1e400' became Inf), warned on | ||||||||||||||||||||||||||||||||||||||||||
| 22 | # the stderr of a stdio server, and left the user believing the timeout they | ||||||||||||||||||||||||||||||||||||||||||
| 23 | # configured was in force. MCP::Run::Bash normalises unusable per-call | ||||||||||||||||||||||||||||||||||||||||||
| 24 | # timeouts to the server default instead of dying, because those arrive | ||||||||||||||||||||||||||||||||||||||||||
| 25 | # mid-session from the model and must not take the server down with them; | ||||||||||||||||||||||||||||||||||||||||||
| 26 | # here nothing is running yet, and a client that cannot start its server says | ||||||||||||||||||||||||||||||||||||||||||
| 27 | # so, while a silent default is invisible until a command dies early. | ||||||||||||||||||||||||||||||||||||||||||
| 28 | # The ceiling is the module's own constant, so the two layers cannot drift: | ||||||||||||||||||||||||||||||||||||||||||
| 29 | # anything above it is a timeout alarm() cannot arm. | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 19 | ▶ | if (defined $ENV{MCP_RUN_TIMEOUT} && length $ENV{MCP_RUN_TIMEOUT}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $ENV{"MCP_RUN_TIMEOUT"} and length $ENV{"MCP_RUN_TIMEOUT"}
MC/DC50%1/2
defined $ENV{"MCP_RUN_TIMEOUT"} and length $ENV{"MCP_RUN_TIMEOUT"}
defined $ENV{"MCP_RUN_TIMEOUT"}
length $ENV{"MCP_RUN_TIMEOUT"}
Truth table66%2/3
A and B
A= defined $ENV{"MCP_RUN_TIMEOUT"}B= length $ENV{"MCP_RUN_TIMEOUT"}
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 11 | my $timeout = $ENV{MCP_RUN_TIMEOUT}; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 11 | my $max = MCP::Run::Bash->MAX_TIMEOUT; | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | # Digits only: whole seconds is what alarm() counts, and a pattern rules out | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # the numeric warning as much as the wrong value behind it. | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 11 | ▶ | die "MCP_RUN_TIMEOUT must be a whole number of seconds between 1 and $max, " | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$timeout =~ /\A[0-9]+\z/ and $timeout > 0 and $timeout <= $max
$timeout =~ /\A[0-9]+\z/ and $timeout > 0
MC/DC100%3/3
$timeout =~ /\A[0-9]+\z/ and $timeout > 0 and $timeout <= $max
$timeout =~ /\A[0-9]+\z/
$timeout > 0
$timeout <= $max
Truth table100%4/4
A and B and C
A= $timeout =~ /\A[0-9]+\z/B= $timeout > 0C= $timeout <= $max
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | . "got '$timeout'\n" | ||||||||||||||||||||||||||||||||||||||||||
| 38 | unless $timeout =~ /\A[0-9]+\z/ && $timeout > 0 && $timeout <= $max; | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 2 | $args{timeout} = $timeout + 0; | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 10 | $args{compress} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 10 | ▶ | if (defined $ENV{MCP_RUN_COMPRESS} && length $ENV{MCP_RUN_COMPRESS}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $ENV{"MCP_RUN_COMPRESS"} and length $ENV{"MCP_RUN_COMPRESS"}
MC/DC50%1/2
defined $ENV{"MCP_RUN_COMPRESS"} and length $ENV{"MCP_RUN_COMPRESS"}
defined $ENV{"MCP_RUN_COMPRESS"}
length $ENV{"MCP_RUN_COMPRESS"}
Truth table66%2/3
A and B
A= defined $ENV{"MCP_RUN_COMPRESS"}B= length $ENV{"MCP_RUN_COMPRESS"}
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | ▶ | $args{compress} = ( $ENV{MCP_RUN_COMPRESS} =~ /^(?:1|true|yes|on)$/i ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 10 | ▶ | if (my $name = $ENV{MCP_RUN_TOOL_NAME}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | $args{tool_name} = $name; | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 10 | MCP::Run::Bash->run_stdio(%args); | |||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | __END__ | ||||||||||||||||||||||||||||||||||||||||||