Codebase Copilot MCP Server
Exposes code search and file reading tools over the Model Context Protocol, enabling any MCP-compatible client to query a codebase with natural language.
README
Codebase Copilot
An AI coding assistant built from scratch to learn and demonstrate four core building blocks of modern AI systems: RAG, Agents, MCP, and Multi-Agent orchestration — applied to a real codebase (tqdm).
Instead of using a framework that hides how these systems work, every layer here is built manually in plain Python, so the internals are fully understood, debugged, and explainable.
What it does
Point it at a codebase (tqdm, in this case) and ask questions like "what is the tqdm class and how does its update method work?" — it retrieves the relevant code, reasons about what it needs, and generates an accurate, grounded answer.
Architecture — four progressive stages
1. RAG (index.py, query.py)
- Parses the codebase using Python's
astmodule, splitting code into meaningful chunks (whole functions/classes, not arbitrary word-count slices) - Embeds each chunk locally using
sentence-transformers - Stores embeddings in a local
ChromaDBvector database - Retrieves the most relevant chunks for a question and generates an answer via the Groq API (
openai/gpt-oss-120b)
Real bug fixed: naive word-count chunking caused the main tqdm class (spread across a large file) to never surface in search results, since no single chunk represented it well. Fixed by switching to AST-based chunking — splitting by function/class boundaries instead, with large classes further split by individual method.
2. Agent (agent.py)
- Gives the model two tools:
search_codeandread_file - The model decides autonomously which tool to use, when, and whether it needs another step before answering — instead of a fixed search-then-answer sequence
- Includes safeguards for real agent failure modes: malformed tool arguments, repeated/looping tool calls, and forced convergence to a final answer within a step budget
3. MCP Server (server.py, test_mcp_client.py)
- Wraps
search_codeandread_fileas a standard Model Context Protocol server, making them accessible to any MCP-compatible client — not just this project's own script - Verified with a custom MCP client that connects over stdio, lists available tools, and calls them successfully against the live database
4. Multi-Agent System (multi_agent.py)
Three specialized agents coordinated by an orchestrator:
- Retriever — searches the codebase (with a targeted secondary search for specific method names)
- Explainer — writes an answer from retrieved context
- Reviewer — checks the answer for accuracy and completeness against the actual context, and can send it back to the Explainer with specific feedback for revision (up to 2 rounds)
Real bug fixed: the Reviewer initially approved an answer that incorrectly claimed information was "missing," when it was actually present in the codebase — the Retriever just hadn't surfaced it. This exposed a real multi-agent design flaw: a Reviewer can only judge consistency with the context it's given, not whether the Retriever gathered the right context in the first place. Fixed by improving retrieval coverage and adding an explicit check in the Reviewer's prompt for this failure pattern.
Tech stack
- Python — core language
- ChromaDB — local vector database
- sentence-transformers (
all-MiniLM-L6-v2) — local embeddings - Groq API (
openai/gpt-oss-120b) — LLM inference - MCP (Model Context Protocol) — standardized tool exposure
Setup
-
Clone this repo and create a virtual environment:
python -m venv venv source venv/bin/activate # Windows: venv\Scripts\activate pip install -r requirements.txt -
Clone tqdm's source into a
repofolder (or pointREPO_PATHinindex.pyat any other small Python codebase):git clone https://github.com/tqdm/tqdm.git repo -
Add a
.envfile with your Groq API key:GROQ_API_KEY=your_key_here -
Build the index:
python index.py -
Try any of the four stages:
python query.py # Week 1: plain RAG python agent.py # Week 2: agent with tools python server.py # Week 3: MCP server (run test_mcp_client.py in a separate terminal to test it) python multi_agent.py # Week 4: multi-agent system
What I learned
Building this project surfaced real engineering problems that don't show up in tutorials:
- Retrieval quality is a hard ceiling on generation quality, no matter how good the LLM is
- Chunking strategy matters more than embedding model choice for code specifically
- Agents need explicit guardrails against looping and malformed tool calls
- A "reviewer" agent is only as good as the context it's reviewing against — multi-agent systems can still fail silently if earlier stages don't surface the right information
Future directions
- Smarter multi-agent flow where the Reviewer's feedback can trigger the Retriever again, not just the Explainer
- Swap the local embedding model for a larger hosted one (e.g. Voyage AI) to compare retrieval quality
- Extend to support editing code, not just answering questions about it
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.
Neon Database
MCP server for interacting with Neon Management API and databases
E2B
Using MCP to run code via e2b.
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.