Build a Codebase Intelligence Tool Like repowise With a RAG-Assisted MCP for Your Monorepo A developer has created a RAG-assisted Model Context Protocol (MCP) server that turns a monorepo into a queryable knowledge base, enabling semantic code search for LLMs and CLI tools. The system uses tree-sitter for AST-aware chunking, a local embedding server with sentence-transformers, and a hybrid retriever combining vector similarity with BM25 lexical search. The tutorial details building three components: an indexer, an MCP server, and a retriever, with a file watcher for incremental updates. Originally published on tamiz.pro. Modern monorepos contain hundreds of thousands of files spanning multiple services, libraries, and configurations. Traditional code search—whether ripgrep, Sourcegraph, or IDE search—struggles with semantic queries like "how do we handle payment retries?" or "find all places where user permissions are checked" . A RAG-assisted Model Context Protocol MCP server can turn your local codebase into a queryable knowledge base, giving LLMs and CLI tools accurate, context-rich answers. This tutorial shows you how to build a production-grade version of tools like repowise https://repowise.dev for your own monorepo. We'll build three components: ┌─────────────┐ ┌──────────────┐ ┌─────────────┐ │ File Watcher│────▶│ Indexer │────▶│ Vector Store│ │ chokidar │ │ LangChain │ │ Qdrant │ └─────────────┘ └──────────────┘ └─────────────┘ │ ▼ ┌─────────────┐ ┌──────────────┐ ┌─────────────┐ │ IDE / CLI │◀────│ MCP Server │◀────│ Retriever │ │ Claude, │ │ FastMCP │ │ Hybrid │ │ Cursor │ └──────────────┘ └─────────────┘ └─────────────┘ Indexer : Splits code into AST-aware chunks, embeds them, and stores them in a local vector database. MCP Server : Exposes a standardized interface tools, resources, prompts that any MCP-compatible client can consume. Retriever : Combines vector similarity with BM25 lexical search and AST context for precise retrieval. Initialize the project structure: mkdir monorepo-rag-mcp && cd monorepo-rag-mcp pnpm init mkdir -p packages/{indexer,mcp-server,embedding-server} Create a shared package for common types: // packages/shared/src/types.ts export interface CodeChunk { id: string; path: string; language: string; startLine: number; endLine: number; content: string; astMetadata?: Record