Created
April 4, 2026 03:07
-
-
Save hed0rah/c197802621d5706b99be83c6f8fef1a8 to your computer and use it in GitHub Desktop.
Windows git bash SSE MCP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "mcpServers": { | |
| "windows_gitbash_mcp": { | |
| "url": "http://127.0.0.1:3001/sse" | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import asyncio | |
| import sys | |
| from pathlib import Path | |
| from fastmcp import FastMCP | |
| # Resolve project root | |
| ROOT = Path.cwd().resolve() | |
| def to_gitbash_path(p: Path) -> str: | |
| """Convert Windows path (C:\\foo\\bar) -> Git Bash path (/c/foo/bar)""" | |
| drive = p.drive[0].lower() | |
| rest = str(p).replace("\\", "/")[2:] | |
| return f"/{drive}{rest}" | |
| ROOT_BASH = to_gitbash_path(ROOT) | |
| app = FastMCP("windows_gitbash_mcp") | |
| @app.tool() | |
| async def run_command(command: str) -> str: | |
| """Run a shell command inside Git Bash from project root.""" | |
| try: | |
| full_cmd = f"cd {ROOT_BASH} && {command}" | |
| proc = await asyncio.create_subprocess_exec( | |
| r"C:\Program Files\Git\usr\bin\bash.exe", | |
| "-c", | |
| full_cmd, | |
| stdout=asyncio.subprocess.PIPE, | |
| stderr=asyncio.subprocess.PIPE, | |
| ) | |
| try: | |
| stdout, stderr = await asyncio.wait_for(proc.communicate(), timeout=120) | |
| except asyncio.TimeoutError: | |
| proc.kill() | |
| await proc.wait() | |
| return "ERROR: command timed out (120s)" | |
| stdout_text = stdout.decode("utf-8", errors="replace") | |
| stderr_text = stderr.decode("utf-8", errors="replace") | |
| # Log to stderr only (stdout is the MCP transport channel) | |
| if stdout_text: | |
| print(stdout_text, file=sys.stderr, flush=True) | |
| output = f"exit={proc.returncode}\n" | |
| if stdout_text: | |
| output += stdout_text | |
| if stderr_text: | |
| output += stderr_text | |
| return output.strip() | |
| except Exception as e: | |
| return f"ERROR: {e}" | |
| if __name__ == "__main__": | |
| app.run(transport="sse", host="127.0.0.1", port=3001) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment