gitbash-mcp
This server lets an AI agent run git-bash (MSYS2) commands on Windows outside its sandbox, with background jobs, policy controls, and diagnostics.
exec: run bash commands/scripts with configurable cwd, env, login shell, and timeout; returns stdout/stderr, exit code, and audit/policy info.
Background jobs:
run_in_backgroundstarts long tasks; job tools (job_output,job_list,job_kill) let you monitor, retrieve output, and stop them.bash_info: report bash path and bash/git versions.
doctor: diagnose git-bash installation and resolve BASH_NOT_FOUND issues.
policy: show the risky-command stance and rules to explain blocks (APPROVAL_REQUIRED / POLICY_DENIED).
Safety limits: concurrency cap, 64KB output spill, whole-tree cancellation, and audit logging—though it is not a security boundary.
Runs bash commands through the git-bash (MSYS2) shell shipped with Git for Windows, giving AI agents a full shell outside their sandbox. Exposes an exec tool that runs bash commands or multi-line scripts with working directory, timeout (killing the whole process tree), login-shell and env options, returning structured results (exit code, stdout/stderr, truncation, spill file, duration, audit id). Also provides bash_info for bash/git versions, doctor for environment diagnostics, and policy for the command-approval posture. Includes zero-config guardrails: process-tree kill on cancel, concurrency limit of 4 with queue reporting, 64KB output caps with spill files in %TEMP%, credential-shaped env var scrubbing, JSONL audit logging, and a read-only/project vs mutating/opaque/catastrophic command classification.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@gitbash-mcprun bash: git log --oneline | head -20 and show me the output"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
gitbash-mcp
把 git-bash (MSYS2) 交给 AI agent 用的 MCP server(DSH / Claude Code / Codex / Cursor / VS Code / Claude Desktop)。
它在 agent 沙箱之外运行:管道、$(...)、子进程、Docker 全部可用;长任务可以转成后台作业。
工具:
exec、job_output、job_list、job_kill、bash_info、doctor、policy运行时 Node >= 18(兼容 Bun);协议 MCP stdio;只支持全局安装
部署
npm i -g gitbash-mcp
gitbash-mcp init # 交互式勾选客户端;--yes 免交互,--dry-run 只预览
gitbash-mcp uninstall # 反向移除,只删自己的条目init 写入绝对路径(node <...>/bin/gitbash-mcp.js),因为 npm / bun 的 shim 目录常常不在 GUI 客户端的 PATH 上。
写入前会备份 *.bak,重复运行幂等。配置完重启对应客户端。
客户端 | 写入位置 | 格式 |
DSH |
| YAML insert |
Claude Code |
|
|
Codex CLI |
|
|
Claude Desktop |
|
|
Cursor |
|
|
VS Code |
|
|
只支持全局安装,不支持 npx / bunx(多一层包装,在 Windows 上以 stdio 启动不稳定)。
bash 找不到时服务照常启动:exec 返回修复指引,doctor 给完整诊断。
Related MCP server: Capsule Bash Server
使用
exec
参数 | 说明 |
| 必填,bash 命令或多行脚本 |
| 工作目录;省略时用客户端声明的 workspace root |
| 进程生命期:前台默认 60000,后台默认不限 |
|
|
| 追加环境变量;值为 |
|
|
返回 JSON,常用字段:
字段 | 含义 |
| 退出码;被杀为 |
| 单流最多 64KB,超出部分转存到 |
| 前台是否没等到结束 / 命令是否还活着(还活着就用 |
|
|
| 实际耗时 / 因并发上限排队的时间 |
| 审计 id / 一行裁决 / 下一步建议 |
命令失败(非零退出、超时、spawn 失败)同样是这个结构,不抛工具错误。每次调用都是新进程,状态不保留。
路径转换默认关闭,所以写 cmd /c … 而不是 cmd //c …(后者会挂住,工具会直接拒绝并提示);
需要旧行为时单次传 env: {"MSYS_NO_PATHCONV": ""}。
长任务与后台作业
前台调用最多等 45 秒;超过时命令不会被杀,而是转成后台作业继续跑并返回 job_id:
工具 | 作用 |
| 毫秒级返回 |
| 默认返回状态 + 每条流尾部 64KB; |
| 列出作业、状态、退出码 |
| 显式停止(杀整棵树) |
典型流程:
exec { command: "docker pull postgres:17.9", run_in_background: true } -> job-xxxx
job_output { job_id: "job-xxxx", wait: true, timeout_ms: 30000 } # 等到结束,收退出码
job_output { job_id: "job-xxxx", offset_bytes: 65536 } # 接着上次的字节偏移读增量
job_kill { job_id: "job-xxxx" } # 显式停止作业活在 server 进程内:重启客户端会丢句柄,但审计日志记了作业的起止、退出码与输出文件路径,结果还能从盘上捞回。
需要跨重启的可靠后台执行,请用 schtasks 或系统服务。
其他工具
bash_info— bash 路径与 bash/git 版本doctor— 完整环境诊断;bash 行为异常先调它policy— 当前姿态与完整规则;被拦住后调它才能向用户解释清楚
命令策略
不是黑名单,是能力分类:命令逐段判定,只有每段都可读、或由项目自己声明、且没有不可判读构造时才自动放行。
唯一开关 GITBASH_MCP_RISKY 写在 MCP 客户端配置里(模型改不了,改完要重启服务器)。
判定 | 默认 |
|
read-only / project | 放行 | 放行 |
mutating / unknown / opaque | 拦住,让你决定 | 放行 + 审计 |
catastrophic | 拒绝 | 放行 + 审计 |
被拦住时模型会拿到三条路:① 你自己在终端跑 ② 换更安全的写法 ③ 配置 GITBASH_MCP_RISKY=allow 并重启。
本进程在沙箱外运行,权限 = 启动它的 agent 进程的完整用户权限,没有文件沙箱。 命令策略、并发上限、输出封顶、审计日志都是「降低误伤」的护栏,不是安全边界。
相关文档
docs/DESIGN.md— 完整契约、决策记录与被否方案docs/REPO_MAP.md— 代码地图docs/PLAN.md— 里程碑与风险登记AGENTS.md— 维护者须知
Available Tools
4 toolsbash_infoShow git-bash environment infoA
Report the resolved bash path, bash/git versions and key environment values. Use doctor for a full diagnosis.
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations exist, so the description carries the full burden. It discloses the read-only nature implicitly by saying 'Report', and lists what values are surfaced, but says nothing about format, caching, or whether output is human- or machine-readable. Adequate but thin for an annotation-free tool.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Two tight sentences, front-loaded with the primary action and immediately followed by the alternative. No filler.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a parameterless info tool with no output schema, the description covers what it reports and where to go if more is needed. It could name the keys returned, but nothing essential for correct invocation is missing.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Zero parameters, so the schema provides nothing to describe and the baseline is 4. The description correctly reflects a no-argument tool rather than implying hidden inputs.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
States a specific verb (Report) plus concrete resources (bash path, bash/git versions, key environment values), and names the sibling 'doctor' as the richer alternative. An agent can distinguish this from exec/doctor/policy without reading schemas.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Explicitly routes heavier diagnostic needs to 'doctor', giving a clear alternative for the wider case. It stops short of stating when this tool is the right choice vs. checking exec or policy, but the routing cues are solid.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
doctorDiagnose the git-bash environmentA
Report how git-bash and git are resolved: every candidate path probed, which one won, the GITBASH_BASH value and whether it is valid, git on PATH, the audit log location, and the exact fix steps when bash is missing. Run this first when exec reports BASH_NOT_FOUND or when bash behaves unexpectedly.
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the burden. It is implicitly read-only (it only reports and offers fix steps) and the zero-parameter schema means side effects are low risk, but it never states that it makes no changes, whether it inspects the filesystem, or what the cost/latency of probing paths is. Adequate but not rich.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Two sentences, both front-loaded: the first lists the diagnostic outputs, the second gives the trigger conditions. Every clause names a distinct output field or a distinct invocation condition; nothing is filler or restated from the name.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
There is no output schema, so the description must describe the return content — and it does so field by field (paths, winner, GITBASH_BASH, git on PATH, audit log, fix steps). Combined with the zero-param schema and the stated triggers, an agent has everything needed to decide to call it and to interpret the result.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The tool takes no parameters, so there is nothing for the description to disambiguate — the baseline for a zero-parameter tool is 4. There are no argument formats, defaults, or enums that need explanation.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description gives a specific verb ('Report how git-bash and git are resolved') and enumerates the exact artifacts it surfaces: candidate paths probed, the winning path, GITBASH_BASH validity, git on PATH, audit log location, and fix steps. It is clearly a diagnostic, not an action tool. It does not explicitly differentiate itself from the sibling bash_info, which likely also concerns bash resolution, so 4 rather than 5.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Explicit triggers are given: 'Run this first when exec reports BASH_NOT_FOUND or when bash behaves unexpectedly.' This tells the agent precisely when this tool is the right call versus the sibling exec. It stops short of naming or excluding bash_info/policy as alternatives, so no full when-not guidance.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
execRun a git-bash commandA
Run a command or multi-line script in git-bash (MSYS2 bash on Windows) and return stdout, stderr and exit code. On Windows this is the preferred shell tool: choose it over a sandboxed PowerShell or shell tool for shell, git, build and script work, and keep the native PowerShell tool for Windows-native cmdlets, COM or .NET calls. Use for bash/git workflows: git, grep/sed/awk pipelines, shell loops, make, scripts. This bridge runs OUTSIDE the agent sandbox: pipes work here that a sandboxed shell tool cannot create. Each call starts a fresh bash process; state does not persist between calls (use cd in the command or pass cwd). Command failures return a JSON result with a non-zero exit_code, so they never raise tool errors. A policy engine blocks destructive commands: such a call returns error_code APPROVAL_REQUIRED (ask the user how to proceed) or POLICY_DENIED (blocked at the current stance). Call the policy tool to see the rules and the current stance. Resource limits: at most 4 commands run at once (extra calls queue and report queued_ms), captured output is capped at 64KB per stream with the remainder written to a capped spill file, and cancelling the tool call kills the whole process tree (killed_by: "cancel"). Every call is recorded in a local audit log; the user can read it with the gitbash-mcp audit command. If git-bash is missing the result carries error_code=BASH_NOT_FOUND with fix instructions; call doctor for details.
| Name | Required | Description | Default |
|---|---|---|---|
| cwd | No | Working directory (Windows path). Defaults to the server working directory | |
| env | No | Extra environment variables for this command (passed through as given, not scrubbed) | |
| login | No | Use bash -lc (login shell, sources profile) instead of bash -c | |
| command | Yes | The bash command line or multi-line script to execute | |
| timeout_ms | No | Kill the command after this many ms (default 60000) |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the full burden and does so well: fresh process per call with no persistent state, non-zero exit_code returned as JSON rather than a tool error, destructive-command blocking with APPROVAL_REQUIRED/POLICY_DENIED codes, 4-command concurrency limit with queued_ms, 64KB per-stream output cap with spill file, process-tree kill on cancel, and audit logging. This is unusually rich behavioral disclosure.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Front-loaded with the core action and the routing rule, which is good. However the back half is a dense wall of operational detail (policy codes, resource limits, audit log, BASH_NOT_FOUND) that is comprehensive but heavy; some items (e.g., audit log command) feel peripheral to invocation decisions and could be trimmed or deferred to the doctor/policy siblings.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a 5-param tool with no annotations and no output schema, the description nearly covers everything an agent needs: routing, stateless behavior, error/exit-code semantics, policy gating, resource limits, cancellation, and the missing-bash fallback. No output schema exists, yet return behavior is explained, so nothing critical is missing.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema coverage is 100%, so baseline is 3. The description adds meaning beyond the schema by warning that each call starts a fresh process (state does not persist) and advising to use cd in the command or pass cwd, which clarifies the cwd parameter's role in the stateless model. Slightly above baseline.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
States a specific verb (run), resource (a git-bash command/script), and the return payload (stdout, stderr, exit code). It explicitly distinguishes itself from the sibling sandboxed PowerShell/shell tool and the native PowerShell tool, so an agent can route correctly without opening any schema.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Explicit when-to-use (git, grep/sed/awk pipelines, shell loops, make, scripts) and when-not (Windows-native cmdlets, COM, .NET — use the PowerShell tool). It also contrasts with the sandboxed shell tool by noting this one runs outside the sandbox. Alternatives are named, not merely implied.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
policyShow the command policyA
Report the active risky-command stance (GITBASH_MCP_RISKY, set by the user in the MCP client config), what each rule tier does under it, and the full rule list. Call this after exec returns error_code POLICY_DENIED or APPROVAL_REQUIRED, so you can explain the block and the user options accurately.
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the disclosure burden and does so well: it names the controlling variable (GITBASH_MCP_RISKY), where it is set (MCP client config), and the three components returned. It does not explicitly state that the call is read-only/side-effect free, which is the only remaining gap for a zero-argument introspection tool.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Two sentences, both earning their place: the first enumerates output content, the second gives the triggering condition and rationale. Front-loaded with what the tool reports rather than preamble.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
There is no output schema, so the description must sketch return content, and it does by listing the stance, per-tier rule behavior, and the rule list. It stops short of describing format or structure of the rule list, a minor omission for an otherwise self-contained introspection tool.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The tool takes zero parameters, so per the baseline this scores 4; there is no parameter semantics to add. The description's mention of GITBASH_MCP_RISKY usefully clarifies that the stance is external configuration rather than a call argument.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
States a specific verb (Report) and precisely enumerates the resource: the active risky-command stance, what each rule tier does, and the full rule list. This is plainly distinguishable from exec, bash_info, and doctor, none of which report policy state.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Gives an explicit trigger condition — call this after exec returns error_code POLICY_DENIED or APPROVAL_REQUIRED — and states the goal (explain the block and the user's options). Nothing about when to invoke is left to inference.
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.
4 tool updates
v2.3.0- First observed
bash_info - First observed
doctor - First observed
exec - First observed
policy
TDQS
Scored across 4 tools
exec is clearly the action tool, while bash_info, doctor, and policy are distinct diagnostic/info tools. bash_info and doctor overlap somewhat (both report bash path and versions), but the descriptions specify that bash_info is a quick summary and doctor is a full diagnosis with fix steps.
The set mixes a verb-style name (exec) with noun-style names (bash_info, doctor, policy), so there is no single predictable verb_noun pattern. Names are still short, readable, and unambiguous, but the convention is not consistent.
Four tools is lean but well-scoped for a shell bridge: one execution tool plus three focused diagnostics. It is slightly thin (no separate audit-log or process-listing tool), but each tool earns its place.
exec covers the core domain (running bash/git commands with output capture, exit codes, policy enforcement), and the diagnostics cover setup, environment, and policy questions. Minor gaps remain, such as no dedicated tool to read the audit log or inspect queued/running commands (those exist only as external CLI/status fields).
Maintenance
Related MCP Connectors
Operate Linux, macOS and Windows from your LLM. Every action runs through an auditable allowlist.
Scoped agent execution. Server-side credentials, policy, budgets and verifiable receipts.
Supervised API-write gateway for AI agents with policy, human approval and execution receipts.
Fail-closed policy guardrails for AI agents running kubectl, terraform, helm, and argocd.
Related MCP Servers
- AlicenseAqualityBmaintenanceEnables secure command-line interactions on Windows systems with support for PowerShell, CMD, Git Bash, and WSL shells, providing controlled file access, command execution, and configurable security restrictions.637 npm4MIT

Capsule Bash Serverofficial
AlicenseAqualityFmaintenanceSandboxed Bash for Agents. Full state capture on every command.34 npm15Apache 2.0- FlicenseNot gradedqualityCmaintenanceSecure localhost MCP gateway that exposes project-scoped file/Git/search tools and controlled CLI agent adapters (Codex, Claude) with fixed argv for safe Windows-native agent work.-
- AlicenseAqualityDmaintenanceSandboxed bash execution MCP server for AI agents, using an in-memory virtual filesystem overlay to prevent real filesystem damage, with configurable network access, timeouts, and optional Python/JS runtimes.962 npmApache 2.0