I Exposed My Local RAG as MCP Tools in Cursor — Now I Query My Private PDFs Without Leaving the IDE
From the publisher’s feed, collected in the ZeroLabs newsroom.
Across my first two articles, I built a fully local RAG pipeline on my laptop — Ollama, ChromaDB, and TinyLlama for private PDF Q&A — then improved how documents are split by moving from fixed-size chunking to recursive chunking with overlap.Both projects worked well from the terminal. I could ingest a document and ask questions. But I kept running into the same friction:I had to leave my editor, open a terminal, copy questions back and forth, and remember which commands to run.That led me to my next experiment: expose the same RAG pipeline as an MCP server so Cursor can query my private documents as tools — while also trying a different local embedding model, all-MiniLM-L6-v2, instead of Ollama for search vectors.This article is about what I built, how MCP fits in, and what changed when embeddings moved from Ollama to sentence-transformers.What is MCP, in plain English?MCP stands for Model Context Protocol.Think of it like a standard plug for AI tools. Instead of every app inventing its own way to call your code, MCP gives assistants like Cursor a consistent way to discover and invoke tools you define — search a database, read a file, call your RAG pipeline.For this project, MCP is the bridge between:Cursor chat — where you ask questions in natural languageYour local RAG code — ingest, search, and answer from your own indexed PDFsYou still own the data. It still runs on your machine. Cursor just gets a clean way to call it.Why I cared about thisMy earlier RAG demos were CLI-first. That is great for learning. It is less great when you are already inside an IDE and want answers from an internal PDF without context switching.I wanted three things:Keep everything local — no cloud API, no documents leaving my laptopReuse my RAG logic — not a rewrite, just a new entry pointLearn MCP hands-on — a practical step toward agent-style workflowsSo I built a third project that adds:A shared service layer (rag/service.py) used by both CLI and MCPAn MCP server (mcp_server.py) with three toolsMiniLM embeddings via Hugging Face instead of Ollama nomic-embed-textSame recursive chunking. Same ChromaDB. Same llama3 for answers. New interfaces and a new embedding path.What changed from my earlier RAG projectsImportant: do not reuse an old .chroma/ folder when you switch embedding models. Different models produce different vector sizes. Mixing them breaks search.Two models, two jobs (plus MCP)A common point of confusion in RAG: you usually need more than one model.1. Embedding model — all-MiniLM-L6-v2This model does not write answers. It converts text into numbers (vectors) that capture meaning.In my first two projects, I pulled embeddings through Ollama. Here I use sentence-transformers instead:Downloads once from Hugging Face (~80 MB)Runs locally in Python — no Ollama needed for ingest or searchProduces 384-dimensional vectorsFast on CPU for learning-sized documentsWhen you ask “What is the MFA policy?” and your document says “Multi-Factor Authentication must be configured before access is granted”, the embedding model helps the system understand those are related — even when the words differ.2. Chat model — llama3 (Ollama)llama3 is ~8B parameters. It is not GPT-4. For learning and simple Q&A on your own docs, it is enough.It is used only when you want a written answer — CLI ask or MCP ask_documents.3. MCP tools — the new interfaceInstead of typing terminal commands, Cursor can call:That split matters. Search is fast and great for debugging retrieval. Ask adds the LLM on top.A real example: search vs askSuppose I indexed an internal monthly expense PDF and asked:“What is highest expense in month of March-2026?”Step 1 — search_documents (retrieval only)The tool returns the top chunks with source file, chunk index, and a short excerpt. I can verify retrieval found the right section — without trusting an LLM summary.Step 2 — ask_documents (full RAG)The same question goes through retrieval, then llama3 writes an answer grounded in those chunks. I also get source excerpts so I can spot when the small model adds extra detail not in the text.That workflow taught me something my earlier CLI-only projects did not surface as clearly: always look at retrieved chunks before blaming the model.The architecture I builtI kept the pipeline small and added a shared service layer plus MCP on top.How the pipeline worksStep 1: Ingest a document (CLI)Document (.txt or .pdf) → extract text → recursive split with overlap → MiniLM embed → store in ChromaDBI use ~500-character chunks with 50-character overlap — same tuning as my chunking article. First ingest downloads MiniLM automatically.Ollama is not required for this step.Step 2: Preview or search (optional, no LLM)Preview: see how a file splits before embedding anythingpython main.py preview data/monthly-expense-data.pdfSearch: test retrieval without calling llama3.python main.py search "What is a total expense in a month of March- 2026?"From Cursor, the same idea is:Use search_documents "Give me highest expense in month of January?"Step 3: Ask a question (CLI or MCP)Question → MiniLM embed → top-K similarity search → prompt llama3 → answer + sourcesCLI:python main.py ask "What MCP tools are available?" --show-sourcesCursor:Use ask_documents: "What MCP tools are available?"Step 4: Connect MCP in CursorIngest at least one document via CLI firstAdd the server to ~/.cursor/mcp.jsonRestart CursorCall rag_status, search_documents, or ask_documents from chatThe Core CodeEmbeddings with MiniLMThe main embedding change is in rag/embedder.py:from sentence_transformers import SentenceTransformerfrom rag.config import EMBED_MODEL_model = Nonedef _get_model() -> SentenceTransformer: global _model if _model is None: _model = SentenceTransformer(EMBED_MODEL) return _modeldef embed_texts(texts: list[str]) -> list[list[float]]: if not texts: return [] model = _get_model() vectors = model.encode(texts, convert_to_numpy=True, show_progress_bar=False) return vectors.tolist()Model name and chunk settings live in one place — rag/config.py:EMBED_MODEL = "all-MiniLM-L6-v2"LLM_MODEL = "llama3"CHUNK_SIZE = 500CHUNK_OVERLAP = 50TOP_K = 4MCP tools with FastMCPThe MCP server reuses the same service functions as the CLI:from mcp.server.fastmcp import FastMCPfrom rag import servicemcp = FastMCP("local-rag-mcp-minilm")@mcp.tool()def search_documents(question: str, top_k: int = 4) -> dict: """Search indexed documents and return matching chunks (no LLM answer).""" result = service.search_documents(question, top_k=top_k) return {"ok": True, **result}@mcp.tool()def ask_documents(question: str, top_k: int = 4) -> dict: """Ask a question and get an answer grounded in indexed documents.""" result = service.ask_documents(question, top_k=top_k) return {"ok": True, **result}@mcp.tool()def rag_status() -> dict: """Return how many chunks are indexed and which source files exist.""" result = service.get_index_status() return {"ok": True, **result}Roughly 50 lines of MCP wiring on top of RAG code I already understood. That was the surprise — MCP felt abstract until I mapped three CLI operations to three tools.Cursor MCP configAdd this to ~/.cursor/mcp.json (adjust paths for your machine):{ "mcpServers": { "local-rag-mcp-minilm": { "command": "C:\\path\\to\\local-rag-mcp-minilm\\.venv\\Scripts\\python.exe", "args": ["C:\\path\\to\\local-rag-mcp-minilm\\mcp_server.py"] } }}Restart Cursor. The tools show up in chat.What the CLI looks likeThe app is still command-line driven for ingest and testing:# Preview how a document is split (no model download needed)python main.py preview data/monthly-expense-data.txt# Index a text or PDF file (downloads MiniLM on first run)python main.py ingest data/monthly-expense-data.txt# Search without calling the LLMpython main.py search "Summerize expense for April month?"# Ask a questionpython main.py ask "Summerize expense for April month?"# Show retrieved sources with the answerpython main.py ask "What is recursive chunking?" --show-sources# Check statuspython main.py status# Clear the vector storepython main.py resetThat is it. No web server. No cloud API. MCP is an extra entry point — not a replacement for the CLI while learning.Project structureI organized the code into small, focused modules:local-rag-mcp-minilm/├── main.py # CLI: ingest, preview, search, ask, status, reset├── mcp_server.py # FastMCP tools for Cursor├── requirements.txt├── README.md├── docs/│ └── architecture.md # Diagrams and pipeline breakdown├── rag/│ ├── config.py # models, chunk size, overlap, top_k│ ├── chunker.py # RecursiveCharacterTextSplitter│ ├── document_loader.py # .txt and .pdf support│ ├── embedder.py # all-MiniLM-L6-v2│ ├── vector_store.py # ChromaDB│ ├── query.py # Retrieve + generate + source excerpts│ └── service.py # Shared logic for CLI + MCP├── examples/│ └── cursor-mcp.json # MCP config snippet└── data/ └── monthly-expense-data.pdf # Demo documentEach file has one responsibility. The service.py layer is the key design choice — CLI and MCP both call the same functions, so behavior stays in sync.What I learned building thisMCP is simpler than the hype suggests. If you already have working functions, tools are mostly wrappers with descriptions. Start with read-only tools like search_documents and rag_status.Search and ask are different products. Exposing both as MCP tools made retrieval debugging much easier. Search shows what the index actually found. Ask adds LLM synthesis on top.Small LLMs need source checking. TinyLlama sometimes smooths or blends details. Returning source excerpts alongside answers (--show-sources / MCP JSON) helped me trust the pipeline more.Embedding model choice is a fresh index. Switching from Ollama embeddings to MiniLM meant re-ingesting documents. That is expected — not a bug.Who is this for?This kind of project is great if you are:Building on local RAG from my earlier articlesLearning MCP with a real project, not a hello-world onlyExploring sentence-transformers as an alternative to Ollama embeddingsUsing Cursor and want your private docs callable as toolsPreparing for interviews where RAG, embeddings, and tool calling come upYou do not need a GPU farm. You need Python, Ollama (for ask only), and at least one document to index.What is next?From here, the natural extensions in this series are:Hybrid RAG — combine keyword search (BM25) with vector similarityIngest via MCP — with path allowlists for safetyConversation memory — multi-turn questions across chat sessionsStronger local chat model — swap TinyLlama for phi3:mini or similarSource-first answers — return chunks only unless the user explicitly asks for synthesisBut even in its current form, this project already shows the core lesson: your RAG pipeline can be a tool, not just a script.Final thoughtMy first RAG article taught me the loop — ingest, embed, retrieve, generate.My second taught me that retrieval quality starts with chunking.This one taught me that once the loop works, the next step is making it callable — from your IDE, through MCP, on your own machine, on your own documents.If you are starting with MCP and RAG together, my advice is the same as before: build the smallest version first. Ingest one PDF. Call rag_status. Run search_documents on one question. Then try ask_documents. Compare the chunks to the answer.That one end-to-end pass teaches more than reading ten protocol diagrams.You can download the complete source code from GitHub: https://github.com/parivshah/local-rag-mcp-minilmThe repository includes setup instructions, architecture diagrams, and an MCP config example. Please let me know if you liked this article or have any questions, feedback, or suggestions. You can connect with me on LinkedIn.I Exposed My Local RAG as MCP Tools in Cursor — Now I Query My Private PDFs Without Leaving the IDE was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.