Code Mode for Zotero
Read-only access to a local Zotero library: search items, retrieve records by Zotero or Better BibTeX citation key, extract PDF full text by page, find relevant passages, and build/query a passage index for cited answers.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Code Mode for Zotero find passages on pyrethroid effects on bees, with page numbers"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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 |
| Lists the |
| 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.
Related MCP server: zotero-mcp
What a script can call
All read-only. Records are small flat dicts (key, title, creators, year, DOI, tags, citationKey, library).
Function | Returns |
| Items matching a query, at most 200 |
| One item, by Zotero key, citation key or Better BibTeX key |
| The text of an item's PDF, one entry per page |
| Paragraphs of one document that contain every word, with page numbers |
| The most relevant passages across the library, with page numbers |
| 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 hereClaude 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.
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 modelPassages 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 |
| found automatically | Path to |
| next to | Path to |
|
|
|
|
|
|
|
| Passage index |
| none | OpenAI-compatible endpoint, e.g. |
|
| Embedding model name |
| 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.
Available Tools
2 toolsexecuteExecuteA
Run Python that reads the user's Zotero library. A global zotero offers search(), get_item(), fulltext(), find() and passages() (meaning-based search over the PDF text, with page numbers; see search_api for details); results are plain dicts and lists. Only what you print(), or a final bare expression, is returned, so filter and summarise in code instead of printing everything. Read-only; no network or file access.
Inputs: code (required), timeout_seconds. Returns: result
search_apiSearch ApiA
List the functions available inside execute(), with signatures and the fields of the records they return. Give a word to narrow the list; leave it empty for everything.
Inputs: query. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 2 tools
The two tools occupy clearly separate roles: search_api is pure introspection/documentation of the execute() surface, while execute runs code. There is no plausible way to confuse them, and the description of execute explicitly points at search_api for detail.
Both names are lowercase snake_case, but search_api follows a verb_noun pattern while execute is a bare verb. Minor deviation rather than a conflict, and both remain readable and predictable.
A code-mode server deliberately needs only an introspection tool and an execution tool, so the count is well-matched to the design rather than thin. A third convenience tool (e.g. a schema/help shortcut) is not needed but the 2-tool surface sits at the low end.
For read-only research workflows the surface is workable: search, get_item, fulltext, find, and passages cover discovery and retrieval. However, there are no write operations (adding items, notes, tags, collections) and no explicit collection/tag listing or export, so Zotero library management is only half-covered.
Maintenance
Related MCP Connectors
Zotero MCP server for Claude and ChatGPT: search, citations, safe writes, PDF passages and pages.
Query your own PDFs and documents from any MCP client. Every answer cites the page it came from.
Agentic search over your Dewey document collections from any MCP-compatible client.
- ORANO MCP ServerDeprecatedio.github.infotik
Read-only MCP server exposing a user ORANO library to their own AI agent.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables ChatGPT to search and retrieve papers, passages, and page evidence from a local Zotero library via a read-only MCP server.AGPL 3.0
- FlicenseNot gradedqualityDmaintenanceMCP server for natural-language search over a local Zotero library, enabling tools to search, retrieve, and manage paper metadata, notes, and PDF fulltext via Claude.-
- FlicenseNot gradedqualityAmaintenanceEnables AI assistants and other MCP clients to search a Zotero library by text query and retrieve an item's full metadata or PDF full text, working against either the local Zotero desktop API or the Zotero Web API.-
- FlicenseNot gradedqualityAmaintenanceEnables MCP clients and AI assistants to search a Zotero library, retrieve complete item metadata, and access full text such as PDF contents through the Zotero API.-