DocsRagMcp 0.1.0

{
  "inputs": [
    {
      "type": "pickString",
      "id": "DOCSRAG_PROVIDER",
      "description": "Embedding provider: ollama (default), openai or azure.",
      "default": "ollama",
      "options": ["ollama", "openai", "azure"]
    },
    {
      "type": "promptString",
      "id": "DOCSRAG_MODEL",
      "description": "Embedding model, or the deployment name for Azure OpenAI. Defaults to nomic-embed-text (Ollama) or text-embedding-3-small (OpenAI)."
    },
    {
      "type": "promptString",
      "id": "DOCSRAG_ENDPOINT",
      "description": "Service URL. Required for Azure OpenAI; optional for Ollama (http://localhost:11434) and OpenAI-compatible APIs."
    },
    {
      "type": "promptString",
      "id": "DOCSRAG_API_KEY",
      "description": "API key for OpenAI or Azure OpenAI. Leave it out for Azure to sign in with Microsoft Entra ID.",
      "password": true
    },
    {
      "type": "promptString",
      "id": "DOCSRAG_ALLOWED_PATHS",
      "description": "Folders the server may index, separated by ; on Windows or : on macOS and Linux."
    },
    {
      "type": "promptString",
      "id": "DOCSRAG_DATABASE",
      "description": "Path of the SQLite index file. Defaults to ~/.docs-rag-mcp/index.db."
    }
  ],
  "servers": {
    "DocsRagMcp": {
      "type": "stdio",
      "command": "dnx",
      "args": ["DocsRagMcp@0.1.0", "--yes"],
      "env": {
        "DOCSRAG_PROVIDER": "${input:DOCSRAG_PROVIDER}",
        "DOCSRAG_MODEL": "${input:DOCSRAG_MODEL}",
        "DOCSRAG_ENDPOINT": "${input:DOCSRAG_ENDPOINT}",
        "DOCSRAG_API_KEY": "${input:DOCSRAG_API_KEY}",
        "DOCSRAG_ALLOWED_PATHS": "${input:DOCSRAG_ALLOWED_PATHS}",
        "DOCSRAG_DATABASE": "${input:DOCSRAG_DATABASE}"
      }
    }
  }
}
                    
This package contains an MCP Server. The server can be used in VS Code by copying the generated JSON to your VS Code workspace's .vscode/mcp.json settings file.
dotnet tool install --global DocsRagMcp --version 0.1.0
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local DocsRagMcp --version 0.1.0
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=DocsRagMcp&version=0.1.0
                    
nuke :add-package DocsRagMcp --version 0.1.0
                    

docs-rag-mcp

CI License: MIT .NET 10 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 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
  • Cites its sources: every passage comes with its file path and heading or PDF page
  • 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 / .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:

<details open> <summary><b>Claude Desktop</b></summary>

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"
      }
    }
  }
}

</details>

<details> <summary><b>VS Code (GitHub Copilot)</b></summary>

In .vscode/mcp.json:

{
  "servers": {
    "docs-rag": {
      "type": "stdio",
      "command": "dnx",
      "args": ["DocsRagMcp", "--yes"],
      "env": {
        "DOCSRAG_ALLOWED_PATHS": "${workspaceFolder}"
      }
    }
  }
}

</details>

<details> <summary><b>Cursor</b></summary>

In ~/.cursor/mcp.json, use the same mcpServers block as for Claude Desktop.

</details>

<details> <summary><b>Claude Code</b></summary>

claude mcp add docs-rag -e DOCSRAG_ALLOWED_PATHS=/path/to/your/notes -- dnx DocsRagMcp --yes

</details>

<details> <summary><b>From source</b></summary>

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"].

</details>

Now ask your assistant: "Index my notes in /path/to/your/notes", then ask questions about them.

Tools

Tool What it does
index_folder Indexes the Markdown, text and PDF files in a folder and its subfolders. Unchanged files are skipped and deleted files are removed.
search_docs Returns the passages closest in meaning to a question, with file, section and score. Optional topK (1-20) and folder filter.
list_sources Lists the indexed files with their number of chunks and when they were indexed.
remove_from_index Removes a file, or every file in a folder, from the index. 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.

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

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"
}

Privacy and security

  • With Ollama, documents and questions never leave your machine.
  • The server only reads your files. The only file it writes is the index.
  • Set DOCSRAG_ALLOWED_PATHS so an assistant can't index folders you didn't intend, such as your home folder. Paths are resolved before they are checked, so docs/../secrets doesn't get around it.
  • Hidden folders (.git, .ssh, ...), symbolic links and node_modules, bin and obj folders are skipped.
  • An index remembers which embedding model built it. Searching it with a different model is refused instead of silently returning wrong results.

Design notes

  • Chunking follows the document's structure. Markdown is split at headings and PDFs by page before being cut into chunks, so every passage knows where it came from. Chunks break at paragraph boundaries when they can, and overlap a little so an idea that spans two chunks can still be found.
  • Each chunk is embedded with its context. The text sent to the embedding model starts with the file name and heading (for example travel-and-expenses.md > Hotels). A short passage like "220 EUR in Paris" then still matches a question about hotel budgets.
  • Brute-force cosine search over SQLite. Vectors are stored as blobs and compared with TensorPrimitives.CosineSimilarity, which uses SIMD. For personal and team document sets (up to tens of thousands of chunks) this stays fast and needs no native vector extension. A vector index is on the roadmap for larger sets.
  • Content hashes make re-indexing cheap. Each file's SHA-256 is stored, so running index_folder again only calls the embedding model for files that changed.
  • Provider-agnostic. The server depends only on IEmbeddingGenerator from Microsoft.Extensions.AI. Supporting another provider means changing one factory class.

Development

dotnet build
dotnet test

The tests use a deterministic fake embedding model, so they need no network. Two of them start the real server process and talk to it over MCP, the way an assistant does.

To check everything against a real model (Ollama by default):

dotnet run samples/smoke.cs -- "How much can I spend on a hotel in Paris?"
src/DocsRagMcp/
  Program.cs                  host, dependency injection, MCP server setup
  DocsRagOptions.cs           settings and validation
  Tools/DocsTools.cs          the four MCP tools
  Indexing/DocumentIndexer.cs folder sync: hash, read, chunk, embed, store
  Indexing/PathGuard.cs       allowed-folder checks
  Ingestion/DocumentReader.cs Markdown, text and PDF reading
  Ingestion/TextChunker.cs    chunking with overlap
  Storage/ChunkStore.cs       SQLite storage and vector search
  Embeddings/                 Ollama, OpenAI and Azure OpenAI clients
tests/DocsRagMcp.Tests/       unit and end-to-end tests
samples/                      sample documents and the smoke test

Roadmap

  • Word (.docx) and HTML files
  • Hybrid search that combines keyword (SQLite FTS5) and vector scores
  • A vector index for very large document sets
  • Exposing indexed files as MCP resources

Contributions are welcome. Open an issue to discuss an idea first.

License

MIT

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last Updated
0.1.0 48 11/23/2026