Librarian

io.github.Terobyte由 GitHub 帳號 Terobyte 發布v0.1.1更新於 Oct 24, 2026

Deterministic ebook-to-markdown pipeline with MCP tools to browse, search, and read your books.

已驗證STDIO僅桌面檔案與儲存知識與記憶

概覽

AI 產生的概覽

本機 MCP 伺服器,把電子書轉成乾淨的 Markdown 章節,讓助理離線瀏覽、搜尋、閱讀書庫並核對引文。

可以做什麼
列出書庫中的書籍,以及某本書的章節(含 token 數與摘要),並提供書籍中繼資料與匯入品質指標。在整個書庫範圍內對章節、標題與作者做全文檢索並回傳片段。依範圍或依 token 預算讀取章節,讓內容符合模型上下文視窗。核對引文是否出自某本書,或在整個書庫中找出出處,回傳 exact、close、distorted、not_found 等判定。
適用情境
適合在本機保存電子書庫、希望助理依據這些書作答、在 token 預算內取出合適章節,或檢查自己給出的引文是否確實出現在原文中。適用於不需向量嵌入與 API 金鑰的離線、可重現檢索。
執行需求
以本機 stdio 程序執行,從 PyPI 套件 librarian-cli 安裝(例如 uv tool install 或 pipx)。書庫根目錄由環境變數 LIB_HOME 或 --library 選項指定,預設為 ./library。書籍需先用命令列工具匯入。安裝與執行都不需要網路、API 金鑰或帳號。
安裝前請注意
MCP 工具為唯讀,但命令列可執行匯入、重建與刪除書籍,應避免讓助理觸及這些破壞性指令。不繞過 DRM,來源合法性由使用者負責。不支援 NFS、SMB 等網路檔案系統。命令列訊息目前為俄文,且伺服器啟動時依賴 FTS5 搜尋索引。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Librarian,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

📚 librarian

[CI] [PyPI] [Python versions] [License] [MCP registry]

Turn any ebook into clean, token-counted Markdown chapters — let Claude read your bookshelf over MCP and catch it misquoting your books. Deterministic RAG: no embeddings, no network, no API keys.

[demo]

Any input format — FB2, EPUB, DOCX, HTML, TXT/MD, text-layer PDF — becomes a directory of clean chapters with token counts. No network, no LLM, no randomness: the same input always produces byte-identical output.

Install

uv tool install librarian-cli# or: pipx install librarian-cli

