NAME

MCP::Run::Bash - MCP server that executes commands via bash

VERSION

version 0.106

SYNOPSIS

use MCP::Run::Bash;

my $server = MCP::Run::Bash->new(
    allowed_commands  => ['ls', 'cat', 'grep'],
    working_directory => '/var/data',
    timeout           => 30,
);
$server->run;

DESCRIPTION

Concrete MCP::Run subclass that executes commands by invoking bash -c $command via IPC::Open3. Captures stdout and stderr separately, enforces a per-command timeout using alarm, and returns the exit code.

When a working_directory is specified (either as a server default or passed per-invocation), it is prepended to the command as cd '$dir' && $command before being handed to bash.

On timeout the child process is sent SIGTERM and the exit code is set to 124 (matching the convention used by GNU timeout(1)).

name

Server name reported to the MCP client in serverInfo. Defaults to mcp-run-bash, overriding the PerlServer default inherited from MCP::Server. Pass name to the constructor to identify as something else.

version

Server version reported to the MCP client in serverInfo. Defaults to this distribution's version, overriding the 1.0.0 default inherited from MCP::Server.

execute

my $result = $self->execute($command, $working_directory, $timeout);

Implements "execute" in MCP::Run. Runs $command under bash -c, capturing stdout and stderr via IPC::Open3 and IO::Select. If $working_directory is defined, prepends cd '$working_directory' && to the command.

The timeout is enforced with alarm. On expiry, SIGTERM is sent to the child process and the exit code is set to 124.

Returns a hashref with keys exit_code, stdout, stderr, and optionally error.

SEE ALSO

  • MCP::Run - Base class defining the run MCP tool

SUPPORT

Issues

Please report bugs and feature requests on GitHub at https://github.com/Getty/p5-mcp-run/issues.

CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

AUTHOR

Torsten Raudssus <getty@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> https://raudssus.de/.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.