Skip to main content

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
search_api(query="") 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 230 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, ...) Items matching a query, at most 200
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://localhost: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.

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 execute call a child Python process with the script. On macOS the child runs under sandbox-exec with 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 with ZOTERO_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.sqlite if present, and attachment files in Zotero's storage folder.
  • Writes: the passage index (~/.local/share/code-mode-for-zotero/rag.sqlite, or ZOTERO_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.
  • 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.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for code-mode-for-zotero 0.1.0
File Size Uploaded Provenance Actions
code_mode_for_zotero-0.1.0.tar.gz 187.5 kB With provenance Details for code_mode_for_zotero-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for code-mode-for-zotero 0.1.0
File Interpreter ABI Platform Actions
code_mode_for_zotero-0.1.0-py3-none-any.whl Python 3 none any Details for code_mode_for_zotero-0.1.0-py3-none-any.whl

Total release size: 316.9 kB

Release files / code_mode_for_zotero-0.1.0.tar.gz

Download URL code_mode_for_zotero-0.1.0.tar.gz
Size 187.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9238a7c779340db1b11125f5ad7a672f9b433e9009a5db9f64dc439b9c7cdef3
BLAKE2b-256 checksum
How to use checksums
6c0e4c7fc1e73d5b98c31ea684058c4e7cdaf65c0cb21df2daf969c8eca3a654
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 Nov 29, 2026.

Transparency log

Release files / code_mode_for_zotero-0.1.0-py3-none-any.whl

Download URL code_mode_for_zotero-0.1.0-py3-none-any.whl
Size 129.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c94d466dd09efad0cd0ba3f560b0ec77372b330a50dd3621b12108ede34f5b2a
BLAKE2b-256 checksum
How to use checksums
f0ecb8fe13049f9dd2ef6c7f934802fc195c91acf8abc23d1905b7d3d72c324b
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 Nov 29, 2026.

Transparency log

Security for code-mode-for-zotero 0.1.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.

Select from 2 files

Attestation for code_mode_for_zotero-0.1.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 Nov 29, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page