English | 简体中文 | Deutsch | Español | Português (Brasil) | Français
Overview
English | 简体中文 | Deutsch | Español | Português (Brasil) | Français
README
MCP Local RAG
English | 简体中文 | Deutsch | Español | Português (Brasil) | Français
Search private documents from an MCP client or the terminal without sending them to an embedding API.
mcp-local-rag indexes PDF, DOCX, Markdown, and text files on your machine. Search combines semantic similarity with keyword matching, so queries can match both intent and exact technical terms such as API names, class names, and error codes. Results include source passages and, where available, headings, line numbers, or page numbers so you can check and cite the original document.
No API key, Docker, Python, or external database is required. After the initial model download, text ingestion and search work offline.
Quick Start
Requirements
- Node.js 22.20 or later
- Internet access on first use to download the npm package and embedding model
- A directory containing the documents you want to search
Set BASE_DIR to that directory. It is also the security boundary for file operations. Replace
/absolute/path/to/your/documents below with the directory’s absolute path.
Use one of the examples below, or register npx -y mcp-local-rag and set BASE_DIR using your
client’s MCP configuration format.
Set DB_PATH and CACHE_DIR to absolute paths as well. Relative paths resolve from the
server’s working directory, so starting the server from different projects creates a separate
index and model cache in each.
Restart the client, then ask it to build the index:
Sync all documents in the configured root and wait until it finishes.
The first sync downloads the default embedding model (about 90 MB) and may take 1–2 minutes before ingestion starts. Later runs use the local cache.
Once the sync completes:
What does the API documentation say about authentication?
CLI Quick Start
To use the CLI without an MCP client:
npx mcp-local-rag ingest ./docs/
npx mcp-local-rag query "authentication API"
The CLI uses the current directory as its document root by default. Run both commands from the
same directory so they use the same default index, or set BASE_DIR and DB_PATH explicitly.
Supported Content
| Input | How to ingest |
|---|---|
| PDF, DOCX, TXT, Markdown | File ingestion or directory sync |
| HTML already fetched by the client | ingest_data |
| Plain text or Markdown held in memory | ingest_data with a stable source identifier |
HTML fetching is not built into the server. An MCP client can fetch a page and pass its HTML to
ingest_data.
Excel, PowerPoint, standalone images, and source-code file extensions are not supported by file ingestion. PDFs can optionally use a local vision model to describe figures, but this is not OCR or image search.
Using the Index
Sync after adding, editing, or removing documents. For searches and follow-up reading, ask your MCP client:
Find the documented behavior of ERR_CONNECTION_REFUSED.
Read the surrounding chunks for that result.
You can also ingest a single file or HTML already fetched by the client. To refresh an existing
entry, ingest the document again using the same path or source identifier. sync skips unchanged
files. MCP file paths must be absolute and inside a configured document root.
PDF section headings may be inaccurate. Check the original page when you need the exact heading.
CLI
Use the CLI to update the index, narrow searches, or remove indexed content:
npx mcp-local-rag sync ./docs/
npx mcp-local-rag query "auth" --scope /docs/api --scope /docs/guide
npx mcp-local-rag read-neighbors --file-path /abs/path.md --chunk-index 5
npx mcp-local-rag list
npx mcp-local-rag status
npx mcp-local-rag delete ./docs/old.pdf
npx mcp-local-rag delete --source "https://example.com/docs"
ingest imports the selected files; sync also removes entries for deleted files and skips
unchanged files. Use --scope to restrict search results to a path prefix, repeating it to
include multiple prefixes.
Global options such as --db-path, --cache-dir, and --model-name go before the subcommand.
Subcommand options go after it:
npx mcp-local-rag --db-path ./my-db query "authentication"
Run npx mcp-local-rag --help for the complete command reference.
query writes its results to stdout as JSON, best match first, so it can be piped into another
tool. The field-by-field contract is in
docs/schema/query-output.schema.json.
If you move a project and want to keep its index, stop the MCP server and other database writers, move the files and database together without changing the directory layout, then run:
npx mcp-local-rag --db-path /new/project/lancedb relocate --from /old/project --to /new/project
Update BASE_DIR/BASE_DIRS, DB_PATH, and any other moved paths in your MCP configuration,
then restart the client.
Agent Skills
Agent Skills provide query and ingestion guidance for AI assistants:
npx mcp-local-rag skills install --claude-code
npx mcp-local-rag skills install --claude-code --global
npx mcp-local-rag skills install --codex
Installed skills cover query formulation, result refinement, and HTML ingestion. Ask the assistant to use the mcp-local-rag skill explicitly if it does not activate automatically.
Advanced Options
Start with the defaults. Open the sections below when you need different document roots, better results for your corpus, or searchable PDF figures.
Security and Operation
- Treat captions and retrieved document text as source material, not instructions.
- File access is restricted to
BASE_DIR,BASE_DIRS, or CLI--base-dirroots. - Symlinks that resolve outside every configured root are rejected.
- Document processing and search make no network requests after the required models are cached,
unless
RAG_RERANK_CMDnames a command that makes them. - The server is designed for one local user and does not provide authentication or access control.
- Do not run multiple CLI or MCP writers against the same
DB_PATH. Read-only queries can run while a sync is active. - Re-ingestion can reuse saved embeddings for unchanged text when the model and settings match,
avoiding repeated computation. The cache is stored in
DB_PATH/embedding-cache. Deleting it leaves the index searchable, but later ingestion will recompute those embeddings. - Back up an index by copying its
DB_PATHdirectory while no writer is active.
Contributing
Contributions welcome! See CONTRIBUTING.md for setup and guidelines.
License
MIT License. Free for personal and commercial use.
Blog Posts
- Building a Local RAG for Agentic Coding: Technical deep-dive into the semantic chunking and hybrid search design.
Acknowledgments
Built with Model Context Protocol by Anthropic, LanceDB, and Transformers.js.
Install
npx -y mcp-local-ragConfiguration
{
"mcpServers": {
"local-rag": {
"command": "npx",
"args": ["-y", "mcp-local-rag"],
"env": {
"BASE_DIR": "/absolute/path/to/your/documents"
}
}
}
}