
Mcp Local Rag
io.github.shinpr由 GitHub 帳號 shinpr 發布v0.23.2更新於 Nov 5, 2026
Easy-to-setup local RAG server with minimal configuration
概覽
本機 RAG 伺服器,為電腦上的 PDF、DOCX、Markdown 與文字檔建立索引,讓助理以語意加關鍵字的混合檢索查找內容,不需呼叫嵌入 API。
- 可以做什麼
- 同步、匯入與刪除文件:依設定的根目錄或單一路徑對齊索引,匯入或取代單一檔案,匯入用戶端已取得的文字、Markdown 或 HTML,並刪除已索引項目
- 檢索文件:語意相似度結合關鍵字加權,可依距離、檔案數量或分組方式篩選結果
- 讀取檢索結果前後的相鄰分塊,並列出支援的檔案及其匯入狀態
- 查看索引與檢索狀態,輪詢執行中的同步工作
- 透過命令列執行相同操作,查詢結果以 JSON 輸出
- 適用情境
- 適合讓助理根據私有或本機文件集(例如 API 文件、規格、筆記)回答問題,並希望檢索留在本機、不經過託管的嵌入服務。也適合需要回溯原文段落、標題、行號或頁碼作為引用依據的情境。
- 執行需求
- 透過 npx 在本機執行,需要 Node.js 22.20 或更新版本。首次使用需連網下載 npm 套件與嵌入模型(預設約 90 MB),之後可離線使用快取。需設定 BASE_DIR 或 BASE_DIRS 指定文件根目錄,建議將 DB_PATH 與 CACHE_DIR 設為絕對路徑。不需 API 金鑰、Docker、Python 或外部資料庫。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Mcp Local Rag,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
[MCP Local RAG: Search below the surface.]
MCP Local RAG
[GitHub stars] [npm version] [License: MIT] [MCP Registry]
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.
Claude Code
Run this command:
Codex
Add to ~/.codex/config.toml:
OpenCode
Add to ~/.config/opencode/opencode.json (or opencode.jsonc):
Cursor
Add to ~/.cursor/mcp.json:
Restart the client, then ask it to build the index:
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:
CLI Quick Start
To use the CLI without an MCP client:
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
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:
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.
MCP Tools
CLI
Use the CLI to update the index, narrow searches, or remove indexed content:
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:
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:
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:
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.
Storage and Document Roots
The MCP server reads environment variables. The CLI accepts the listed variables and flags.
Keep the same DB_PATH when commands should use the same index.
File operations stay within configured roots. For multiple directories, set
BASE_DIRS='["/absolute/docs","/absolute/specs"]' or repeat CLI --base-dir. Precedence: CLI
roots, BASE_DIRS, BASE_DIR, then the current directory. Only the highest-priority source is
used; roots from different sources are not merged. Invalid BASE_DIRS is an error. Relative
DB_PATH and CACHE_DIR are resolved from the working directory.
To keep files out of the index, set IGNORE_PATHS to a JSON array of glob patterns, for example
IGNORE_PATHS='["plugs/**","**/*.draft.md"]'. Each pattern is matched against the file's path
relative to the root that contains it, written with / on every OS. * and ** do not match
names that start with ., so write such directories out, as in ".obsidian/**". ingest,
list, and sync skip matching files when they scan a directory, and sync removes any that
are already indexed. Invalid IGNORE_PATHS is an error.
Models and Search Tuning
Choose an embedding model for your documents’ language and subject. Compare settings using questions you actually ask and check which source passages are returned. The model must support mean pooling and L2 normalization, which this tool uses to produce embeddings.
Both prefix options default to false and work independently. Try EMBED_TITLE_PREFIX when a
passage needs the document’s overall topic, or EMBED_HEADING_PREFIX when it needs its
section’s topic. Enabling both is not always better. They affect embeddings, not the returned
text or keyword index; heading context is omitted when it would exceed the input budget.
When changing embedding models, build a fresh index at a new DB_PATH. Vectors from different
models are not comparable, even when their dimensions match. After changing RAG_DTYPE or
either prefix option, re-ingest all indexed documents before searching. sync skips unchanged
files.
The CLI does not read MCP client configuration. When sharing an index, use the same model,
RAG_DTYPE, and prefix settings for ingestion and search. A change to RAG_DEVICE alone does
not require a new index.
Search Tuning
The first four settings below apply to both MCP and CLI queries. To give exact terms more
weight, try increasing RAG_HYBRID_WEIGHT and compare results on your own questions. External
reranking is MCP-only.
External Reranking (RAG_RERANK_CMD)
The command reads search results, including matched text, from stdin. If it calls a remote service, that text may leave your machine.
Give the executable and its complete argument template. Put {query} and {top} where the
command expects the query and result count. Single or double quotes group paths or arguments
containing spaces, and backslashes stay literal. The server runs the executable without a
shell, so an npm-installed .cmd shim on Windows will not start.
The command must read and return results in the format defined by the query output schema. It can remove or reorder results and modify their text. The server returns its output.
Results keep their original order if the command fails, times out, or returns output that does not match the schema.
PDF Figures and Stored Images
By default, ingestion indexes only text. To make PDF figures searchable, enable local caption
generation with visual: true in MCP or --visual in the CLI. Captions are generated
descriptions, not OCR or exact transcriptions.
fast (default) downloads about 250 MB on first use. Choose quality for labels and text
within figures; it downloads about 1.7 GB and takes longer to run.
Select the profile with visualQuality: "quality" in MCP or --visual-quality quality in the
CLI.
To return images with matching text, use STORE_IMAGES=true in MCP or --images with CLI
ingest and sync. This is independent of caption generation and supports detected PDF
figures/tables and supported DOCX PNG/JPEG images.
Sync preserves each PDF's caption profile. CLI sync --visual --visual-quality quality changes
the profile even for unchanged PDFs; MCP sync preserves it. To turn captions off, ingest the
file normally. To retry failed captions, re-ingest with the desired visual profile.
Image storage must be enabled on each ingestion or sync that processes the file. Changing the image setting alone does not refresh unchanged files; re-ingest them to apply it.
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.
Troubleshooting
"No results found"
Documents must be ingested first. Run "List all ingested files" to verify. If results are
missing after a sync, check that ingestion and search use the same absolute DB_PATH; a
relative path may point to a different index.
Model download failed
Check internet connection. If behind a proxy, configure network settings. The model can also be downloaded manually.
"File too large"
Default limit is 100MB. Split large files or increase MAX_FILE_SIZE.
Slow queries
Check chunk count with status. Large documents with many chunks may slow queries. Consider
splitting very large files.
"Path outside BASE_DIR"
Ensure file paths are within one of the configured roots (BASE_DIR, any BASE_DIRS entry, or
any CLI --base-dir). Use absolute paths.
"BASE_DIRS must be a JSON array..."
BASE_DIRS accepts a JSON array of one or more non-empty path strings:
- Valid:
BASE_DIRS='["/Users/me/work","/Users/me/specs"]' - Invalid:
BASE_DIRS=/a:/b(delimiter syntax not supported) - Invalid:
BASE_DIRS='[]'(empty array)
MCP client doesn't see tools
- Verify config file syntax
- Restart client completely (Cmd+Q on Mac for Cursor)
- Test directly:
npx mcp-local-ragshould run without errors
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.
來源:README.md,提交 bafba24
工具
0版本歷史
15- v0.23.2最新Nov 5, 2026
- v0.23.1Oct 22, 2026
- v0.23.0Oct 21, 2026
- v0.22.1Oct 14, 2026
- v0.22.0Oct 14, 2026
- v0.21.3Oct 10, 2026
- v0.21.2Oct 10, 2026
- v0.21.1Oct 7, 2026
- v0.21.0Oct 3, 2026
- v0.20.1Oct 2, 2026
- v0.20.0Oct 1, 2026
- v0.19.1Sep 23, 2026
- v0.19.0Sep 20, 2026
- v0.18.6Sep 18, 2026
- v0.18.5Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分