NAME

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

VERSION

version 0.001

SYNOPSIS

use MCP::Server::Run::Bash;

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

DESCRIPTION

Concrete MCP::Server::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)).

execute

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

Implements "execute" in MCP::Server::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

SUPPORT

Issues

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

CONTRIBUTING

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

AUTHOR

Torsten Raudssus <torsten@raudssus.de>

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus.

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