calibre-mcp
CLAUDE.md16 starsChanged 5 months agoMITView on GitHub
Build the most capable Calibre MCP server in existence — a single, reliable TypeScript server that replaces the current two-server hack (FaceDeer/calibre_full_mcp_server for reads + shell-command-mcp/calibredb for writes) running in Claude Desktop today. It must: 1. Match the full tool surface of every known Calibre MCP server (feature parity baseline). 2. Add semantic search — the headline differentiator no existing TS server has. 3. Fix the write path that breaks in Cowork (MCP error -32602, args-as-strings). - GUI-concurrency lock is…
In this repository5 other files it gives its agents.
- calibre-distillSkill
- calibre-distill-topicSkill
- calibre-mcp-setupSkill
- calibre-mcpSkill
- calibre-study-notesSkill
The file
We split this CLAUDE.md into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 6
Keep this file lean; status narrative does NOT belong here.
- Very specific: line 57
Read paths (FTS, calibre_ping) resolve the libId too.
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md — Calibre MCP Server
<!-- Project memory for the calibre-mcp build: the invariants a fresh session needs BEFORE touching
code today. Chronological build history → docs/dev/JOURNAL.md. Locked decisions + deferred registry
→ docs/dev/DECISIONS.md. Longer policy/context sections are @imported from docs/claude/.
Keep this file lean; status narrative does NOT belong here. -->Macro goal
Build the most capable Calibre MCP server in existence — a single, reliable
TypeScript server that replaces the current two-server hack (FaceDeer/calibre_full_mcp_server
for reads + shell-command-mcp/calibredb for writes) running in Claude Desktop today.
It must:
- Match the full tool surface of every known Calibre MCP server (feature parity baseline).
- Add semantic search — the headline differentiator no existing TS server has.
- Fix the write path that breaks in Cowork (
MCP error -32602, args-as-strings).
Target environment (ground-truth, do not re-derive)
- Calibre 9.10, macOS Apple Silicon (macOS 26 beta), Node v24.
- Library: ~801 books in
Programming Books(default) + aReaserch Bookslib, under~/Documents/Books/. - Mostly PDF/EPUB, technical, EN + RU. Many have raw filenames (
795731065,top.dvi,B0CZS7H23N.pdf) → metadata recovery matters. - Calibre GUI is normally running + Content Server live on
:8080. - Clients: Claude Desktop, Claude Code CLI, Cowork. Transport: stdio.
Hard constraints / gotchas (these killed earlier attempts)
- GUI-concurrency lock is real (reproduced). With the app open, direct
calibredb/SQLite/DB-API access is refused or dangerous. Safe live paths: Content Server HTTP (reads) orcalibredbrouted through the server URL. Treat the DB as read-mostly; never race the GUI on writes. Write path RESOLVED (docs/dev/CAPABILITIES.md§2): route writes through the running server — shellcalibredb --with-library http://localhost:8080/#Lib(it speaks/cdb/cmdfor us), the server permitting writes via--enable-local-write; a direct/cdb/set-fieldsHTTP client is a LATER opt. -32602serialization bug (our Cowork failure) is client-side, confirmed, unfixed. Defense = Zod coercion on every input:z.coerce.number(),z.preprocess(JSON.parse, …)for arrays/objects, unions for ids. Neverz.coerce.boolean()on"false".- stdout is sacred on stdio — all logs to stderr. One stray
console.logcorrupts the stream. - FTS is book-level only (no PDF page / EPUB spine location) and not enabled on this library yet. Calibre has no OCR; PDF is the worst conversion/extraction input.
- Writes gated by default — read-only unless an explicit env flag + per-tool
annotationsallow it. - Clients strip
structuredContent(Claude Desktop drops it from the tool-result notification; some clients surface only text blocks). Anything the model must act on — ranked hits, excerpts,nextCursortokens — must ALSO appear in the text content; the cover-board widget refetches its data via the widget-internalcalibre_board_datatool for the same reason (#26, D-017).
Engineering invariants (constrain every edit)
- Write gate is two-key. The master gate is
CALIBRE_MCP_ENABLE_WRITE(truthy) inconfig.ts;server.ts.disable()s everywrite:truetool when it's off. On top, each write tool carries per-toolannotationsand is preview-first (preview/confirm/applyin-band params, not MCP elicitation — seedocs/dev/DECISIONS.mdD-003). Path-taking writes (calibre_add_book) enforce a path whitelist (CALIBRE_MCP_ADD_ROOTS,realpathSyncboundary check). - libId-resolve pattern for ALL
calibredbcalls.calibredb --with-libraryneeds the library ID (Programming_Books), not the display name (Programming Books, which 404s). Resolve display→libId viacontent.resolveLibraryIdfirst, then pass it ascalibredbopts.library. Read paths (FTS,calibre_ping) resolve the libId too. (seedocs/dev/DECISIONS.mdD-008.) - SDK-free seam. Tool handlers/schemas/domain code never import
@modelcontextprotocol/sdk; only the transport/registration layer (server.ts+run-stdio.ts) does.tools/types.tsstructurally mirrorsCallToolResult/ToolAnnotationsso handlers stay SDK-free. Isolates the SDK-v2 migration. - Return-not-throw
isErrorcontract. Handlers return a result withisError+ an actionable message steering the model's next step; they don't throw across the SDK boundary. - Tool-count ≤ ~20. Fold related calibredb subcommands into task/intent tools; don't 1:1-mirror
the CLI (
docs/claude/tool-surface.md+docs/dev/DECISIONS.mdD-005). Currently 18 model-facing tools — 17 task tools (docs/dev/TOOLS-spec.md) +calibre_ping— plus 1 widget-internal (calibre_board_data,_meta.ui.visibility ["app"], D-017). - Never report a committed write as failed. Routed writes commit server-side before
calibredbreplies (#33): a failing post-write diff re-read degrades to a success result with the intended-value diff, and a CLI timeout is verified against a re-read — confirmed → success, unconfirmed → steer the model tocalibre_get_bookbefore retrying. Applies tocalibre_update_bookand thecalibre_bulk_updateapply loop. - User/model-supplied regex compiles via
src/tools/user-regex.ts, never barenew RegExp(). It accepts leading PCRE-style inline flags ((?i)…) by folding them into JS RegExp flags and gives an explicit error for inexpressible ones likex(#30). - Content cursors are opaque and bound.
calibre_get_contentcursors encode{offset, id, format}and reject cross-book/format replay; decode is tolerant (never throws) but invalid/hand-built cursors get an actionable error, not a silent restart at 0 (#26). The numericoffsetparam is the cursor-free jump path (e.g. a search hit'scharStart) — mutually exclusive withcursor(#28).
Working rules
- English for all code, comments, docs (per global policy). Respond to Artem casually, concise, in markdown.
- Cite first-party sources; flag anything unconfirmed — don't trust memory for versions/APIs/tool lists.
Imported context
- @docs/claude/tool-surface.md — two-surfaces framing, FaceDeer capability baseline, ≤20 tool-count policy
- @docs/claude/stack-and-licensing.md — locked tech stack + GPL clean-room operating rules
- @docs/claude/artifacts-and-qmd.md — docs corpus map + qmd search workflow
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

