docs-rag-mcp

An MCP server, written in C#, that lets Claude, GitHub Copilot, Cursor and other AI assistants search your own documents with retrieval-augmented generation (RAG).
Point it at a folder of Markdown, text, HTML, Word or PDF files. It splits them into passages, turns each passage into an embedding, and stores everything in a local SQLite file. When you ask your assistant a question, it calls search_docs, gets back the most relevant passages with their file and section, and answers from them.
- Runs fully local with Ollama, or uses OpenAI or Azure OpenAI embeddings
- One file, no database server: the index is a single SQLite file
- Incremental: re-indexing only embeds files that changed, and drops files you deleted
- Stays in sync: indexed folders are watched, so new, edited and deleted files are picked up on their own, even changes made while the server was stopped
- Cites its sources: every passage comes with its file path and heading or PDF page
- Indexed files are MCP resources: clients can list them and attach a whole document to the conversation
- Reads HTML too: saved web pages and generated docs sites are split at their headings, without scripts, styles, menus, headers and footers
- Reads Word documents:
.docx files are split at their Title and Heading 1 to 3 paragraphs, in any language version of Word, with lists and tables kept readable
- Ignores front matter: YAML front matter from Jekyll, Hugo, Docusaurus or Obsidian is left out of the index, and its
title names the text before the first heading
- Hybrid search: ranks by meaning and by keywords, so exact terms such as API names and error codes are found too
- Optional reranking: a cross-encoder model, run locally with llama.cpp or as a service such as Cohere or Jina, can reorder the best passages
- Safe by default for shared machines: you can limit which folders it may read
Example
With the sample handbook indexed, asking "Can I spend a month working from Spain?" returns:
2 passages for "Can I spend a month working from Spain?":
[1] samples/handbook/remote-work.md > Working from another country (score 0.71)
## Working from another country
You can work from another country for up to 30 days a year. Tell your manager and HR
two weeks in advance, because some countries need paperwork for tax and insurance.
[2] samples/handbook/remote-work.md > Remote work (score 0.57)
...
Neither "Spain" nor "month" appears in the document. The search matches on meaning, not keywords.
How it works
flowchart LR
A[AI assistant<br/>Claude, Copilot, Cursor] -- MCP over stdio --> B[docs-rag-mcp]
B -- index_folder --> C[Read .md / .txt / .html / .docx / .pdf<br/>split by heading or page<br/>chunk with overlap]
C --> D[Embedding model<br/>Ollama, OpenAI, Azure OpenAI]
D --> E[(SQLite<br/>chunks + vectors)]
B -- search_docs --> D
E -- cosine similarity, top K --> B
Quick start (local, with Ollama)
You need the .NET 10 SDK and Ollama. Pull the embedding model once:
ollama pull nomic-embed-text
The server is published on NuGet and in the MCP Registry as io.github.Ahmed-Manai/docs-rag-mcp. dnx, which comes with .NET 10, downloads and starts it, so there is nothing else to install. Add it to your assistant in one click:

VS Code asks which folder the server may read. The Cursor button lets it read any folder: to limit it, add DOCSRAG_ALLOWED_PATHS to its entry in ~/.cursor/mcp.json, as shown below.
Or add it by hand:
In claude_desktop_config.json (Settings > Developer > Edit Config):
{
"mcpServers": {
"docs-rag": {
"command": "dnx",
"args": ["DocsRagMcp", "--yes"],
"env": {
"DOCSRAG_ALLOWED_PATHS": "/path/to/your/notes"
}
}
}
}
In .vscode/mcp.json:
{
"servers": {
"docs-rag": {
"type": "stdio",
"command": "dnx",
"args": ["DocsRagMcp", "--yes"],
"env": {
"DOCSRAG_ALLOWED_PATHS": "${workspaceFolder}"
}
}
}
}
In ~/.cursor/mcp.json, use the same mcpServers block as for Claude Desktop.
claude mcp add docs-rag -e DOCSRAG_ALLOWED_PATHS=/path/to/your/notes -- dnx DocsRagMcp --yes
git clone https://github.com/Ahmed-Manai/docs-rag-mcp.git
cd docs-rag-mcp
dotnet build -c Release
Then use "command": "dotnet" with "args": ["run", "--no-build", "-c", "Release", "--project", "/path/to/docs-rag-mcp/src/DocsRagMcp"].
Now ask your assistant: "Index my notes in /path/to/your/notes", then ask questions about them.
Try it on the sample handbook
No documents at hand? The repository comes with a short employee handbook:
git clone https://github.com/Ahmed-Manai/docs-rag-mcp.git
Allow docs-rag-mcp/samples/handbook in DOCSRAG_ALLOWED_PATHS, then ask your assistant:
- "Index the folder /path/to/docs-rag-mcp/samples/handbook"
- "Can I spend a month working from Spain?"
It answers from the "Working from another country" section of remote-work.md, as in the example above.
Tools
| Tool |
What it does |
index_folder |
Indexes the Markdown, text, HTML, Word and PDF files in a folder and its subfolders. Unchanged files are skipped and deleted files are removed. The folder is then watched and kept in sync. |
search_docs |
Returns the passages closest in meaning to a question, with file, section and score. Optional topK (1-20) and folder, which limits the search to part of the index (see below). |
list_sources |
Shows where the index is, its size and the embedding model that built it, then lists the indexed files with their number of chunks and when they were indexed, and the watched folders. |
remove_from_index |
Removes a file, or every file in a folder, from the index, and stops watching the folder. Files on disk are never touched. |
search_docs and list_sources are marked read-only and remove_from_index destructive, so clients can decide when to ask you for confirmation.
Searching part of the index
folder accepts any of these, and only files inside it are scored, both by meaning and by keywords:
- an absolute path of a folder or a single file, such as
/home/me/notes/api
- a resource URI, such as
file:///home/me/notes/api/auth.md
- a path relative to the indexed folders, such as
api/v2: it matches that subfolder in every indexed folder that has one
If no indexed file is inside it, search_docs says so instead of returning unrelated passages.
Resources
Every indexed file is also an MCP resource, so clients that support resources (for example Claude Desktop and VS Code) can list the files and attach a whole document to the conversation, not only the passages search_docs finds.
| Field |
Value |
| URI |
The file's file:// URI, for example file:///home/me/notes/handbook/travel.md or file:///C:/Users/me/notes/handbook/travel.md |
| Name |
The indexed folder and the path inside it, for example handbook/travel.md |
| Content |
Markdown and text files as they are on disk. HTML, Word and PDF files as the text extracted for the index, with PDF pages marked [page 2] |
| MIME type |
text/markdown for Markdown files, text/plain for everything else |
The list follows the index: when files are indexed, changed or removed, the server sends notifications/resources/list_changed.
Only files that are in the index can be read. A file that is not indexed, was deleted, has become a symbolic link (or sits in a folder that has), or is no longer inside DOCSRAG_ALLOWED_PATHS is refused, even if its URI is valid.
Configuration
Settings come from environment variables (or the matching command-line switch, such as --provider).
| Variable |
Default |
Description |
DOCSRAG_PROVIDER |
ollama |
ollama, openai or azure |
DOCSRAG_MODEL |
nomic-embed-text (Ollama), text-embedding-3-small (OpenAI) |
Embedding model, or the deployment name for Azure OpenAI |
DOCSRAG_ENDPOINT |
http://localhost:11434 (Ollama) |
Required for Azure OpenAI. For OpenAI, set it to use any OpenAI-compatible API |
DOCSRAG_API_KEY |
|
OpenAI or Azure OpenAI key. Read from the environment only, never from the command line |
DOCSRAG_ALLOWED_PATHS |
any folder |
Folders the server may index, separated by ; on Windows and : on macOS and Linux |
DOCSRAG_DATABASE |
~/.docs-rag-mcp/index.db |
Where the index is stored |
DOCSRAG_CHUNK_SIZE |
1200 |
Maximum characters per chunk |
DOCSRAG_CHUNK_OVERLAP |
200 |
Characters repeated between consecutive chunks |
DOCSRAG_SEARCH_MODE |
hybrid |
hybrid combines keyword and vector ranking; vector uses vector similarity only |
DOCSRAG_WATCH |
true |
Watch indexed folders and index changes automatically. Set to false to index only when index_folder is called |
DOCSRAG_RERANK_ENDPOINT |
off |
URL of a rerank endpoint, such as http://localhost:8012/v1/rerank. Setting it turns on reranking |
DOCSRAG_RERANK_MODEL |
|
Reranking model, for services that serve several, such as rerank-v3.5 (Cohere) or jina-reranker-v2-base-multilingual (Jina) |
DOCSRAG_RERANK_API_KEY |
|
Key for the rerank service, sent as a bearer token. Read from the environment only, never from the command line |
DOCSRAG_RERANK_CANDIDATES |
20 |
How many of the best passages are sent to the reranker, from 1 to 100. At least topK are always sent |
OpenAI
"env": {
"DOCSRAG_PROVIDER": "openai",
"DOCSRAG_API_KEY": "sk-..."
}
Azure OpenAI
"env": {
"DOCSRAG_PROVIDER": "azure",
"DOCSRAG_ENDPOINT": "https://my-resource.openai.azure.com/",
"DOCSRAG_MODEL": "my-embedding-deployment"
}
Without DOCSRAG_API_KEY, the server signs in with Microsoft Entra ID through DefaultAzureCredential (az login, Visual Studio, managed identity...). Your account needs the Cognitive Services OpenAI User role on the resource.
LM Studio, vLLM and other OpenAI-compatible servers
"env": {
"DOCSRAG_PROVIDER": "openai",
"DOCSRAG_ENDPOINT": "http://localhost:1234/v1",
"DOCSRAG_MODEL": "text-embedding-nomic-embed-text-v1.5"
}
Reranking
Reranking is off by default. When it is on, search_docs first ranks the passages as usual, then sends the best ones (20 by default) with the question to a cross-encoder model, and returns them in the model's order. A cross-encoder reads the question and the passage together, so it can tell which passage actually answers the question better than comparing two embeddings can, but it is too slow to run over the whole index.
docs-rag-mcp calls any endpoint that speaks the /rerank API that Cohere introduced, which Jina, llama.cpp, vLLM, Infinity and LocalAI also use. To stay local, serve a reranking model with llama.cpp:
llama-server -hf gpustack/bge-reranker-v2-m3-GGUF:Q4_K_M --reranking --port 8012 -c 8192 -b 8192 -ub 8192
"env": {
"DOCSRAG_RERANK_ENDPOINT": "http://localhost:8012/v1/rerank"
}
Or use a hosted service: