AutoPatch MCP Server
AutoPatch is a self-healing debugging agent that runs a repo's tests, retrieves similar past fixes from its git history, proposes and applies function-level patches, and re-tests until the suite passes. It exposes this loop as MCP tools for clients like Claude Desktop and Cursor.
README
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.
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).
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.