Offline contract: install and runtime need no network (the tokenizer's vocabulary is vendored in the package).

Quick start

lib ingest examples/*.epublib listlib find curiouserlib get <book-id> --budget 3000

Commands

CommandPurpose
lib ingest <files…> [--force] [--no-keep-source] [--config cfg.toml] [--verbose]Process books into the library; prints a file · id · status · score table.
lib list [<book-id>]No argument — all books; with an id — that book's chapters (n, title, tokens, summary).
lib get <book-id> <spec>Print chapters by range (1-3,7) to stdout.
lib get <book-id> --budget N [--from K]Greedily print consecutive chapters from K while the token sum stays ≤ N.
lib find <query> [--limit 10] [--book <id>] [--reindex] [--json]Full-text search across chapters and titles/authors library-wide (bm25, snippets, RU/EN stemming).
lib info <book-id>JSON: book metadata + quality metrics.
lib doctor [<book-id>]No id — books in review and broken directories; with id — that book's report.
lib reingest --all [--config cfg.toml] [--verbose]Rebuild the library from source/ with the current code/config.
lib rm <book-id>Delete a book and rebuild the index.
lib serve [--library <path>]Stdio MCP server over the library.
lib verify "quote" [--book ID] [--json] [--limit N]Check a quote against one book or attribute it across the library.

Library root: --library <path> (or the LIB_HOME env var, default ./library). Data goes to stdout, diagnostics to stderr. Exit codes: 0 success, 1 runtime error, 2 usage error.

Give Claude your bookshelf

librarian-cli ships a built-in stdio MCP server with 6 read-only tools — list_books, list_chapters, find, get_chapters, book_info, verify_quote — so Claude can browse the catalog, search it, pull chapters under a token budget, and check its own quotes against the source on its own: deterministic RAG with no embeddings, no network, and no API keys.

Claude Code:

claude mcp add librarian --env LIB_HOME=$HOME/books -- uvx librarian-cli

Claude Desktop (claude_desktop_config.json):

json
{  "mcpServers": {    "librarian": {      "command": "uvx",      "args": ["librarian-cli"],      "env": { "LIB_HOME": "/path/to/books" }    }  }}

Verify quotes

An MCP server that catches Claude misquoting your books.

lib verify "quote" checks whether a quote actually appears in your library, verbatim — punctuation, case, ё/е, and markdown formatting don't count. Two modes:

  • Book mode (--book <id>): full scan of one book — "does this book actually say this?" Works without the search index.
  • Shelf mode (no --book): attribution across the whole library via FTS5 candidates — "which book is this from?" The quote needs at least 5 significant words (stop words don't count), or the check is skipped with verdict: null.
lib verify "Рукописи не горят" --book bulgakov-master-i-margaritalib verify "рукописи не горят никогда"
verdictmeaning
exactmatches after normalization (punctuation/case/ё/typography don't count)
closesimilarity ≥ 0.95 — near-exact, differences shown as a word-diff
distortedsimilarity ≥ 0.75 — the right place, but the quote is misremembered
not_foundsimilarity < 0.75 — nothing like it in the book/library
nullcheck wasn't run: empty quote, or a short quote without --book

Exit codes (grep-style semantics, a deliberate departure from the project's usual "1 = runtime error" — see docs/MILESTONES.md deviation 38):

exitcasestdout
0exact / close — quote confirmedfull report / JSON
1distorted / not_found — not confirmedfull report / JSON
1runtime error (unknown book id, no search index, locked index)empty
2usage error: empty/short quote (verdict: null), --limit < 1empty (message on stderr)

Script discriminator: exit 1 with non-empty stdout means "checked, not confirmed"; exit 1 with empty stdout means an error (diagnostics went to stderr instead). Exit 0 includes close — a strict CI gate must check verdict == "exact" in the --json output, not the exit code alone.

Quality

Every book gets a score from five metrics (coverage, structure, garbage, encoding, dehyphenation): ok (score ≥ 0.90, no hard triggers) — saved silently; review (0.60 ≤ score < 0.90, or triggers present) — saved with a warning, details via lib doctor <id>; failed (score < 0.60) — not saved. Scans and password-protected PDFs honestly fail (OCR and DRM removal are out of scope).

Determinism

The pipeline has no network access, no LLM calls, and no randomness — the same input file always produces byte-identical output. That makes ingestion reproducible and cacheable, and it's what makes lib serve's RAG deterministic: no embeddings to drift, no model calls to vary between runs.

Limitations

  • PDF: works well on typographically normal books; complex layouts may land in review.
  • DRM is not circumvented; source legality is the user's responsibility.
  • Networked filesystems (NFS/SMB) are not supported (the advisory lock isn't reliable there).
  • MOBI/DJVU and text-less scans are not supported (v3 candidates: OCR, calibre).
  • CLI messages are currently in Russian; English output is planned.
  • lib verify: quotes spanning a chapter boundary are not supported (v1) — the best you'll get is distorted on one half.
  • lib verify: close on a single-word replacement is realistic from ~150 characters of quote; shorter quotes with a replaced word honestly land in distorted — a third of a three-word quote really is a distortion.
  • lib verify shelf mode (no --book) needs the FTS5 search index; book mode (--book <id>) works without it in the CLI. lib serve as a whole still requires FTS5 — it syncs the index at startup regardless of which tool gets called.
  • lib verify in book mode scans the whole chapter text in pure Python; a long book can take a few seconds of CPU. The MCP tool runs it in a worker thread so it doesn't block the rest of the server.

Русская версия

See README.ru.md for the Russian documentation.

來源:README.md,提交 9ad3b3c

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v0.1.1最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分