Skip to main content
Glama

Bash MCP Server (bash-mcp)

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.


Key Features

  • 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_PATH environment variable across all platforms. The target executable is expected to implement Bash semantics and accept standard -c <command> arguments.

  • 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 via setsid or 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.

  • 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.

  • 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-remote opt-in.


Related MCP server: Bash MCP Server

Exposed Tools

1. execute_bash

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=True

  • open_world_hint=True

  • read_only_hint=False

2. get_bash_environments

Returns diagnostic details about all detected Bash runtimes, executable paths, and the active default environment.


Installation & Setup

Ensure uv is installed.

# Clone or navigate to the repository
cd bash-mcp

# Install dependencies and sync the virtual environment
uv sync

Running the Server

Stdio Transport (Default)

uv run bash-mcp
uv run bash-mcp --transport streamable-http --host 127.0.0.1 --port 8000

Legacy SSE Transport

uv run bash-mcp --transport sse --host 127.0.0.1 --port 8000

Security 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.


Integrating with Antigravity / MCP Clients

Antigravity Global Configuration (~/.gemini/config/mcp_config.json)

{
  "mcpServers": {
    "bash": {
      "command": "uv",
      "args": [
        "--directory",
        "C:\\Users\\User\\stuff\\bash-mcp",
        "run",
        "bash-mcp"
      ]
    }
  }
}

Running Tests

Run the test suite with pytest:

uv run pytest

Available Tools

2 tools
execute_bashB
Destructive

Execute a Bash command or script with robust process lifecycle management. Automatically detects and uses Git Bash or WSL on Windows, and native Bash on POSIX.

ParametersJSON Schema
NameRequiredDescriptionDefault
cwdNo
commandYes
env_typeNoauto
timeout_secondsNoExecution timeout in seconds (1-3600).

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

B3/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare destructiveHint=true and openWorldHint=true, and the description's 'Execute a Bash command or script' is consistent with those. The description adds useful context about automatic Git Bash/WSL detection and process lifecycle management, though 'robust process lifecycle management' is vague and does not detail side effects or termination behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise at two sentences and front-loads the core action. The phrase 'robust process lifecycle management' adds little concrete detail, but the overall length is appropriate and not bloated.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a destructive, open-world command executor with four parameters, the description gives useful but incomplete context. It covers environment auto-detection, but omits cwd semantics, return/output behavior, and does not mention when to call get_bash_environments. The output schema and annotations partially compensate for these gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is low at 25%; only timeout_seconds has an inline description. The description partially covers env_type by mentioning automatic Git Bash/WSL detection, but it does not explain the command parameter, cwd, or env_type enum values beyond the schema. cwd is left entirely to inference.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with a clear action ('Execute') and a specific resource ('Bash command or script'), so an agent can understand the core function immediately. It does not explicitly differentiate from the sibling get_bash_environments, but the tool names and general purpose are clear enough.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no explicit guidance about when to use this tool versus alternatives like get_bash_environments. It states what the tool does, but selection criteria are left entirely to inference.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

get_bash_environmentsA
Read-only

Inspect detected Bash runtime environments and paths on the current system.

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.3/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare readOnlyHint=true and destructiveHint=false. The description adds useful context by stating that this inspects 'detected' environments on the 'current system,' implying local discovery rather than exhaustive enumeration. This goes beyond the annotations without contradicting them.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single concise sentence with no filler. The core action and resource are front-loaded, making it easy for an agent to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

This is a simple zero-parameter inspection tool with a rich output schema and annotations indicating read-only, non-destructive behavior. The description sufficiently explains what the tool returns information about, and nothing essential is missing for safe invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has zero parameters and schema description coverage is 100%, so there is no parameter ambiguity. The baseline for zero-parameter tools is 4, and the description needs to communicate nothing further about arguments.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description uses a specific verb ('Inspect') and a specific resource ('detected Bash runtime environments and paths on the current system'). This clearly distinguishes it from sibling execute_bash, which is about running commands rather than inspecting environment information.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies the tool is for inspecting discovered Bash environments, but it does not explicitly state when to prefer this over execute_bash or provide any exclusion criteria. An agent can infer the usage context, but the guidance is not explicit.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 2 tool updatesv0.1.0
    • First observedexecute_bash
    • First observedget_bash_environments

TDQS

A3.7/5.0

Scored across 2 tools

Disambiguation5/5

The two tools have clearly distinct purposes: one executes commands, the other inspects the environment. There is no overlap or ambiguity between them.

Naming Consistency5/5

Both tool names follow a consistent verb_noun pattern: execute_bash and get_bash_environments. The naming style is uniform and predictable.

Tool Count4/5

Two tools is minimal but appropriate for a narrowly scoped bash execution server. The environment inspection tool supplements the primary execution capability without unnecessary bloat.

Completeness4/5

The core domain of executing bash commands is fully covered by execute_bash, and environment introspection adds useful context. While more convenience tools could exist, most operations can be accomplished through command execution.

Maintenance

ActivityMaintained
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    C
    maintenance
    Enables execution of bash commands with support for timeouts and background jobs, allowing file operations, build commands, system inspection, and long-running tasks.
    36 npm
    9
    MIT
  • A
    license
    A
    quality
    C
    maintenance
    An MCP server that enables the execution of arbitrary bash commands and returns detailed output including stdout, stderr, and exit codes. It supports customizable working directories, execution timeouts, and environment variable configurations.
    1
    MIT
  • A
    license
    A
    quality
    C
    maintenance
    Enables execution of bash commands via MCP, allowing clients to run shell commands and set a working directory.
    2
    34
    MIT
  • A
    license
    B
    quality
    D
    maintenance
    Enables secure execution of whitelisted shell commands through MCP, with support for stdin input, timeout control, and comprehensive output including stdout, stderr, and execution time.
    1
    MIT