
Rag Mcp
io.github.jaimenbell由 GitHub 帳號 jaimenbell 發布v0.1.0更新於 Oct 24, 2026
Minimal RAG-over-a-corpus MCP retrieval: search_knowledge returns cited chunks. Local embeddings.
概覽
一個本機 MCP 伺服器,讓助理在預先匯入的 Markdown 語料庫中檢索,並回傳附引用的段落。
- 可以做什麼
- 以查詢、結果數量和可選的文件類別篩選條件檢索本機語料庫,回傳附來源、標題和區塊索引引用的段落。將 Markdown 文件匯入內嵌的 ChromaDB 儲存,預設為增量處理,只重新嵌入內容變更的檔案並清除過期區塊。在依日期命名的快照系列內對重複區塊去重,保留首次出現及其日期。透過命令列對同一儲存執行一次性查詢。
- 適用情境
- 當你希望助理依據自己的本機筆記或文件作答,且能追溯引用來源,同時不想使用付費嵌入 API 或託管向量資料庫時使用。適合可事先匯入並依排程更新的 Markdown 檔案語料庫。
- 執行需求
- 需要本機 Python 環境並從 PyPI 安裝此套件,且在檢索前已將 Markdown 語料庫匯入 ChromaDB 儲存。透過環境變數設定:RAG_MCP_CORPUS_ROOT、RAG_MCP_DB_PATH、RAG_MCP_COLLECTION 和 RAG_MCP_EMBEDDER。嵌入在本機 CPU 上執行,預設模型為 all-MiniLM-L6-v2,可選擇啟用 bge-large-en-v1.5。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Rag Mcp,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
rag-mcp
A minimal, honest RAG-over-a-corpus MCP retrieval tool. One tool,
search_knowledge(query, k, doc_class=None), that embeds a query, vector-searches a local corpus, and returns passages with citations (source + heading + chunk index) so answers are traceable.
Built to slot into the mcp-factory manifest model. Fully local + $0 (no paid embedding API).
Why it's safe to put in front of a real corpus
- Cited - every hit carries
source+heading+chunk_index. - Auth-scoped - results are confined to the configured corpus root; sources that escape it
(absolute paths,
..traversal) are refused. - Fail-soft - a down or empty store returns a structured error, never an exception that crashes the calling agent.
- Bounded -
kis clamped to[1, 20]; empty queries are rejected. - Version-pinned deps (
requirements.txt).
Stack
Protocol revision
Pinned to mcp==2.0.0, the first SDK release implementing MCP protocol revision
2026-07-28. The server serves both eras on the same stdio connection -- the
client's first frame picks:
2026-07-28 is not reachable via the initialize handshake; it is a "modern"
revision reached through server/discover or an inline _meta version stamp. Era
selection is automatic and per-connection -- there is no server-side flag.
tests/test_protocol_version.py asserts both paths end-to-end, so a dependency
rollback that silently drops the server to an older revision fails CI instead of
passing quietly.
Quick start
Keeping the index fresh (incremental ingest)
Ingest is incremental by default. A manifest inside the store dir records a SHA-256 of each file's decoded text; a run re-embeds only what actually changed, and prunes what upsert alone never could (chunks of deleted/renamed notes, and trailing chunks of notes that got shorter).
Measured on a live 2808-file / 26.6 MiB corpus (bge, CPU):
That is what makes a frequent schedule affordable: reingest.bat is meant to run
every 15 minutes instead of once daily at 03:00, which had left a note written
at 03:05 invisible to search_knowledge for nearly 24 hours.
The manifest is only trusted when the run identity matches -- embedder, embedding dimension, collection and chunking parameters. Change any of them and every file is re-embedded, so an embedder swap can never be silently half-applied. A missing, corrupt, or mismatched manifest, or a manifest against an empty store, all degrade to a full rebuild; nothing degrades to a wrong skip.
Snapshot de-duplication
The manifest's skip is a whole-file hash, so it cannot see the duplication that
actually hurts retrieval: a daily snapshot series (fleet-health-2026-07-23.md and
friends) repeats yesterday's paragraphs verbatim inside a file whose hash still
changed. Measured on the live vault, one ## RED Bots status line took five
distinct values across fifteen consecutive files and crowded a top-10 with
byte-identical copies of itself, burying the document that explained it at rank 16.
Ingest therefore also de-duplicates at chunk level, but only within a dated
series and only against the immediately preceding snapshot. The first occurrence
is always embedded and keeps its own date as its source; later verbatim repeats
are not embedded, and instead extend the survivor's repeat_dates metadata, which
search_knowledge returns as snapshot_date / also_unchanged_on /
snapshots_covered. So "what did this say on date X" is still answerable -- that is
why the series is de-duplicated rather than excluded. A value that changes and later
returns is kept, because it is a new fact rather than a repeat.
Scope is narrow and stated with the rule in rag_mcp/snapshots.py: filename ending
in -YYYY-MM-DD, at least 3 such files sharing a directory and stem, byte-identical
under an identical heading. On the live corpus that is 316 of 2,814 files and
collapses 842 of 50,428 chunks (17.5% of series chunks, 1.67% corpus-wide) while
touching zero ordinary notes. Disable with --no-snapshot-dedupe.
--full rebuilds in place (ignores the manifest, keeps the store); --clean
deletes the store first. Both still WRITE a manifest, so the next run is cheap.
reingest-clean.bat (weekly) remains a belt-and-braces reset.
As an MCP server
Register via mcp.yaml (validated against mcp-factory's Manifest loader). The tool is
search_knowledge(query, k, doc_class=None); it reads the store configured by the
RAG_MCP_* env vars.
Filtering by document class
Every chunk's metadata carries a doc_class, set at ingest time. It is "handoff" when
the doc's YAML frontmatter has type: handoff or a tags entry of handoff
(case-insensitive), or -- since a doc's frontmatter is optional and the session mirrors
this exists to flag often carry none -- when the file sits directly under a
handoff_mirror_dir (default context/, configurable via ingest()'s
handoff_mirror_dir=/handoff_mirror_basenames= params or the CLI's
--handoff-mirror-dir/--handoff-mirror-basename flags) and is named handoff.md /
active.md / resume.md, or matches an anchored "handoff" filename token (e.g.
handoff-2026-09-03.md, morning-dispatch-handoff.md) -- never a bare substring, so a
title that merely mentions the word (handoff-skill-redesign-spec.md) stays "note".
Everything else defaults to "note". Pass doc_class to scope a query to one class, e.g.
to keep an agent's own session/handoff bookkeeping out of a knowledge lookup:
doc_class is a validated, case-sensitive enum -- "note" or "handoff" (see
rag_mcp.search.ALLOWED_DOC_CLASSES) -- or omitted for no filter. A value outside that
set (wrong case, a typo, any other type) returns a structured invalid_doc_class error,
same shape as invalid_query. A syntactically valid doc_class that simply has no
matches in the current store still fails soft to an empty, ok: true result.
An incremental ingest run backfills doc_class (and any other metadata-schema change) onto
already-embedded, content-unchanged chunks WITHOUT re-embedding them -- see
ingest.CURRENT_METADATA_VERSION. A store that predates this feature entirely gets the
correct doc_class on every chunk after exactly one incremental run, not a full --clean
rebuild.
Tests
This count is the total collected, CI-enforced against the live pytest summary
(scripts/check_readme_counts.py, wired into .github/workflows/ci.yml). One
test is platform-conditional -- WINDOWS_ONLY in
tests/test_reindex_handle_release.py only runs on Windows -- so Linux CI
reports 271 passed, 1 skipped for the same 272-test suite; the gate compares
passed-plus-skipped against this claim, not passed alone, so that expected
skip does not read as drift.
Layout
Commercial support
Maintained by Jaimen Bell. For production MCP integrations, custom servers, or agent-reliability work, see jaimenbell.dev.
Building your own MCP server? The MCP Starter Kit has templates, a build playbook, and packaging war-stories from shipping this one.
mcp-name: io.github.jaimenbell/rag-mcp
來源:README.md,提交 9448785
工具
0版本歷史
1- v0.1.0最新Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分