AR

arXiv LaTeX MCP Server for Precise Math Interpretation

Fetch and process arXiv LaTeX with an MCP server to extract and precisely interpret mathematical expressions from scientific papers.

Quick Install
npx -y @takashiishida/arxiv-latex-mcp

Overview

This project provides an MCP (Model Context Protocol) server that fetches arXiv paper sources (LaTeX), processes them, and exposes structured representations of mathematical content for downstream models and tools. By combining arXiv source retrieval, LaTeX parsing, macro expansion, and math-specific normalization, the server enables precise interpretation and reliable provenance for equations, symbols, and expressions extracted from scientific papers.

The server is intended for developer workflows that need exact math semantics rather than raw rendered images. Typical consumers are LLM-driven agents, symbolic algebra interfaces, dataset creators, and search/indexing systems that require a machine-readable, disambiguated view of math expressions together with links back to the original arXiv source.

GitHub: https://github.com/takashiishida/arxiv-latex-mcp

Features

  • Fetch arXiv source tarballs for papers via arXiv IDs
  • Parse LaTeX to extract math environments (inline, display, aligned, arrays)
  • Expand user-defined macros and common package macros where possible
  • Produce structured math output (LaTeX AST and optional MathML)
  • Maintain provenance: map expressions to file, line, surrounding context, and PDF coordinates (when available)
  • HTTP/MCP-compatible API to stream content and serve tool-style endpoints
  • Dockerized deployment and CLI utility for batch processing
  • Configurable parser behavior (macro whitelist, package handling, strict/lenient parsing)

Installation / Configuration

Prerequisites: Docker or Python 3.10+ and Git.

Clone the repo:

git clone https://github.com/takashiishida/arxiv-latex-mcp.git
cd arxiv-latex-mcp

Run with Docker:

# Build
docker build -t arxiv-latex-mcp .

# Run (exposes default MCP-compatible HTTP endpoints on 8080)
docker run -p 8080:8080 \
  -e MCP_HOST=0.0.0.0 -e MCP_PORT=8080 \
  -v /path/to/cache:/data/cache \
  arxiv-latex-mcp

Run locally with Python:

python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

# Example environment variables
export MCP_HOST=127.0.0.1
export MCP_PORT=8080
export CACHE_DIR=./cache

# Start server
python mcp_server/main.py

Configuration options (example):

# config.yml
http:
  host: 0.0.0.0
  port: 8080

arxiv:
  cache_dir: ./cache
  timeout_sec: 30

parser:
  expand_macros: true
  macro_whitelist:
    - \\vec
    - \\mathrm
  output_formats:
    - ast
    - mathml

Available Tools / Resources

The server exposes MCP-style tool endpoints suitable for model-driven workflows. Common endpoints:

EndpointMethodDescription
/fetch/{arxiv_id}GETDownload and unpack arXiv source tarball
/parse/{arxiv_id}POSTParse LaTeX sources and return structured math artifacts
/equation/{arxiv_id}/{eq_id}GETRetrieve a single equation with provenance
/statusGETHealth and queue status

Example response (JSON snippet for an extracted equation):

{
  "eq_id": "eq:3.2",
  "latex": "\\nabla \\cdot \\vec{E} = \\rho",
  "ast": { "type": "binary", "op": "=", "left": { ... }, "right": { ... } },
  "mathml": "<math>...</math>",
  "source": {
    "file": "main.tex",
    "line_start": 123,
    "line_end": 125,
    "context": "As shown in (3.2) ..."
  }
}

Included utilities:

  • CLI: fetch, parse, list equations
  • Batch mode: parse lists of arXiv IDs to a local datastore
  • Optional helper to locate equation bounding boxes in the compiled PDF (requires LaTeX toolchain)

Use Cases

  1. LLM-assisted paper QA

    • Use the server as a tool in an agent that needs to inspect formulas precisely. Example workflow: agent calls /parse/2101.00001, retrieves an AST for a suspect equation, converts it to canonical form, and uses a CAS to verify an identity.
  2. Symbolic verification and reproducibility

    • Extract expressions with macro expansion and send them to symbolic engines (SymPy, Sage). Because the server preserves provenance, you can report exactly which file and lines contributed to a given expression.
  3. Mathematical search and indexing

    • Index ASTs or MathML instead of raw text to enable formula-level search, similarity queries, or clustering across a corpus of arXiv papers.
  4. Dataset creation for ML tasks

    • Batch-parse arXiv IDs to generate labeled examples: (latex, AST, MathML, provenance). Useful for training models on math normalization, translation, or equation recognition.

Examples:

  • Fetch and parse via curl:
curl -X POST "http://localhost:8080/parse/2101.00001" \
  -H "Content-Type: application/json" \
  -d '{"formats":["ast","mathml"], "strict":false}'
  • Retrieve a particular equation:
curl "http://localhost:8080/equation/2101.00001/eq:3.2"

Notes and Best Practices

  • The parser aims to expand common macros but cannot perfectly resolve arbitrary package logic; prefer papers with included macro definitions or provide macro overrides in config.
  • For PDF-coordinate provenance, the server compiles LaTeX and requires a TeX toolchain in the environment.
  • Use caching for large-scale processing; the server supports on-disk cache to avoid repeated downloads.

For code, issues, and contribution guidelines, see the GitHub repository: https://github.com/takashiishida/arxiv-latex-mcp