A Model Context Protocol (MCP) server that provides robust Bash execution capabilities across Windows, macOS, and Linux. Built with Python 3.12+ and managed with uv.
- Cross-Platform Multi-Runtime Support:
- Windows: Automatically detects and supports Git Bash (
C:\Program Files\Git\bin\bash.exe), WSL (Windows Subsystem for Linux), and MSYS2. - macOS / Linux: Native POSIX
bash. - Custom Override: Override runtime with the
BASH_PATHenvironment variable across all platforms. The target executable is expected to implement Bash semantics and accept standard-c <command>arguments.
- Windows: Automatically detects and supports Git Bash (
- Process Lifecycle Management & Containment Model:
- Windows (Git Bash / MSYS2): Windows Job assignment is best-effort and occurs immediately after process creation; a short pre-assignment execution window exists. Processes assigned to the dedicated Windows Job Object (
JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE) have termination attempts performed on their entire process tree on timeout, cancellation, or error. - WSL (Linux VM): Employs PID-marker-based process-group signaling and clean group termination (
SIGTERM->SIGKILL) to terminate background Linux processes inside the VM on timeout or cancellation. (Note: commands that detach into independent sessions viasetsidor modify supervisor markers require container-level isolation such as Docker/cgroups for full sandbox containment). - POSIX (macOS / Linux): Creates isolated process groups (
start_new_session=True) and performs phased shutdown (SIGTERM-> 0.2s grace interval ->SIGKILL). - Cancellation-Safe: Shielded cleanup performs bounded reader-drain and process-reap attempts, and closes pipe transports even under repeated task cancellation.
- Windows (Git Bash / MSYS2): Windows Job assignment is best-effort and occurs immediately after process creation; a short pre-assignment execution window exists. Processes assigned to the dedicated Windows Job Object (
- Exact Bash Semantics:
- WSL commands are passed directly as raw positional parameters without outer shell interpolation, preserving exact variable scoping, literal single-quotes, and quoted heredocs.
- PE Binary Screening:
- Checks expected DOS/PE signatures (
MZ,PE\0\0) for Windows binary executables, rejecting plain-text or corrupt files.
- Checks expected DOS/PE signatures (
- Bounded Stream Capture & Truncation Metadata:
- Streams are drained concurrently with per-stream byte limits (default 1 MB) to prevent unbounded memory consumption from noisy commands.
- Output truncation is clearly indicated in results with byte-accurate counts.
- Partial output emitted prior to timeouts is preserved.
- Modern Transport Protocols:
stdio(default, recommended for local clients like Antigravity, Claude Desktop, Cursor).streamable-http(recommended modern network transport).sse(legacy network transport).- Strict loopback protection: only canonical loopback addresses (
127.0.0.1,localhost,::1) are permitted without explicit--allow-remoteopt-in.
Executes a Bash command, pipeline, or multi-line script.
| Parameter | Type | Default | Description |
|---|---|---|---|
command |
string |
(required) | The Bash command or multi-line script to run. |
cwd |
string |
null |
Working directory. Accepts Windows paths or native POSIX paths (e.g. /tmp under WSL). |
timeout_seconds |
integer |
120 |
Execution timeout in seconds (must be between 1 and 3600). |
env_type |
string |
"auto" |
Execution environment ("auto", "git_bash", "wsl", "msys2", "native", "custom"). |
Tool Annotations:
destructive_hint=Trueopen_world_hint=Trueread_only_hint=False
Returns diagnostic details about all detected Bash runtimes, executable paths, and the active default environment.
Ensure uv is installed.
# Clone or navigate to the repository
cd bash-mcp
# Install dependencies and sync the virtual environment
uv syncuv run bash-mcpuv run bash-mcp --transport streamable-http --host 127.0.0.1 --port 8000uv run bash-mcp --transport sse --host 127.0.0.1 --port 8000Security Note: Binding to non-loopback interfaces requires passing
--allow-remote. Because command execution runs with host user privileges, network deployments should be secured with TLS, authentication proxies, or container isolation.
{
"mcpServers": {
"bash": {
"command": "uv",
"args": [
"--directory",
"C:\\Users\\User\\stuff\\bash-mcp",
"run",
"bash-mcp"
]
}
}
}Run the test suite with pytest:
uv run pytest