Module db

Source
Expand description

Database access layer — direct SQLite reads on Zotero’s databases.

§The key insight

Zotero stores everything in SQLite. The Python MCP server was slow because it went through BBT JSON-RPC (a JavaScript plugin inside Zotero’s Electron app) to read this same data. By reading SQLite directly, we eliminate the dominant bottleneck: ~300ms per BBT RPC call → <1ms per SQLite query.

§Two databases

  • zotero.sqlite — all item metadata, collections, tags, creators, attachments, notes. Uses an EAV (Entity-Attribute-Value) schema: items → itemData → itemDataValues with field IDs mapped via fields.

  • better-bibtex.migrated — citekey assignments. Maps Zotero item keys (like “9MS26VH5”) to citation keys (like “demilloHintsTestData1978”). This file may not exist if BBT isn’t installed.

Both are opened read-only. We never write to Zotero’s databases directly — writes go through the Zotero Web API.

Modules§

bbt
BBT (Better BibTeX) citekey database reader.
zotero
Zotero SQLite database reader.

Structs§

DbPool
Holds connections to both Zotero databases.