bash-mcp
Runs structured bash commands inside a WSL Ubuntu environment, returning stdout, stderr, exit code, duration, truncation and timeout flags. Provides persistent sessions with managed cwd and environment variables (including shared, live-updated envs), cwd allowlists and command classification for safety, plus an audit trail with rotation, gzip archival and readback.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
bash-mcp
A small MCP server that exposes WSL bash as a structured tool to MiniMax Code. Replaces the old wsl -d ... -- bash -c "..." PowerShell pattern with a single tool call.
Why
Running WSL commands from PowerShell (wsl -d Ubuntu-22.04 -- bash -lc "...") has daily friction costs:
Quoting hell — PowerShell reinterprets
$()asGet-Date, backticks, and regex escapes break.UTF-16 garbage —
wsl.exeto PowerShell pipe occasionally emits garbled output.Stateless shells — each call is a fresh shell; no cwd, env, or history.
Output is unstructured — stdout/stderr mixed, no exit code, no duration.
No safety net — a single bad
rm -rfquote wipes the home.
bash-mcp solves all of these with one tool call returning {stdout, stderr, exit_code, duration_ms, timed_out, truncated, classification, audit_id}.
Related MCP server: gitbash-mcp
License
What's new in v0.11.0
bash_mcp_session_fork(session_id, name?, cwd?)— a session can now be branched. The copy starts with the parent'scwdand its ownenvexactly as they are at that instant, and the parent is left untouched: it is a branch, not a move. A shared-env binding is inherited by reference, so the copy keeps seeing that env live. The fork is an ordinary session, so it is persisted to disk like any other (v0.9).Shared environments — a named dict of variables that several sessions can subscribe to, re-read on every run. Rotating a token in the shared env updates every subscribed session on its next command.
bash_mcp_env_share(name, vars, unset?)— create or update a shared env (varsmerges,unsetremoves keys).bash_mcp_env_list()— the shared envs and the sessions subscribed to each.bash_mcp_env_delete(name)— delete it and unsubscribe the sessions.bash_mcp_session_bind_env(session_id, env_name?)— subscribe a session; omitenv_nameto unsubscribe.Layering:
os.environ< shared env < the session's own env. The session's own value wins when both define the same key.One shared env per session; binding again replaces the previous one.
The values are write-only. They are applied to the commands but never echoed back:
env_shareandenv_listreturn key names and counts only, and the audit log records keys, never values — same rule as the rest of the audit trail.
17 tools (up from 12).
bash_mcp_statusnow derives the tool list from the FastMCP tool manager instead of a hand-maintained list, so a new tool can never drift out of sync.422 tests passing (up from 347).
What's new in v0.11.0
bash_mcp_session_fork(session_id, name?, cwd?)— a session can now be branched. The copy starts with the parent'scwdand its ownenvexactly as they are at that instant, and the parent is left untouched: it is a branch, not a move. A shared-env binding is inherited by reference, so the copy keeps seeing that env live. The fork is an ordinary session, so it is persisted to disk like any other (v0.9).Shared environments — a named dict of variables that several sessions can subscribe to, re-read on every run. Rotating a token in the shared env updates every subscribed session on its next command.
bash_mcp_env_share(name, vars, unset?)— create or update a shared env (varsmerges,unsetremoves keys).bash_mcp_env_list()— the shared envs and the sessions subscribed to each.bash_mcp_env_delete(name)— delete it and unsubscribe the sessions.bash_mcp_session_bind_env(session_id, env_name?)— subscribe a session; omitenv_nameto unsubscribe.Layering:
os.environ< shared env < the session's own env. The session's own value wins when both define the same key.One shared env per session; binding again replaces the previous one.
The values are write-only. They are applied to the commands but never echoed back:
env_shareandenv_listreturn key names and counts only, and the audit log records keys, never values — same rule as the rest of the audit trail.
17 tools (up from 12).
bash_mcp_statusnow derives the tool list from the FastMCP tool manager instead of a hand-maintained list, so a new tool can never drift out of sync.422 tests passing (up from 347).
What's new in v0.10.0
The gzip-on-rotation pass no longer destroys backups. The v0.7 gzip pass compressed a rotated backup, but the rotation shift only renamed plaintext backups (
audit.jsonl.N). Gzipped backups (audit.jsonl.N.gz) were never shifted, so they kept their index — and the next gzip pass wrote a freshaudit.jsonl.1.gzstraight over the existing one. With gzip enabled, every rotation silently destroyed the oldest backup. The shift now moves both variants, and the gzip pass never overwrites an existing archive (it warns and keeps both files instead).The gzip pass is on by default, above a 1 MiB threshold. Until now
BASH_MCP_AUDIT_GZIP_THRESHOLD_BYTESdefaulted to0(= disabled), so the feature existed but never ran unless you opted in. The default is now1048576(1 MiB): a rotated backup larger than that is compressed toaudit.jsonl.N.gzand its plaintext is removed. Set the env var to0to opt out and keep plaintext-only rotation.bash_mcp_statusgainedaudit.{gzip_backups, plaintext_backups}— how many rotated backups are compressed vs. plaintext, so the rotation can be verified at a glance.347 tests passing (up from 338).
What's new in v0.9.0
Sessions survive a server restart — every
bash_mcp_session_*mutation is mirrored to a SQLite store (~/.local/share/bash-mcp/sessions.db, stdlibsqlite3, no new dependency). On boot the server restores the sessions that were alive before, so a WSL reboot no longer wipes the agent's cwd/env state.New module
src/bash_mcp/session_store.py— one row per session (session_id,name,cwd,env,created_at,last_used_at). One connection per operation (FastMCP runs tools in a thread pool), so the store is thread-safe without extra locking.Fail-soft, always — a missing directory, an unwritable path or a corrupt database degrades to "no persistence"; it never raises into a tool call. Sessions keep working in memory.
Opt out —
BASH_MCP_SESSION_PERSIST=0restores the pre-v0.9 process-lifetime behaviour (nothing is written, nothing is read).Relocate —
BASH_MCP_SESSION_DB_PATHoverrides the location.Restore rules — a session whose
cwdwas deleted, that is no longer under an allowed root, or whose id is malformed is dropped from the store instead of being restored. The env dict is truncated toMAX_ENV_VARS.Idle eviction deletes the row too, so an evicted session does not come back on the next boot.
bash_mcp_statusgainedsessions.persistence.{enabled, path, persisted_sessions}.
12 tools, no new tool — v0.9 changes the lifecycle of the existing session tools; it does not add any.
What's new in v0.3.0
Audit log rotation —
audit.jsonlrotates at 25 MB (configurable) keeping 5 backups (audit.jsonl.{1..5}). Lazy + thread-safe.Concurrency limit — max 8 concurrent subprocesses via
threading.BoundedSemaphoreat the executor boundary. Excess calls queue, never drop.bash_mcp_statusextended withaudit.{max_bytes, backup_count, backups_present}andconcurrency.{max_concurrent, active}fields.95 tests passing (up from 84).
What's new in v0.8.0
Per-project cwd allowlists via
.bash-mcp.toml— drop a TOML file at your repo root (or any ancestor) and bash-mcp picks it up for calls whose cwd lives under that directory. Two modes:extend(default; merge with global) andreplace(sandbox; replace global). Zero behavior change when no file is present. See Configuration →.bash-mcp.tomlbelow for the schema. No new MCP tool — v0.8 is purely a config-driven feature.
What's new in v0.7.1
bash_mcp_audit_read(backup_index, max_entries?, tool_filter?)— closes the v0.7 gzip one-way archival caveat. Transparently decompressesaudit.jsonl.N.gzbackups in addition to plaintext. Returns a stable{backup_index, path, format, entries, returned}object. Audited astool="bash_mcp_audit_read".Cleanup — deleted stray
infra/install.sh.before-addendum(untracked, never committed).12 tools total (up from 11). 289 tests passing (up from 274). 86 smoke cases (up from 78).
All changes are non-breaking. v0.7.0 callers see zero behavior change.
What's new in v0.7.0
bash_mcp_classify(command)denylist explainer — read-only tool that returns{class, matched_pattern, pattern_index, hint_with_dangerous_false, hint_with_dangerous_true, would_execute, would_execute_with_dangerous_true, audit_id}. Use BEFOREbash_run_commandif you're unsure whether a command will be rejected. Saves a round-trip and gives the exact regex that would fire.Session auto-TTL (opt-in) — set
BASH_MCP_SESSION_IDLE_TIMEOUT_Sto enable. A daemon janitor evicts sessions whoselast_used_atis older than the timeout. Each eviction is audited astool="bash_mcp_session_destroy" reason="idle_ttl_expired". Default 0 = disabled (preserves v0.6 contract).Audit log gzip-on-rotation (opt-in) — set
BASH_MCP_AUDIT_GZIP_THRESHOLD_BYTESto enable. After rotation, any backup larger than the threshold is gzipped to.jsonl.N.gz(one-way; usezcatto inspect). Default 0 = disabled (preserves v0.3 plaintext-only behavior). (Since v0.10 the default is 1 MiB and the pass no longer destroys the oldest backup — see "What's new in v0.10.0".)bash_mcp_statusextended withaudit.{gzip_threshold_bytes, gzip_enabled}andsessions.{idle_timeout_s, janitor_enabled}.274 tests passing (up from 220).
All three features are opt-in via env vars and default to off, so existing callers see zero behavior change.
What's new in v0.6.0
Stateful sessions — four new tools (
bash_mcp_session_create,_run,_destroy,_list) keep a server-sidecwdand accumulatedenvdict across calls. Use them when you need tocdsomewhere and stay there, orexporta variable and have it persist for the next call.Sessions are process-lifetime — a server restart wipes them. Caller is responsible for
_destroy. There is no auto-TTL. (Superseded in v0.9: sessions are persisted to disk and restored on boot.)Best-effort parser — top-level
cd PATH,export VAR=value,unset VARare tracked; shell scripts, functions,$(...), heredocs are out of scope (the subprocess still runs correctly, but state isn't persisted from them).bash_mcp_statusextended withsessions.{active, max_env_per_session}.220 tests passing (up from 164).
See CHANGELOG.md for full history.
What's new in v0.4.0
Quarterly denylist review #1 — 6 new HARD patterns + 4 new SOFT patterns (see Safety table below).
Denylist review history in
safety.pydocumenting all reviews to date (v0.1, v0.2, v0.3, v0.4).164 tests passing (up from 95).
Tools
Tool | Purpose |
| Execute bash. Returns structured output. |
| OS, kernel, Python, uv, PATH entries. |
| ~37 well-known tools with |
| Resolve a single binary. |
| Service health, audit stats + rotation config, concurrency, sessions, uptime, tool list. |
| Create a stateful session; returns a |
| Run a command in a session; persists |
| Destroy a session, free memory, drop the disk row. |
| List active sessions, most-recently-used first (includes sessions restored on boot). |
| Branch a session: copy its |
| Create or update a named shared environment. v0.11. |
| List the shared environments and their subscribers (keys only, never values). v0.11. |
| Delete a shared environment and unsubscribe its sessions. v0.11. |
| Subscribe a session to a shared env (omit |
| Branch a session: copy its |
| Create or update a named shared environment. v0.11. |
| List the shared environments and their subscribers (keys only, never values). v0.11. |
| Delete a shared environment and unsubscribe its sessions. v0.11. |
| Subscribe a session to a shared env (omit |
| Read-only denylist explainer; returns |
| Read entries from a rotated audit backup (plaintext or gzip). v0.7.1. |
The server exposes its tools with underscore names (bash_run_command, bash_mcp_status, bash_mcp_session_create, ...). MiniMax Code prefixes them with the server name, so the tool you actually call is mcp__bash-mcp__bash_run_command. The hyphenated bash-mcp_run_command does not exist on the server.
Quick start (for the agent)
// Discover environment
bash_mcp_check_env()
// Check if a tool is installed
bash_mcp_list_binaries() // batch
bash_mcp_which({name: "rg"}) // single
// Run a command
bash_mcp_run_command({command: "ls -lah /tmp"})
// Run with custom cwd and timeout
bash_mcp_run_command({command: "pytest -xvs", cwd: "/home/jbecerra/projects/myapp", timeout_ms: 120000})
// Bypass the SOFT denylist
bash_mcp_run_command({command: "sudo systemctl restart nginx", dangerous: true})
bash_mcp_run_command({command: "pip uninstall requests", dangerous: true})
// Verify service health (audit + concurrency state)
bash_mcp_status()⚠️ DO NOT use wsl -d ... -- bash -c "..."
A PreToolUse hook in MiniMax Code denies any shell call whose command starts with wsl(\.exe)?\s. If you trigger it, you'll see an abort reason pointing you to this README.
Escape hatch (for genuine testing): prefix the command with BASH_MCP_SKIP=1.
Architecture
MiniMax Code ──HTTP POST──> bash-mcp server (WSL, port 54321)
│
├─ classify(command) → safe / dangerous / reject
├─ acquire concurrency.slot() (BoundedSemaphore, max 8)
├─ subprocess.run([bash, "-lc", command], ...)
├─ truncate stdout/stderr to 50KB
├─ audit.log(...) → audit.jsonl
└─ on size > 25 MB: rotate → audit.jsonl.{1..5}Streamable-http transport. bash_mcp_run_command is stateless per call; the
four bash_mcp_session_* tools additionally clone + write cwd and env
through src/bash_mcp/sessions.py (process-lifetime only). v0.7 adds a
daemon janitor thread (opt-in via BASH_MCP_SESSION_IDLE_TIMEOUT_S) and
gzip-on-rotation for the audit log (on by default above 1 MiB via
BASH_MCP_AUDIT_GZIP_THRESHOLD_BYTES; 0 disables it).
Safety
Full list lives in src/bash_mcp/safety.py. Snapshot:
HARD denylist (always rejected, cannot be bypassed):
Category | Patterns |
Block-device destruction |
|
Process / system | fork bombs ( |
Unrecoverable delete |
|
Supply chain |
|
SOFT denylist (requires dangerous=true):
Category | Patterns |
Privilege / process |
|
System changes |
|
Package removal (v0.4) |
|
Package install |
|
Destructive sync (v0.4) |
|
Every error response includes hint (actionable next step) and documentation (path to the skill) — the agent does not need to parse free text to recover.
cwd is allowlist-validated: must resolve under $HOME, /tmp, /home, /mnt/c/Users/jesus, or /var/tmp. Windows-style paths (C:\foo) are auto-converted to /mnt/c/foo.
Denylist is reviewed quarterly. Last review: v0.4 (2026-09-12) — see safety.py for full history.
Configuration
All via environment variables. Set them in the Environment= lines of infra/systemd/bash-mcp.service (the reference unit), export them in your shell before running locally, or add them to the screen launch command in infra/launcher.sh.
This WSL instance runs with
systemd=falsein/etc/wsl.conf, sosystemctl --useris unavailable (Failed to connect to bus) and the server runs in ascreensession instead. See Operations -> Start / stop / restart.
Variable | Default | Purpose |
|
| Bind address |
|
| Bind port (IANA dynamic range) |
|
| Audit log rotation threshold |
|
| Audit log backups kept |
|
| Rotated backups above this size are gzipped. |
|
| Max in-flight subprocesses |
|
| Persist sessions to disk (v0.9). |
|
| Session store location (v0.9) |
Shared environments live in the same SQLite file (tables shared_envs and
session_env_bindings). Limits: at most MAX_ENV_VARS (256) variables per
shared env and MAX_SHARED_ENVS (64) shared envs in total.
Shared environments live in the same SQLite file (tables shared_envs and
session_env_bindings). Limits: at most MAX_ENV_VARS (256) variables per
shared env and MAX_SHARED_ENVS (64) shared envs in total.
.bash-mcp.toml (per-project cwd allowlist, v0.8)
Drop a .bash-mcp.toml at any directory in your project. bash-mcp walks up
from the call's cwd to find it (stops at $HOME or filesystem root, max 32
hops) and applies the resulting allowlist to that call. No new tool, no
schema-validation library, no install hook.
Schema:
# mode is optional. Defaults to "extend".
mode = "extend" # or "replace"
# required: list of paths the project's cwds may resolve under.
# Relative entries resolve against the TOML's parent dir;
# absolute entries (after ~ expansion) are used as-is.
# Existence is NOT checked here — executor.run checks separately.
allowed_roots = [".", "frontend", "backend", "/srv/shared-cache"]Modes:
extend(default) — add the project'sallowed_rootsto the globalALLOWED_CWD_ROOTS. Use this when your project needs to expose additional worktrees, build dirs, or shared caches outside the global allowlist (e.g./srv/shared-cacheabove).replace— replace the global list with the project's roots. Use this for sandboxed environments where the global list is too permissive. An emptyallowed_rootslist is a deliberate lockout (no cwd is allowed; the caller receivesINVALID_CWD).
Failure modes (all fail-soft — bash-mcp falls back to the global allowlist, no crash):
Malformed TOML → stderr warning, global roots apply.
Unknown
modevalue → stderr warning, defaults toextend.allowed_rootsis not a list of strings → stderr warning, global roots apply.
Cache: the loaded allowlist is cached per (start_dir, mtime_ns) for
the lifetime of the bash-mcp process. Editing the TOML invalidates the
cache; deleting the TOML means the next call from that directory re-walks
the tree.
Deploying
infra/install.sh deploys everything to a fresh WSL/Windows setup:
systemd unit →
~/.config/systemd/user/bash-mcp.service(reference unit — on asystemd=falseWSL the server actually runs in ascreensession)PreToolUse hook →
~/.minimax/agents/mavis/hooks/bash-mcp-redirect.mdSkill →
~/.minimax/skills/bash-mcp/(and~/.mavis/skills/bash-mcp/for the legacy runtime)mcp.json entry →
~/.minimax/mcp/mcp.jsonAgent system_prompt addendum → reported on stdout by
install.sh [5/5]; applied manually once per environment via the desktopmavis agent update mavistool (the WSL and WindowsmavisCLIs do not expose theagentsubcommand)
The script also prints the one mavis mcp create command that must be
run from Windows PowerShell (the runtime registry is Windows-side).
./infra/install.shAgent integration
bash-mcp ships an infra/system-prompt-addendum.md that, when applied, is
appended to the mavis agent's systemPrompt. This is the agent-side guardrail
that prevents the model from falling back to the wsl -d ... -- bash -c "..."
pattern from PowerShell — even when the PreToolUse hook times out or the skill
isn't auto-loaded.
Auto-apply is not supported. The mavis CLI on WSL is the IDE launcher
(start / stop / status only), and the Windows mavis.cmd references
daemon/cli.js which is not bundled in current installs. Neither CLI exposes
agent update. The apply must be performed by the desktop mavis MCP tool,
which is what install.sh [5/5] documents on stdout.
Manual apply (run once per environment, anywhere with the desktop tool):
# install.sh prints the exact 3-step command (snapshot → build → apply)
# on stdout. The canonical addendum is at infra/system-prompt-addendum.md.
# Idempotent: rerun is a no-op if the marker substring is already in system_prompt.Why this lives in bash-mcp, not in the agent repo. bash-mcp is the project
that owns the bash-mcp-vs-wsl-d rule across all three sync points (skill,
hook, mcp.json description). The system_prompt addendum is the fourth sync
point — same wording, same escape hatch (BASH_MCP_SKIP=1), same cross-references
to this README. Keeping all four together is what AGENTS.md means by "four places
that must stay in sync".
Operations
Start / stop / restart
# Start (idempotent — waits for port 54321, retries up to 3 times)
bash ~/projects/bash-mcp/infra/launcher.sh
# Attach to the server's screen session (that is where the logs are)
screen -r bash-mcp # detach again with Ctrl-A d
# Stop
screen -S bash-mcp -X quit
# Health / config snapshot
bash_mcp_status()Why not
systemctl? This WSL instance runs withsystemd=falsein/etc/wsl.conf, sosystemctl --user start bash-mcp.serviceis a silent no-op (Failed to connect to bus) — the old launcher called it and never reported an error, so bash-mcp simply did not come back after a reboot. The unit file ininfra/systemd/is kept as the reference for theEnvironment=lines and thescreenExecStart.
Architecture diagram
architecture.mermaid is the source of truth; architecture.html is its
standalone render (open it in any browser). Regenerate after editing the
mermaid source:
uv run python infra/scripts/build-architecture.py # write architecture.html
uv run python infra/scripts/build-architecture.py --check # CI: fail if staleProve a session survives a restart (v0.9)
# 1. create a session with a distinctive cwd + env
uv run python infra/scripts/proof-persistence.py create
# 2. restart the server, then check the session came back
screen -S bash-mcp -X quit && bash ~/projects/bash-mcp/infra/launcher.sh
uv run python infra/scripts/proof-persistence.py check <session_id>Audit log (rotation in v0.3+)
The audit log at ~/.local/share/bash-mcp/audit.jsonl rotates automatically when it crosses BASH_MCP_AUDIT_MAX_BYTES (default 25 MB).
# Tail the current log
tail -f ~/.local/share/bash-mcp/audit.jsonl
# Pretty-print last 5 entries
tail -5 ~/.local/share/bash-mcp/audit.jsonl | jq .
# Check current size + rotation config
bash_mcp_status # → audit.size_bytes, audit.max_bytes, audit.backup_count, audit.backups_present
# List existing backups (audit.jsonl.{1..5})
ls ~/.local/share/bash-mcp/
# Read a specific backup
less ~/.local/share/bash-mcp/audit.jsonl.1 | jq .Rotation behavior:
Lazy — happens on next
log()call after the threshold is crossed.Thread-safe —
audit.jsonland the rotation move happen under one lock.Fail-soft —
OSErroron rename prints to stderr; next call retries.Naming —
audit.jsonl.{N}(stdlib convention); oldest is dropped when count exceedsBASH_MCP_AUDIT_BACKUP_COUNT.No content loss — verified by
test_rotation_preserves_content.
Concurrency (v0.3+)
Max 8 concurrent subprocesses by default. Excess calls queue (don't drop). Tune via BASH_MCP_MAX_CONCURRENT.
# Check current limit + active count
bash_mcp_status # → concurrency.max_concurrent, concurrency.activeIf you make 20 parallel tool calls, 8 run, 12 queue. The semaphore is at the executor boundary, so bash_run_command, bash_check_env's version probes, and any future subprocess-using tool all share the same cap.
Health check (no SSH/curl needed)
# Via MiniMax Code (recommended):
bash_mcp_status
# Or via shell + curl:
curl http://localhost:54321/mcp/ # then initialize + tools/call bash_mcp_statusWSL IP changed (after reboot)
cd /home/jbecerra/projects/bash-mcp
./infra/update-ip.shThis rewrites only the bash-mcp URL in ~/.minimax/mcp/mcp.json (and ~/.cursor/mcp.json if present). Does not touch semantic-memory.
Bootstrap on Windows login
infra/launcher.sh ships out of the box. To run it automatically on every Windows logon, register the scheduled task (run as Administrator from PowerShell):
powershell -ExecutionPolicy Bypass -File C:\path\to\bash-mcp\infra\windows\install-task.ps1This registers BashMcp-WSL-Bootstrap in Task Scheduler with a 60s delay, RunLevel=Highest, action = wsl.exe /home/jbecerra/projects/bash-mcp/infra/launcher.sh. The launcher starts bash-mcp in a screen session and waits for port 54321 (idempotent: if the port is already open it exits immediately).
Not registered on this machine. The XML ships in the repo but the task was never installed here —
Get-ScheduledTask -TaskName BashMcp-WSL-Bootstrapreturns nothing. Until it is registered, bash-mcp must be started manually after every reboot:bash ~/projects/bash-mcp/infra/launcher.sh.
Verify:
Get-ScheduledTask -TaskName BashMcp-WSL-Bootstrap | Format-ListRemove:
Unregister-ScheduledTask -TaskName BashMcp-WSL-Bootstrap -Confirm:$falseThe install.sh script (when run without --dry-run) prints the same install-task.ps1 path as a hint.
Development
Install
source ~/.local/bin/env
export PATH="$HOME/.local/bin:$PATH"
cd /home/jbecerra/projects/bash-mcp
uv syncRun locally
uv run python -m bash_mcp.server --transport streamable-http --host 0.0.0.0 --port 54321Run tests
uv run pytest tests/ -v357 tests cover:
106 safety cases (test_safety.py) — parametrized denylist + safe baselines + review-history
53 session registry cases (test_sessions.py) — create/run/destroy/list + state parsing
30 executor cases (test_executor.py) — subprocess + cwd allowlist + Windows→WSL
24 e2e cases against the live server (test_e2e.py)
20 session auto-TTL cases (test_sessions_ttl.py)
15 session persistence cases (test_sessions_persistence.py)
15 denylist-explainer cases (test_classify_tool.py)
14 gzip-on-rotation cases (test_audit_gzip.py)
12 audit read-back cases (test_audit_read.py)
11 per-project allowlist cases (test_project_allowlist.py)
10 live-server probe cases (test_live_server_probe.py)
9 error envelope cases (test_errors.py)
9 gzip rotation-lifecycle cases (test_audit_gzip_rotation.py)
6 audit log rotation cases (test_audit_rotation.py)
5 concurrency limit cases (test_concurrency.py)
4 server-persistence cases (test_server_persistence.py)
The end-to-end tests need a server that is not busy
test_e2e.py (24 tests) hits the live server on 127.0.0.1:54321. The server
serializes its work: while it executes a tool call it does not answer any
other MCP request. So running the suite through bash-mcp makes the e2e tests
skip — explicitly, with a visible reason, but skip. Run them from a shell
outside the server:
uv run pytest tests/ -m e2e -v -rs # only the live tests
uv run pytest tests/ -m "not e2e" -v # only the offline testsThe live_server fixture (tests/conftest.py) decides between running and
skipping, and it never skips silently:
Server state | Outcome |
Nothing listening on the port | the e2e are skipped, with the reason shown by |
Listening and answering | the e2e run |
Listening but not answering, suite running inside the server | the e2e are skipped with the reason shown |
Listening but not answering, suite running outside the server | the suite fails — something is genuinely wrong |
See tests/live_server.py for the decision matrix.
Project layout
bash-mcp/
├── AGENTS.md # project-scoped rules for future agents
├── CHANGELOG.md # version history
├── LICENSE # MIT
├── README.md # this file
├── architecture.mermaid # architecture diagram — source of truth
├── architecture.html # architecture diagram — standalone render (generated)
├── pyproject.toml # uv-managed, FastMCP 2.7.0
├── uv.lock
├── src/bash_mcp/ # server code
│ ├── server.py # FastMCP + 17 tools
│ ├── executor.py # subprocess wrapper, timeout, truncation, cwd allowlist, concurrency slot
│ ├── safety.py # classify(command) + quarterly denylist reviews
│ ├── audit.py # JSONL append-only logger + size-based rotation
│ ├── discovery.py # which / list_binaries (thread-pool)
│ ├── concurrency.py # BoundedSemaphore wrapper
│ ├── sessions.py # stateful sessions (cwd + env across calls) + fork + shared envs + fork + shared envs
│ └── project_allowlist.py # per-project .bash-mcp.toml resolution
├── tests/ # 422 tests (24 e2e need a live server)
│ ├── conftest.py # session-store isolation + the live_server gate
│ ├── live_server.py # live-server probe + run/skip/fail decision matrix
│ ├── test_safety.py # denylist cases
│ ├── test_executor.py # subprocess + cwd allowlist
│ ├── test_errors.py # error envelope shape + hints
│ ├── test_audit_rotation.py # rotation cases
│ ├── test_audit_gzip.py # gzip-on-rotation cases
│ ├── test_audit_gzip_rotation.py # gzip rotation lifecycle (v0.10)
│ ├── test_audit_read.py # bash_mcp_audit_read cases
│ ├── test_classify_tool.py # bash_mcp_classify cases
│ ├── test_concurrency.py # concurrency limit cases
│ ├── test_session_store.py # SQLite store + shared envs (v0.9 / v0.11)
│ ├── test_sessions.py # session create / run / destroy / list
│ ├── test_sessions_ttl.py # idle TTL janitor
│ ├── test_sessions_persistence.py # session persistence (v0.9)
│ ├── test_server_persistence.py # status + boot restore (v0.9)
│ ├── test_project_allowlist.py # .bash-mcp.toml resolution
│ ├── test_session_fork.py # session forking (v0.11)
│ ├── test_shared_env.py # shared environments (v0.11)
│ ├── test_session_tools.py # the v0.11 tools + live layering (v0.11)
│ ├── test_live_server_probe.py # probe decision matrix
│ └── test_e2e.py # live-server round-trips
└── infra/ # deployment artifacts
├── install.sh # idempotent deploy (--dry-run supported)
├── launcher.sh # WSL bootstrap — starts the server in screen
├── update-ip.sh # refresh WSL IP in mcp.json
├── mcp.json.snippet # documentation reference
├── scripts/
│ ├── smoke-v07.py # live-server round-trip for every tool
│ ├── build-architecture.py # regenerate architecture.html from architecture.mermaid
│ └── proof-persistence.py # prove a session survives a server restart (v0.9)
├── systemd/
│ └── bash-mcp.service # reference unit (screen ExecStart)
├── hooks/
│ ├── bash-mcp-redirect.md
│ └── bash-mcp-redirect.js
├── skills/
│ └── bash-mcp/
│ ├── SKILL.md
│ └── _meta.json
└── windows/ # Windows-side deployment helpers
├── BashMcp-WSL-Bootstrap.xml # Scheduled Task template
└── install-task.ps1 # PowerShell installer for the taskAdd a new tool
from bash_mcp import audit
@mcp.tool
def bash_my_new_tool(...) -> dict:
"""Docstring becomes the tool description for the agent."""
...If your tool calls subprocess.run, wrap it in concurrency.slot() so it participates in the global cap:
from bash_mcp.concurrency import slot as concurrency_slot
with concurrency_slot():
subprocess.run([...])Add a denylist pattern
Add to
REJECT_PATTERNS(hard) orDANGEROUS_PATTERNS(soft) insrc/bash_mcp/safety.py.Add a parametrized test case in
tests/test_safety.py.Update
README.mdsafety table and the deployed~/.mavis/skills/bash-mcp/SKILL.md.Add a dated entry to the review-history block at the top of
safety.pylisting what was added.Restart the server so the new pattern is live:
screen -S bash-mcp -X quit && bash ~/projects/bash-mcp/infra/launcher.sh.
For non-trivial gaps or batch additions, treat it as a quarterly review (see AGENTS.md).
Adjust rotation / concurrency limits
Change the
Environment=lines ininfra/systemd/bash-mcp.service(the reference unit) or export the variable before starting the launcher.Restart:
screen -S bash-mcp -X quit && bash ~/projects/bash-mcp/infra/launcher.shVerify via
bash_mcp_status()that the new values are loaded.
Test the hook manually
# Should deny (abort)
echo '{"input":{"toolName":"bash","toolArgs":{"command":"wsl -d Ubuntu -- bash -c \"echo hi\""}},"output":{}}' \
| node /home/jbecerra/projects/bash-mcp/infra/hooks/bash-mcp-redirect.js
# => {"_abort":{"reason":"..."}}
# Should pass
echo '{"input":{"toolName":"bash","toolArgs":{"command":"git status"}},"output":{}}' \
| node /home/jbecerra/projects/bash-mcp/infra/hooks/bash-mcp-redirect.js
# => {}
# Should pass (escape hatch)
echo '{"input":{"toolName":"bash","toolArgs":{"command":"BASH_MCP_SKIP=1 wsl echo"}},"output":{}}' \
| node /home/jbecerra/projects/bash-mcp/infra/hooks/bash-mcp-redirect.js
# => {}Deploy to a fresh WSL machine
git clone <this-repo> /home/jbecerra/projects/bash-mcp
cd /home/jbecerra/projects/bash-mcp
./infra/install.sh
# Then from Windows PowerShell, run the printed `mavis mcp create` command.Out of scope (deferred to v0.9+)
Already shipped:
Stateful sessions with persistent cwd across calls— shipped in v0.6 (bash_mcp_session_create/_run/_destroy/_list). Process-lifetime only; see "What's new in v0.6.0".Windows Scheduled Task XML for login auto-start— shipped in v0.5 atinfra/windows/BashMcp-WSL-Bootstrap.xml+install-task.ps1.Auto-TTL / idle cleanup— shipped in v0.7 (opt-in viaBASH_MCP_SESSION_IDLE_TIMEOUT_S, daemon janitor thread + audit on each eviction). See "What's new in v0.7.0".A "denylist explainer" tool— shipped in v0.7 asbash_mcp_classify(command). Returns{class, matched_pattern, hint, would_execute, ...}without executing. Lets the agent self-check before sending.
Still pending:
Persistent shell state (PTY-based) — v0.6 sessions are best-effort regex parsing of
cd/export/unset. v0.7 could keep a realbashprocess alive per session (viapexpector similar) and track shell variables, aliases, functions,set -e/pipefail, and job control. Requires a redesign of the session lifecycle and a hard cap on concurrent shells (memory + fd cost).Disk persistence for sessions— shipped in v0.9 (SQLite store insession_store.py, restored on boot, opt-out viaBASH_MCP_SESSION_PERSIST=0). See "What's new in v0.9.0".Session snapshots(forka session at a point in time)— shipped in v0.11 asbash_mcp_session_fork: the copy is the snapshot. See "What's new in v0.11.0".Cross-session env sharing— shipped in v0.11 as the shared-env tools, live and one-per-session. See "What's new in v0.11.0".Web UI for browsing the audit log — minimal Flask/FastAPI page on a separate port with filters by tool / classification / time.
Audit log compression— shipped in v0.7.1 viabash_mcp_audit_read(closes the gzip one-way archival caveat) and completed in v0.10, which fixed the rotation pass that destroyed the oldest backup and turned the gzip threshold on by default (1 MiB). See "What's new in v0.7.1" and "What's new in v0.10.0". Remaining: audit log shipping (Loki/CloudWatch), still deferred.Audit log shipping — Loki push API, CloudWatch Logs, or local syslog. Optional, gated by config.
Per-project allowlists(.bash-mcp.tomlin repo root)— shipped in v0.8 via the.bash-mcp.tomlschema. See Configuration →.bash-mcp.tomlabove. Supports bothextend(merge with global) andreplace(sandbox) modes.A formal threat-model document — STRIDE-style analysis of the audit log, the hook, the denylist, and the session lifecycle.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Operate Linux, macOS and Windows from your LLM. Every action runs through an auditable allowlist.
Autonomous agent guardrails, bash sandboxing, MCP rugpull diffing & prompt firewalls.
Run commands, code and file operations for AI agents in Cloud Hypervisor microVM sandboxes.
Use your own Windows, Mac or Linux computer from ChatGPT, Claude, Cursor or Gemini CLI: run commands, read, write and search files, run long processes. Your computer only makes an outgoing connection (no open ports or VPN). Read-only mode, allowed folders, blocked commands and an action log keep you in control. Free plan available.
Related MCP Servers
AlicenseAqualityFmaintenanceSandboxed Bash for Agents. Full state capture on every command.328 npm15Apache 2.0- AlicenseAqualityCmaintenanceRuns git-bash (MSYS2) commands for AI agents on Windows from outside the agent's sandbox, so pipelines, command substitution, and subprocesses work. Exposes exec, bash_info, doctor, and policy tools with timeouts, output spilling, concurrency limits, capability-based command gating, and JSONL auditing.4MIT
- AlicenseAqualityFmaintenanceEnables an AI agent to run shell commands and move files inside a WSL distro on the same Windows machine via wsl.exe, with no sshd, key, or port required. Each pre-registered distro-and-user entry enforces guard policies limiting dangerous commands, Windows interop, write targets, and accessible paths.101MIT
- AlicenseNot gradedqualityCmaintenanceEnables AI agents on Windows to read, write, copy, move, and delete files inside WSL distributions, run shell commands in a login shell, and convert between Windows and Linux path styles. Commands are piped to bash -s via stdin so quotes, $, backticks, and other special characters pass through without Windows shell escaping errors.MIT