paper-retrieval
<div id="header" align="center">
<h1>mustcite-mcp</h1>
</div>


**Paper search for coding agents.** mustcite-mcp indexes a corpus of AI/ML papers (full text and the citation
graph between them) and serves it to Claude Code, Codex, or any MCP client. One `find_papers` call runs the whole
retrieval pipeline and returns ranked papers, each with the passage that matches the question and its official URL.
[mustcite.com](https://mustcite.com) lets people search the corpus that [OpenPapers](https://github.com/zhangleiniu/OpenPapers)
collects; mustcite-mcp gives agents the same corpus, searched in depth. [paperlevelup](https://github.com/zhangleiniu/paperlevelup),
an agent skill for organizing topic folders of papers and finding the ones you are missing, uses it as its main
library search.
<p align="center">
<img src="docs/ecosystem.svg" alt="OpenPapers collects papers, masterset-toolkit extracts full text and citations, mustcite-mcp indexes them and serves MCP tools to a coding agent, which paperlevelup guides; mustcite.com serves the same corpus to people" width="860">
</p>
| Step | Tool | Output |
|---|---|---|
| Collect | [OpenPapers](https://github.com/zhangleiniu/OpenPapers) | PDFs and metadata (official URL, OpenReview id, DOI) for 15 AI/ML venues |
| Extract | [masterset-toolkit](https://github.com/NIU-Graph-Intelligence/masterset-toolkit) | GROBID full text, citation contexts, a paper table with references matched to papers in the corpus |
| Index and serve | mustcite-mcp (this repository) | indexes, a search engine, and the MCP tools |
| Work with papers | [paperlevelup](https://github.com/zhangleiniu/paperlevelup) (optional) | an agent workflow on top of the tools |
No data ships with this repository: you build your corpus with the first two tools, on your own machine.
## What a search looks like
Ask the agent in plain words; it passes your question to `find_papers` verbatim and reports every result:
<p align="center">
<img src="docs/chat-find.svg" alt="Example: a question about local citation recommendation returns 20 papers with evidence passages; the agent points out which ones match best" width="760">
</p>
This is a real call on a corpus of about 185k papers. The service ranks; judging which results fit your intent
stays with the agent and with you. Other requests it handles:
| You ask | Tool |
|---|---|
| "papers on X", "which papers do X?" | `find_papers`, with filters on venue, year, and authors |
| "work related to this paper", "baselines for Y" | `find_related_papers` (by id, URL, or title + abstract) |
| "does this paper use dataset Z?" | `search_passages`, `exact_search`, `get_paper(section=...)` |
| "who cites it, and why?" | `get_citation_neighbors`, with the citing sentence |
| "summarize this paper" | `get_research_profile` (key passages; the agent writes the summary) |
## How search works
<p align="center">
<img src="docs/search-pipeline.svg" alt="Search pipeline: BM25 and dense retrieval over papers and passages, fused and reranked, expanded through the citation graph, fused again, returned with evidence passages" width="900">
</p>
- **Three text channels**: BM25 over full-text passages, dense retrieval over titles and abstracts
([Qwen3-Embedding-4B](https://huggingface.co/Qwen/Qwen3-Embedding-4B)) and over passages
(Qwen3-Embedding-0.6B), fused by reciprocal-rank fusion.
- **Reranking**: the top 50 papers are reranked with [Qwen3-Reranker-4B](https://huggingface.co/Qwen/Qwen3-Reranker-4B).
- **Citation graph**: personalized PageRank and co-citation, seeded from the reranked top, add well-cited work
the text missed.
- **The verbatim question**: agents pass the user's words as `original_query`. Its results are merged into every
follow-up call, so a narrowed query cannot lose them.
- **Evidence**: each result carries its passage closest to the query; the agent quotes it.
- **Optional**: a citation-intent model, for `relation_type="baseline"` (papers cited as baselines), and an LLM judge
(any OpenAI-compatible endpoint) for `llm_judge=true`.
The configuration was chosen by evaluation on test sets built from the corpus itself (a citation sentence → the
papers it cites; a paper → its references). The commands are included (see [Evaluation](#evaluation)).
## Requirements
- Linux, Python 3.12, [uv](https://docs.astral.sh/uv/).
- An NVIDIA GPU with about 20 GB of free memory, for building the embeddings and for serving. The server loads
the models on first use and releases the GPU after an idle period.
- For about 185k papers: about 30 GB of disk for snapshot and indexes, and about 40 GB of RAM for the server.
Smaller corpora need proportionally less.
## Setup
1. **Collect papers** with OpenPapers for the venues and years you want.
2. **Extract full text and references** with masterset-toolkit: GROBID full text, citation contexts, and the
dataframe builder (`preprocessing/dataframe_builder/`), which writes `all_papers_with_refs.parquet`. Keep
`PAPER_UUID_NAMESPACE` the same in both tools.
3. **Configure**: `cp .env.example .env` and set
- `PR_DATA_ROOT`: where snapshots, indexes, and logs go;
- `PR_CORPUS_PARQUET`: the toolkit's `all_papers_with_refs.parquet` (may contain `{run_id}`);
- `PR_FULLTEXT_ROOT`: the toolkit's data directory (the parquet's `path` column is relative to it);
- `PR_METADATA_DIR`: OpenPapers' `metadata/` directory;
- `PR_SNAPSHOT_RUN_ID`: a name for this corpus version, e.g. `2026-11`;
- `PR_CORPUS_DESCRIPTION`: how the tools describe your corpus to agents (optional).
4. **Build**:
```
uv sync
uv run paper-retrieval snapshot # paper table, links, citation edges
uv run paper-retrieval passages # full text -> passages with citation markers
uv run paper-retrieval build --build full # chunks, BM25, citation graph, embeddings (GPU)
```
Every step is resumable and writes a `manifest.json` (inputs, parameters, counts) next to its output.
5. **Serve** (binds to 127.0.0.1 only):
```
uv run paper-retrieval-server --build full --no-llm
```
6. **Connect an agent.** The MCP adapter is a thin stdio process that forwards calls to the server; it registers
as `paper-retrieval`. On the same machine:
```
claude mcp add paper-retrieval -- /path/to/mustcite-mcp/.venv/bin/paper-retrieval-mcp
```
From another machine, run the adapter over SSH (no port is exposed):
```
claude mcp add paper-retrieval -- ssh <server> /path/to/mustcite-mcp/.venv/bin/paper-retrieval-mcp
```
For Codex, in `~/.codex/config.toml`:
```toml
[mcp_servers.paper-retrieval]
command = "ssh"
args = ["<server>", "/path/to/mustcite-mcp/.venv/bin/paper-retrieval-mcp"]
```
7. **Give the agent the guide.** `agent/SKILL.md` tells it how to call the tools and report results (pass the
question verbatim, report every result in order, cite the URL). Install it as a skill, or use
[paperlevelup](https://github.com/zhangleiniu/paperlevelup), which carries the same rules.
When the corpus grows, `paper-retrieval rebuild --run-id <new run>` runs snapshot, passages, and the full build for
the new run (unchanged papers' vectors are reused) and reloads the running server.
The repository is named after the corpus it was built for; the Python package, the commands, and the MCP server
are named `paper-retrieval`.
## Optional components
- **Citation intent**: set `PR_INTENT_MODEL` to a directory holding a trained model (`model.json` + `model.npz`; see
`src/paper_retrieval/intent.py`). Without one, `relation_type="baseline"` ranks like `any` (the response says so),
and citation neighbors carry no baseline probability.
- **LLM judge**: start the server without `--no-llm` and set `PR_LLM_BASE_URL`, `PR_LLM_MODEL`, and
`PR_LLM_API_KEY` for an OpenAI-compatible endpoint (e.g. vLLM). `find_papers(llm_judge=true)` then adds a
relevance judgment to each result.
## Evaluation
```
uv run paper-retrieval build --build eval # papers up to 2024 only
uv run paper-retrieval testsets --version v1 # test queries from 2025 papers
uv run paper-retrieval evaluate --tasks t1 t2 --splits dev --retrievers bm25-paper "rrf:bm25-paper+dense-papers-qwen3-emb-0.6b"
```
T1 asks for the papers a 2025 citation sentence cites; T2 for a 2025 paper's references. Retriever specs are
described in `src/paper_retrieval/retrievers.py`; the configuration the server runs is in
`src/paper_retrieval/serving.py`.
## Development
This repository is exported from the authors' working repository at each release, so its history has one commit
per release (see [CHANGELOG.md](CHANGELOG.md)). Issues and pull requests are welcome: accepted pull requests are
applied upstream and appear in the next release, with credit.
```
uv run pytest # no GPU or data needed; includes an end-to-end run on a synthetic corpus
python3 docs/make_figures.py # regenerate the figures
```
## License
MIT (see [LICENSE](LICENSE)).
TDQS
Scored across 7 tools
The tools have mostly distinct retrieval goals: broad question search, passage search, exact term matching, related-paper discovery, metadata/section retrieval, citation neighbors, and research-profile extraction. There is some conceptual overlap between search_passages, exact_search, and get_paper with section retrieval, but the descriptions provide clear boundaries for when to use each.
Most names follow a clear verb_noun pattern such as find_papers, search_passages, get_paper, and get_citation_neighbors. exact_search is the main deviation, using an adjective_noun form, but it is still readable and consistent enough overall.
Seven tools is a well-scoped set for a paper retrieval server, with each tool covering a distinct retrieval mode or evidence-gathering need. No tool appears redundant or out of place.
The server covers semantic search, passage verification, exact matching, related work, metadata, citation context, and research-profile extraction. Minor gaps might include author/venue filtering or batch paper comparison, but the core retrieval lifecycle is well represented.