Skip to main content
Glama
README.md
# litquery

[Install](#install) / [Sources](#sources) / [Tools](#tools) / [How it works](#how-it-works)

A local MCP server and command line tool that:

- Searches Scopus, Web of Science, IEEE Xplore and three open indexes with one search string
- Keeps the records, the databases' original replies and a log of every search in a folder on your computer
- Removes duplicates, fills in missing abstracts and exports RIS, BibTeX or CSV
- Uses your own API keys, which stay in the credential store of your operating system

It was written for systematic literature reviews, where every search has to be reported. It serves just as well for a quick look at what exists on a topic.

## One search string, six databases

```
("digital twin" OR "cyber-physical system") AND warehouse AND simulat*
```

| Source | What is sent |
| --- | --- |
| Scopus | `TITLE-ABS-KEY(("digital twin" OR "cyber-physical system") AND warehouse AND simulat*)` |
| Web of Science | `TS=(("digital twin" OR "cyber-physical system") AND warehouse AND simulat*)` |
| IEEE Xplore | `(("digital twin" OR "cyber-physical system") AND warehouse AND simulat*)`, searched in the metadata fields |
| Semantic Scholar | `("digital twin" \| "cyber-physical system") + warehouse + simulat*` |
| OpenAlex | `title_abstract_keywords.search:(("digital twin" OR "cyber-physical system") AND warehouse),title_abstract_keywords.search.exact:(simulat*)` |
| CORE | refused: CORE does not expand wildcards |

Every answer carries the query that was sent. Where a database cannot do exactly what the string asks, the answer says so: a warning for a small difference (the topic search of Web of Science also covers Keywords Plus), the mark `approximate` for a larger one, and a refusal with a way out where it cannot be done at all.

## Sources

| Source | Role | API key | Abstracts | Good to know |
| --- | --- | --- | --- | --- |
| Scopus | main | required | on the university network, over VPN or with an institutional token | weekly allowance set by Elsevier |
| Web of Science | main | required (Starter API) | never | 50 records per call, daily allowance by plan, first 100,000 records of a search |
| IEEE Xplore | main | required | yes | about 200 calls a day, 200 records per call |
| Semantic Scholar | extra | optional | most records | title and abstract only; without a key all anonymous users share one small allowance |
| OpenAlex | extra | optional, free | most records | matches word stems, so `model` also finds `models` |
| CORE | extra | optional | some records | no NOT, no wildcards, first 10,000 records of a search |
| Crossref | lookup | none | some records | asked for abstracts by DOI, never searched |

ACM Digital Library and Google Scholar have no API. Export RIS or BibTeX from the website (for Google Scholar through Publish or Perish) and add the file with `import_file`.

## Install

Python 3.11 or newer.

```
git clone https://github.com/sanketkute/litquery
cd litquery
python -m venv .venv
```

Windows:

```
.venv\Scripts\pip install -e .
```

macOS and Linux:

```
.venv/bin/pip install -e .
```

This puts two programs into `.venv\Scripts` (Windows) or `.venv/bin`: `litquery`, the command line tool, and `litquery-mcp`, the MCP server.

### Keys

```
.venv\Scripts\litquery keys setup
```

This asks for each key in turn. What you paste is not shown, and Enter skips a key. The keys go into the credential store of the operating system (Credential Manager on Windows, Keychain on macOS, Secret Service on Linux) under the name `litquery`. At the end each service is contacted once to confirm that its key works.

| Key | Where to get it | |
| --- | --- | --- |
| `scopus_api_key` | [dev.elsevier.com](https://dev.elsevier.com) | |
| `scopus_insttoken` | Elsevier, through your library | optional; gives abstracts away from the university network |
| `wos_api_key` | [developer.clarivate.com](https://developer.clarivate.com) | subscribe to the Web of Science Starter API |
| `ieee_api_key` | [developer.ieee.org](https://developer.ieee.org) | |
| `semanticscholar_api_key` | [semanticscholar.org/product/api](https://www.semanticscholar.org/product/api) | optional |
| `openalex_api_key` | [openalex.org/settings/api](https://openalex.org/settings/api) | optional, free |
| `core_api_key` | [core.ac.uk/services/api](https://core.ac.uk/services/api) | optional |
| `contact_email` | | optional; sent to Crossref with each lookup, which then answers faster |

A key can also come from an environment variable, which takes precedence over the stored one: `LITQUERY_SCOPUS_API_KEY`, `LITQUERY_SCOPUS_INSTTOKEN`, `LITQUERY_WOS_API_KEY`, `LITQUERY_IEEE_API_KEY`, `LITQUERY_S2_API_KEY`, `LITQUERY_OPENALEX_API_KEY`, `LITQUERY_CORE_API_KEY`, `LITQUERY_CONTACT_EMAIL`.

### Connect it to Claude

Claude Code, with the full path of the server program:

```
claude mcp add -s user litquery -- C:\path\to\litquery\.venv\Scripts\litquery-mcp.exe
```

```
claude mcp add -s user litquery -- /path/to/litquery/.venv/bin/litquery-mcp
```

Claude Desktop, Cursor and other clients that read an `mcpServers` block:

```json
{
  "mcpServers": {
    "litquery": {
      "command": "C:\\path\\to\\litquery\\.venv\\Scripts\\litquery-mcp.exe"
    }
  }
}
```

Then ask, for example:

> Create a review in D:\reviews\warehouse-twins. Count the hits for ("digital twin" OR "cyber-physical system") AND warehouse AND simulat* from 2015 on in the main databases and show me five records from Scopus.

## Tools

| Tool | Command line | What it does |
| --- | --- | --- |
| `status` | `litquery status [--check]` | Which keys are stored (never their values), which sources are ready, calls made today. With `check`, one small request to each source. |
| `init_review` | `litquery init FOLDER` | Creates the folder for one review. |
| `count` | `litquery count QUERY` | Hits per database, nothing downloaded. For developing the search string. |
| `preview` | `litquery preview QUERY -s SOURCE` | The first records one database returns. Nothing is stored. |
| `run_search` | `litquery run QUERY` | Downloads every record into the review, one logged run per source. |
| `dedupe` | `litquery dedupe` | Groups records of the same work and returns the numbers for a PRISMA flow diagram. |
| `fill_abstracts` | `litquery fill-abstracts` | Fetches missing abstracts by DOI. |
| `snowball` | `litquery snowball SEED...` | Follows the citations of seed papers backward and forward through Semantic Scholar. |
| `find` | `litquery find [TEXT]` | Lists stored records by text, source, run, year or missing abstract. |
| `import_file` | `litquery import FILE` | Adds a RIS or BibTeX file exported by hand. |
| `export` | `litquery export` | Writes RIS, BibTeX or CSV to `exports/`. |
| `search_log` | `litquery log [--write]` | Every search with its date, the exact query, the settings and the counts. |

The command line prints the same JSON the tools return. `litquery <command> --help` lists the options.

## Search strings

- `AND`, `OR` and `NOT` in capitals, `"quoted phrases"`, brackets, `*` for any ending (`simulat*`) and `?` for one character.
- `fields` says where to search: `tak` for title, abstract and keywords (the default), `title_abs` for title and abstract, `title` for the title only.
- `year_from` and `year_to` limit the publication year.
- `native` sends one database a query in its own syntax, unchanged: `{"scopus": "TITLE-ABS-KEY(rfid) AND SUBJAREA(ENGI)"}`.
- A lower-case `and`, two words without an operator between them and an unclosed quotation mark are errors with a hint. The search string is never guessed at.

The command line calls these `--fields`, `--from`, `--to` and `--native SOURCE=QUERY`. Run it inside the review folder, or name the folder with `-r FOLDER`:

```
litquery init warehouse-twins
cd warehouse-twins
litquery count '("digital twin" OR "cyber-physical system") AND warehouse AND simulat*' --from 2015
litquery run '("digital twin" OR "cyber-physical system") AND warehouse AND simulat*' --from 2015 --label "final search"
litquery dedupe
litquery fill-abstracts
litquery export --format ris
litquery log --write
```

The single quotes around the search string work in bash, zsh and PowerShell 7. Windows PowerShell 5.1 drops the inner quotation marks, so use PowerShell 7 there.

## How it works

- The search string is parsed once. Each source writes it in its own syntax with explicit brackets, so operator precedence is the same everywhere.
- A review folder holds `litquery.sqlite` (records, runs and the search log), `raw/` (every reply of every database as it arrived) and `exports/`.
- A download is one run per source. It stops at the time limit or when a database refuses further calls, and `resume_run_ids` continues it from the page where it stopped.
- A search that reports more hits than `max_records` (5,000 unless you set it) is refused before anything is downloaded, so a string that is too broad does not use up an API allowance.
- Records with the same DOI are one work. Where a DOI is missing, the same or nearly the same title counts only together with a shared author name and publication years at most one apart. Records with different DOIs are never merged automatically.
- Pairs that only look alike are listed in `exports/possible-duplicates.csv`. Your decisions (`merge`, `keep_apart`) are remembered, and a decided pair is not listed again.
- A missing abstract is taken from another record of the same work, then by DOI from Semantic Scholar, OpenAlex and Crossref. Each abstract keeps a note of where it came from.
- The search log lists every run with its date, source, search string, the exact query sent, the settings, the hits reported and the records retrieved and new. `search_log` writes it as Markdown and CSV for the methods section.

## Options

| Environment variable | Meaning |
| --- | --- |
| `LITQUERY_REVIEW_DIR` | The review folder to use when a call names none |
| `LITQUERY_WOS_DAILY_LIMIT` | Calls per day that your Web of Science plan allows (default 5000) |
| `LITQUERY_STATE_DIR` | Where the count of today's calls is kept (default `%LOCALAPPDATA%\litquery` on Windows, `~/.local/state/litquery` elsewhere) |

To give Claude a default review folder, add the variable to the server entry:

```
claude mcp add -s user litquery -e LITQUERY_REVIEW_DIR=D:\reviews\warehouse-twins -- C:\path\to\litquery\.venv\Scripts\litquery-mcp.exe
```

## Limits

- Version 0.1. Semantic Scholar, OpenAlex, CORE and Crossref are checked against the live services. Scopus, Web of Science and IEEE Xplore pass their tests against simulated replies written from the API documentation and have not yet been run with real keys.
- Developed and tested on Windows so far. It is written to run on macOS and Linux as well, but that is not tested yet.
- No screening and no full texts. Export to Rayyan, ASReview, Covidence or Zotero for that.
- The Web of Science Starter API delivers no abstracts, and Scopus delivers them only to subscribers. `fill_abstracts` finds many of the missing ones in the open indexes, not all.
- The terms of each provider apply to the records you download, for example on how long they may be kept and whether they may be shared.

## Security

- Keys are read from the credential store or the environment at the moment a request is made. No tool returns them, and `status` only says whether one is stored.
- Keys are removed from error messages and from the replies saved in `raw/`. Request addresses never appear in an error.
- The server talks to its client over standard input and output and opens no network port.
- Requests go to the seven services above and nowhere else. There is no telemetry, and Crossref receives a contact email only if you stored one.

## Development

```
.venv\Scripts\pip install -e ".[dev]"
.venv\Scripts\python -m pytest
```

About a thousand tests run in under two minutes without network access. The services are simulated.

## License

MIT. See [LICENSE](LICENSE).