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
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。