Skip to main content
Glama
calibre-mcp

calibre-mcp

by gletonai
README.md
# calibre-mcp

A read-only [MCP](https://modelcontextprotocol.io) server for a Calibre ebook
library. Point an agent at your library and it can search it with Calibre's own
query syntax, read full metadata, browse facets, and page through the actual
text of EPUB and PDF files.

```
calibre-mcp --library "/home/you/Calibre Library"
```

## Why another one

`calibre_full_mcp_server` works, but three things made it unreliable in daily
use:

| Problem there | Here |
|---|---|
| Holds the library open, so books added afterwards are invisible until restart — and lookups answer "no such book" confidently | Opens `metadata.db` read-only on **every call**; nothing can go stale |
| No file formats or paths in metadata; can't tell an EPUB from a metadata-only stub | Formats, sizes and on-disk paths are always returned |
| Empty fields are silently omitted, so "no tags" and "field unsupported" look identical | Missing values come back as `null` / `[]` / `{}` |
| Ships `delete_book`, `bulk_update_metadata`, `convert_book` to the model | Read-only: no tool can modify or delete anything |

It also runs as a **stdio** server, so there is no daemon to restart and no
second copy of the library state to disagree with Calibre.

## Tools

| Tool | What it does |
|---|---|
| `search` | Calibre query syntax (`author:`, `tag:`, `series:`, `pubdate:>2000`, `~regex`, `and`/`or`/`not`, `#custom`), paging and sorting. Delegates to `calibredb search`, so semantics are Calibre's, not an approximation. |
| `book` | Full metadata: authors, tags, series, publisher, languages, identifiers, description, rating, formats + sizes, cover, custom columns. |
| `books` | The same for a batch of ids. |
| `facets` | Distinct values with counts for authors, tags, series, publisher, languages, formats, rating, or `#custom`. |
| `read_book` | A character range of the book text. EPUB is parsed natively; PDF via `pdftotext`; other formats via `ebook-convert`. |
| `search_inside` | Regex search within one book, with context snippets. |
| `cover` | Cover image path, optionally inline as base64. |
| `library_info` | Library path, counts, formats present, custom columns. |

## Install

Requires Python 3.10+ and `mcp>=1.0`. Calibre (`calibredb`) is used for search
when present; without it a simpler `LIKE` scan is used. `pdftotext` is needed
for PDF text and `ebook-convert` for exotic formats.

```sh
pipx install git+https://github.com/gletonai/calibre-mcp
```

Gentoo: `app-misc/calibre-mcp` in the `gletonai/bakusaiga` overlay.

## Configuration

The library is resolved in this order, first hit wins:

1. `--library PATH`
2. `$CALIBRE_MCP_LIBRARY`
3. `$CALIBRE_LIBRARY`
4. the path Calibre itself saved (`~/.config/calibre/global.py.json`)

Register it with Claude Code:

```sh
claude mcp add -s user calibre-mcp -- calibre-mcp --library "/home/you/Calibre Library"
```

## Scope

Read-only on purpose. Metadata edits, imports and conversions belong in Calibre,
where they are visible, interruptible and undoable; an agent with a `delete`
tool pointed at a personal library is a worse trade than the convenience is
worth.

Custom column support is best-effort: text, series, enumeration, authors,
rating, bool, int, float and datetime are read; composite columns are skipped.

## Development

```sh
python3 -m pytest -q          # no Calibre install needed
python3 -m calibre_mcp --library /path/to/lib --version
```

The tests build a synthetic `metadata.db` from Calibre's own DDL, so they run
anywhere; `tests/test_library.py` also covers EPUB spine ordering and paging.