Skip to main content
Glama
Swastigit2005

AutoPatch MCP Server

AutoPatch — Self-Healing Debugging Agent (MCP Server)

AutoPatch is a closed-loop agent: it runs a repo's tests, and if something fails, it searches that repo's own git history for how a similar bug was fixed before, generates a patch guided by that precedent, applies it, and re-runs the tests — looping until the suite passes or it gives up after a capped number of attempts. It doesn't just answer questions about code, it takes real actions (running pytest, writing files) and reacts to real feedback (test results), which is the core pattern behind current autonomous software-engineering agents (Devin, OpenHands, SWE-agent).

Everything is also exposed as an MCP server, so any MCP client (Claude Desktop, Cursor, a LangGraph agent via langchain-mcp-adapters) can drive the same loop through four tools instead of the Streamlit UI.

Architecture

                 ┌─────────────┐
        ┌───────▶│  run_tests  │◀────────────────┐
        │        └──────┬──────┘                 │
        │           pass │ fail                   │
        │               ▼                        │
        │      ┌───────────────────┐              │
   __END__      │ retrieve_precedent│  ChromaDB over the repo's own
                │  (ChromaDB search) │  git log (commit msgs + diffs)
                └─────────┬──────────┘             │
                          ▼                        │
                 ┌─────────────────┐               │
                 │  propose_patch   │  Groq LLM, function-level fix,
                 │  (Groq + Llama)  │  guided by the retrieved precedent
                 └─────────┬────────┘               │
                          ▼                        │
                 ┌─────────────────┐               │
                 │   apply_patch    │──────────────┘
                 └─────────────────┘

Implemented as a LangGraph StateGraph with a conditional edge that routes back into the loop on failure (capped at MAX_PATCH_ITERATIONS) and out to END on success.

Related MCP server: knownissue

Why function-level patching, not whole-file rewrites

Early design considered asking the LLM to return the entire corrected file. Rejected: LLMs occasionally truncate or silently drop unrelated functions when asked to reproduce a whole file. Instead, the LLM only ever returns the single corrected function; src/code_surgery.py splices it back into the real file via AST-based function-boundary detection, and the diff shown in the UI is computed with difflib against the actual bytes that get written — what you see is guaranteed to be what's applied.

The demo repo

demo_repo/ is a tiny, real git repository (own history, own commits) with a calculator package. Its git history contains a genuine bug-fix commit: divide() originally divided by (b - 1) instead of b, fixed in a later commit. demo_repo/bug_scenarios/ lets you re-inject that same class of bug (and two others) into the working tree at will, so AutoPatch always has something fresh to heal, and — for the average_offbyone scenario — a real historical precedent to retrieve and learn from.

Setup

git clone <your-repo-url>
cd autopatch
python -m venv venv && source venv/bin/activate
pip install -r requirements.txt

cp .env.example .env
# edit .env: set GROQ_API_KEY (and optionally GROQ_API_KEY_FALLBACK)

python scripts/seed_git_history.py   # builds demo_repo's real git history, once

Running it

Streamlit dashboard (recommended for a live demo):

streamlit run streamlit_app.py

Pick a bug scenario in the sidebar, click "Inject bug," then "Run AutoPatch agent" — watch it test, retrieve, patch, and re-test live.

CLI:

python main.py --scenario average_offbyone

MCP server (stdio transport, for Claude Desktop / Cursor / any MCP client):

python -m src.mcp_server

Add to your MCP client config, e.g. Claude Desktop's claude_desktop_config.json:

{
  "mcpServers": {
    "autopatch": {
      "command": "python",
      "args": ["-m", "src.mcp_server"],
      "cwd": "/path/to/autopatch",
      "env": {"GROQ_API_KEY": "..."}
    }
  }
}

REST API (for non-MCP clients, e.g. a CI webhook):

uvicorn src.rest_api:app --reload
# POST /inject {"bug_id": "average_offbyone"}
# POST /heal

Tests

pytest tests/ -v

test_patcher.py and test_agent_graph.py use a fake Groq client (no API key or network needed); test_executor.py runs the real demo repo's test suite as a subprocess.

Tech stack

Python, LangGraph (cyclic state graph with conditional routing), MCP (FastMCP), ChromaDB (git-history vector index), Groq (Llama 3.3, with automatic fallback to a secondary API key on rate limits), FastAPI, Streamlit, GitPython, pytest, difflib/ast for source-level patching.

Deployment

See render.yaml / Procfile — deploys as a single Render web service running the Streamlit dashboard (the MCP server and REST API run in-process alongside it for the demo; run src.mcp_server separately for real MCP-client integration).

F
license - not found
-
quality - not tested
C
maintenance

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

View all related MCP servers

Related MCP Connectors

  • AI code review for GitHub PRs with an MCP autofix loop for Claude Code and Cursor

  • Shared debugging memory for AI coding agents

  • User-owned memory for AI agents, Copilot, Claude, IDEs, CLIs, and chat apps over remote MCP.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Swastigit2005/Autopatch-MCP-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server