Code Mode for Zotero
Read your Zotero library from Claude, ChatGPT or any MCP client, by letting the model write short Python scripts instead of calling dozens of tools. The scripts run in a sandbox on your computer, read the local zotero.sqlite, and only what they print goes back to the model. Passages can be searched by meaning, in French or English, and every hit comes with its page, so answers can be cited as citekey, p. 12.
Not affiliated with Zotero or the Corporation for Digital Scholarship. Zotero is their project; this is an independent tool that reads the files Zotero keeps on your disk.
Status: alpha (0.1). macOS and Linux. Windows is not supported yet, because scripts cannot be isolated there.
Why code mode
A classic Zotero MCP server exposes one tool per operation, which puts thousands of tokens of tool definitions in every conversation and sends every intermediate result through the model. This server has two tools:
| Tool | What it does |
|---|---|
api_docs(topic="") |
Lists the zotero.* functions a script can call, with their documentation. |
execute(code, timeout_seconds=30) |
Runs a script and returns what it printed. |
The two definitions take about 420 tokens. A search over 200 items, a filter and a sort happen inside the script, and only the five lines the script prints reach the model.
What a script can call
All read-only. Records are small flat dicts (key, title, creators, year, DOI, tags, citationKey, library).
| Function | Returns |
|---|---|
zotero.search(query, collection, library, tags, ...) |
Items matching a query and filters (collection and library by name), 50 by default, at most 200 |
zotero.collections(), zotero.libraries(), zotero.tags() |
What the library contains, to filter on |
zotero.get_item(ref, detail) |
One item, by Zotero key, citation key or Better BibTeX key |
zotero.fulltext(ref, first, last) |
The text of an item's PDF, one entry per page |
zotero.find(ref, query) |
Paragraphs of one document that contain every word, with page numbers |
zotero.passages(query, limit, keys) |
The most relevant passages across the library, with page numbers |
zotero.rag_index(...), zotero.rag_status() |
Build and inspect the passage index |
Every library in the database is searched (personal and groups) unless ZOTERO_MCP_LIBRARY says otherwise (0 for the personal library, or a group id).
Install
Requires Python 3.10 or later and Zotero installed on the same computer (it does not need to be running).
uv tool install 'code-mode-for-zotero[embeddings]' # or: pipx install ..., pip install ...
code-mode-zotero --check-sandbox # what scripts can and cannot do here
Claude Desktop, in claude_desktop_config.json:
{
"mcpServers": {
"zotero": {
"command": "code-mode-zotero",
"env": {
"ZOTERO_RAG_EMBED_URL": "http://127.0.0.1:1234/v1",
"ZOTERO_RAG_EMBED_MODEL": "text-embedding-bge-m3"
}
}
}
}
The env block is optional; without it, passage search works on keywords only. Claude Desktop does not read your shell profile, so variables go in this block.
Passage search
code-mode-zotero --check-embeddings # one call to your embeddings server, with a sanity check
code-mode-zotero --index # build or refresh the index; resumable
code-mode-zotero --index --force # rebuild everything, e.g. after changing the model
Passages are cut from each PDF without crossing a page, cleaned of reference lists, tables and line numbers, and stored in one SQLite file. Keyword search uses French and English word stems, so "pyréthrinoïde" finds "pyréthrinoïdes". When an embeddings endpoint is configured (LM Studio, Ollama, vLLM or any OpenAI-compatible /v1/embeddings), passages are also ranked by meaning and the two rankings are merged. If the endpoint is unreachable, search falls back to keywords and says so in each result.
What it runs, reads, writes and sends
This section is complete; if the code does something not listed here, it is a bug.
- Runs: the MCP server, and for each
executecall a child Python process with the script. On macOS the child runs undersandbox-execwith no network, no file writes, no new processes and no access to your home folder; on Linux it runs in an empty network namespace (files and processes are not blocked there, so scripts only run withZOTERO_MCP_SANDBOX=relaxed). CPU time, output size and run time are limited everywhere, memory on Linux. - Reads:
zotero.sqlite, read-only (it may be copied to a temporary folder so it can be read while Zotero is writing),better-bibtex.sqliteif present, and attachment files in Zotero's storage folder. - Writes: the passage index (
~/.local/share/code-mode-for-zotero/rag.sqlite, orZOTERO_RAG_DB) and a cache of extracted text (~/.cache/code-mode-for-zotero/fulltext/). It never writes to your Zotero library. - Sends: passage text and search queries to the embeddings endpoint you configure, and nowhere else. With no endpoint configured, the server makes no network call. There is no telemetry.
See PRIVACY.md and SECURITY.md.
Settings
| Variable | Default | Meaning |
|---|---|---|
ZOTERO_DB_PATH |
found automatically | Path to zotero.sqlite |
ZOTERO_BBT_DB |
next to zotero.sqlite |
Path to better-bibtex.sqlite |
ZOTERO_MCP_LIBRARY |
all |
all, 0 (personal) or a group id |
ZOTERO_MCP_SANDBOX |
strict |
relaxed runs scripts without full isolation |
ZOTERO_RAG_DB |
~/.local/share/code-mode-for-zotero/rag.sqlite |
Passage index |
ZOTERO_RAG_EMBED_URL |
none | OpenAI-compatible endpoint, e.g. http://localhost:1234/v1 |
ZOTERO_RAG_EMBED_MODEL |
nomic-embed-text |
Embedding model name |
ZOTERO_RAG_EMBED_KEY |
none | Bearer token, if the endpoint needs one |
Limits
- Read-only: no adding, tagging or annotating items.
- A timeout stops a script but not a database call already running.
- Scanned PDFs without a text layer are reported (
needsOcr) and not indexed. - If PyMuPDF is installed in the same environment, it is used to repair malformed PDFs and to recover OCR text layers that the main extractor misses. It is not a dependency (it is under the AGPL); install it yourself if you want this.
- An index built with one embedding model cannot be queried with another.
Authors and origin
Loïc Talignani and Thierry Valéro. The data-access layer comes from Zotero MCP (MIT); see NOTICE. MIT License.
Metadata
Release files for code-mode-for-zotero 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| code_mode_for_zotero-0.2.0.tar.gz | 190.7 kB | With provenance | Details for code_mode_for_zotero-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| code_mode_for_zotero-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for code_mode_for_zotero-0.2.0-py3-none-any.whl |
Total release size: 322.4 kB
Release files / code_mode_for_zotero-0.2.0.tar.gz
| Download URL | code_mode_for_zotero-0.2.0.tar.gz |
|---|---|
| Size | 190.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d69f897584a58672482ae1b49ff6e30d39f1fff4d00727f403b9f3c9a7627564
|
|
BLAKE2b-256 checksum How to use checksums |
ad35e19abcfa6f66194f9ba1efdcf314c13d1dc2217f50aeda8e9400ca3f0c5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logRelease files / code_mode_for_zotero-0.2.0-py3-none-any.whl
| Download URL | code_mode_for_zotero-0.2.0-py3-none-any.whl |
|---|---|
| Size | 131.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1d0f53c9fa6e20e354d9610fe3fccc352b285a14898aa772044109bfde0b848a
|
|
BLAKE2b-256 checksum How to use checksums |
32a8ad6c96b5666b8738fce6ff5962619a252722d584ecde070ba2ff800d7494
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logSecurity for code-mode-for-zotero 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for code_mode_for_zotero-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.